public final class ObjectArrays
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
private |
ObjectArrays() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.Object |
checkElementNotNull(java.lang.Object element,
int index) |
(package private) static java.lang.Object[] |
checkElementsNotNull(java.lang.Object... array) |
(package private) static java.lang.Object[] |
checkElementsNotNull(java.lang.Object[] array,
int length) |
static <T> T[] |
concat(T[] array,
T element)
Returns a new array that appends
element to array . |
static <T> T[] |
concat(T[] first,
T[] second,
java.lang.Class<T> type)
Returns a new array that contains the concatenated contents of two arrays.
|
static <T> T[] |
concat(T element,
T[] array)
Returns a new array that prepends
element to array . |
(package private) static java.lang.Object[] |
copyAsObjectArray(java.lang.Object[] elements,
int offset,
int length)
Returns a copy of the specified subrange of the specified array that is literally an Object[],
and not e.g.
|
private static java.lang.Object[] |
fillArray(java.lang.Iterable<?> elements,
java.lang.Object[] array) |
static <T> T[] |
newArray(java.lang.Class<T> type,
int length)
Returns a new array of the given length with the specified component type.
|
static <T> T[] |
newArray(T[] reference,
int length)
Returns a new array of the given length with the same type as a reference array.
|
(package private) static void |
swap(java.lang.Object[] array,
int i,
int j)
Swaps
array[i] with array[j] . |
(package private) static java.lang.Object[] |
toArrayImpl(java.util.Collection<?> c)
Returns an array containing all of the elements in the specified collection.
|
(package private) static <T> T[] |
toArrayImpl(java.util.Collection<?> c,
T[] array)
Returns an array containing all of the elements in the specified collection; the runtime type
of the returned array is that of the specified array.
|
(package private) static <T> T[] |
toArrayImpl(java.lang.Object[] src,
int offset,
int len,
T[] dst)
Implementation of
Collection.toArray(Object[]) for collections backed by an object
array. |
public static <T> T[] newArray(java.lang.Class<T> type, int length)
type
- the component typelength
- the length of the new arraypublic static <T> T[] newArray(T[] reference, int length)
reference
- any array of the desired typelength
- the length of the new arraypublic static <T> T[] concat(T[] first, T[] second, java.lang.Class<T> type)
first
- the first array of elements to concatenatesecond
- the second array of elements to concatenatetype
- the component type of the returned arraypublic static <T> T[] concat(T element, T[] array)
element
to array
.element
- the element to prepend to the front of array
array
- the array of elements to appendarray
, with element
occupying
the first position, and the elements of array
occupying the remaining elements.public static <T> T[] concat(T[] array, T element)
element
to array
.array
- the array of elements to prependelement
- the element to append to the endarray
, with the same contents as array
, plus element
occupying the last position.static <T> T[] toArrayImpl(java.util.Collection<?> c, T[] array)
If the collection fits in the specified array with room to spare (i.e., the array has more
elements than the collection), the element in the array immediately following the end of the
collection is set to null
. This is useful in determining the length of the collection
only if the caller knows that the collection does not contain any null elements.
This method returns the elements in the order they are returned by the collection's iterator.
TODO(kevinb): support concurrently modified collections?
c
- the collection for which to return an array of elementsarray
- the array in which to place the collection elementsjava.lang.ArrayStoreException
- if the runtime type of the specified array is not a supertype of
the runtime type of every element in the specified collectionstatic <T> T[] toArrayImpl(java.lang.Object[] src, int offset, int len, T[] dst)
Collection.toArray(Object[])
for collections backed by an object
array. the runtime type of the returned array is that of the specified array. If the collection
fits in the specified array, it is returned therein. Otherwise, a new array is allocated with
the runtime type of the specified array and the size of the specified collection.
If the collection fits in the specified array with room to spare (i.e., the array has more
elements than the collection), the element in the array immediately following the end of the
collection is set to null
. This is useful in determining the length of the collection
only if the caller knows that the collection does not contain any null elements.
static java.lang.Object[] toArrayImpl(java.util.Collection<?> c)
This method assumes that the collection size doesn't change while the method is running.
TODO(kevinb): support concurrently modified collections?
c
- the collection for which to return an array of elementsstatic java.lang.Object[] copyAsObjectArray(java.lang.Object[] elements, int offset, int length)
String[]
.private static java.lang.Object[] fillArray(java.lang.Iterable<?> elements, java.lang.Object[] array)
static void swap(java.lang.Object[] array, int i, int j)
array[i]
with array[j]
.static java.lang.Object[] checkElementsNotNull(java.lang.Object... array)
static java.lang.Object[] checkElementsNotNull(java.lang.Object[] array, int length)
static java.lang.Object checkElementNotNull(java.lang.Object element, int index)