E - The type of the entry of the array under consideration.public final class ArraysExt<E> extends Object
Arrays.
Partially this is influenced by Collections.| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ArraysExt.ArrayComparator<O>
Comparator class
which implements a kind of lexical ordering on arrays
based on the ordering of the components
defined by
atomic. |
| Modifier and Type | Field and Description |
|---|---|
static Object[] |
EMPTY
The class
double[][]. |
| Modifier | Constructor and Description |
|---|---|
private |
ArraysExt() |
| Modifier and Type | Method and Description |
|---|---|
private static Object |
createUnWrappedEmptyArray(Object[] wrappedArray)
Returns an empty array with type like
wrappedArray
with basic type replaced by its wrapper. |
private static Object[] |
createWrappedEmptyArray(Object elemArray)
Returns an empty array with type like
elemArray
with basic type replaced by its wrapper. |
static void |
fill(Object[] array,
Object obj)
Replaces all of the elements of the specified array
with the specified element.
|
static Comparator<Object[]> |
getComparator(Comparator<Object> atomic)
Returns a comparator of the class
ArraysExt.ArrayComparator
which implements a kind of lexical ordering on arrays
based on the ordering of the components
defined by atomic. |
static Object[] |
nCopies(int num,
Object obj)
Returns an array consisting of n copies
of the specified object.
|
static List<Object> |
recAsList(Object[] array)
Turns the given array recursively
into a hierarchy of nested lists.
|
static Object |
recAsList(Object source,
Class<?> cls)
Converts
source
which is typically an array,
recursively into an nested List
with the given atomic entry type using the specified caster. |
static Object |
recAsList(Object source,
Class<?> cls,
Caster caster)
Converts
source
which is typically an array,
recursively into an nested List
with the given atomic entry type using the specified caster. |
static void |
reverse(Object[] array)
Reverses the order of the elements in the specified array.
|
static boolean[] |
toPrimitive(Boolean[] arr)
Converts an array of
Booleans
into an array of according booleans. |
static byte[] |
toPrimitive(Byte[] arr)
Converts an array of
Bytes
into an array of according bytes. |
static char[] |
toPrimitive(Character[] arr)
Converts an array of
Characters
into an array of according chars. |
static double[] |
toPrimitive(Double[] arr)
Converts an array of
Doubles
into an array of according doubles. |
static float[] |
toPrimitive(Float[] arr)
Converts an array of
Floats
into an array of according floats. |
static int[] |
toPrimitive(Integer[] arr)
Converts an array of
Integers
into an array of according ints. |
static long[] |
toPrimitive(Long[] arr)
Converts an array of
Longs
into an array of according longs. |
static short[] |
toPrimitive(Short[] arr)
Converts an array of
Shorts
into an array of according shorts. |
static Object |
unWrapArray(Object[] wrappedArray)
Returns an array which corresponds with the given one
except that the entries are unwrapped.
|
static Object[] |
wrapArray(Object elemArray)
Returns an array which corresponds with the given one
except that the entries are wrapped.
|
public static final Object[] EMPTY
double[][].public static void reverse(Object[] array)
array - the array whose elements are to be reversed.public static void fill(Object[] array, Object obj)
array - the array to be filled with the specified element.obj - The element with which to fill the specified array.public static Object[] nCopies(int num, Object obj)
num - the number of elements in the returned list.obj - the element to appear repeatedly in the returned list.IllegalArgumentException - if n < 0.public static List<Object> recAsList(Object[] array)
array - an array of objects which may in turn be arrays of objects.list of objects satisfying
list.get(i) == array[i]
if array[i] is not an Object[];
list.get(i) == recAsList(array[i]) otherwise.
Note that list may be a nested list.CollectionsExt.recToArray(List)public static Object recAsList(Object source, Class<?> cls)
source
which is typically an array,
recursively into an nested List
with the given atomic entry type using the specified caster.
Note that if source is not an array,
it must be compatible with cls
up to equivalence of basic classes and their wrappers
and up to subclassing.source - an arbitrary Object,
but typically an array as e.g. Object[][]
or double[].cls - Up to compatibility defined by caster,
the type of the entries of the return value.
Recursive conversion from arrays to lists stops
if an entry of type compatible with cls is found.
Note that this may also be a primitive type
such as int or an array type
Double[][][] or List[][][]
or even int[][][].
cls and source
are assignment compatible
up to equivalence of basic classes and their wrappers,
source is returned.
cls and source are not compatible,
source must be an array;
otherwise an exception is thrown.
In the former case,
a list list of objects is returned
satisfying list.size() == Array.getLength(source) and
list.get(i) == recAsList(Array.get(source,i),cls)
for all valid indices i.
Note that the return value
is either the result of a casting process or a list.
In the latter case its entries are either lists themselves
or again the result of a casting and so on.
Clearly its atomic entries are always Objects
even when starting with sources
of type int[] for instance.
IllegalArgumentException - if source is neither an array,
nor assignment compatible with cls
up to equivalence between basic types and their wrappers.
Also if source is an array,
and this condition holds for some component.
This is a recursive definition.public static Object recAsList(Object source, Class<?> cls, Caster caster)
source
which is typically an array,
recursively into an nested List
with the given atomic entry type using the specified caster.
Note that if source is not an array,
it must be compatible with cls
with respect to caster.source - an arbitrary Object,
but typically an array as e.g. Object[][]
or double[].cls - Up to compatibility defined by caster,
the type of the entries of the return value.
Recursive conversion from arrays to lists stops
if an entry of type compatible with cls is found.
Note that this may also be a primitive type
such as int or an array type
Double[][][] or List[][][]
or even int[][][].
caster - performs the conversion of the top-level elements
of the source.cls and source are compatible
(see Caster.areCompatible(java.lang.Class<?>, java.lang.Object)),
the cast of source is returned.
Note that compatibility is up to wrapping of elementary types
and unwrapping of their wrappers.
Arrays are converted to Lists
applying this method recursively to their entries.
cls and source are not compatible,
source must be an array;
otherwise an exception is thrown.
In the former case,
a list list of objects is returned
satisfying list.size() == Array.getLength(source) and
list.get(i) == recAsList(Array.get(source,i),.. ,caster)
for all valid indices i.
Note that the return value
is either the result of a casting process or a list.
In the latter case its entries are either lists themselves
or again the result of a casting and so on.
Clearly its atomic entries are always Objects
even when starting with sources
of type int[] for instance.
IllegalArgumentException - if source is neither an array,
nor compatible with cls
with respect to caster.
Also if source is an array,
and this condition holds for some component.
This is a recursive definition.private static Object[] createWrappedEmptyArray(Object elemArray)
elemArray
with basic type replaced by its wrapper.elemArray - a non-null array with elementary entry type
such as double[][][].elemArray
with basic type replaced by its wrapper.
For example
createWrappedEmptyArray(new int[][][] {....})
yields new Integer[][][] {}.IllegalArgumentException - if elemArray is not an array
or if its entry type is not elementary
as e.g. for new Integer(0)
or for new Integer[][] {}.NullPointerException - if elemArray is nullprivate static Object createUnWrappedEmptyArray(Object[] wrappedArray)
wrappedArray
with basic type replaced by its wrapper.wrappedArray - a non-null array with wrapper entry type
such as Double[][][].wrapperArray
with basic type replaced by its wrapper.
For example
createUnWrappedEmptyArray(new Integer[][][] {....})
yields new int[][][] {}.IllegalArgumentException - if the entry type of wrappedArray is no wrapper type
as e.g. for new int[][] {}.public static Object[] wrapArray(Object elemArray)
elemArray - an array with elementary component type
as e.g. new int[][] {}.
May also be null.null if elemArray == null.
an array with the same length as elemArray.
The type of the components is the wrapper type
of the type of the components of elemArray.
Also the entries are those of elemArray
just wrapped.IllegalArgumentException - if elemArray is not an array
or if its entry type is not elementary
as e.g. for new Integer(0)
or for new Integer[][] {}.public static double[] toPrimitive(Double[] arr)
Doubles
into an array of according doubles.public static float[] toPrimitive(Float[] arr)
Floats
into an array of according floats.public static long[] toPrimitive(Long[] arr)
Longs
into an array of according longs.public static int[] toPrimitive(Integer[] arr)
Integers
into an array of according ints.public static short[] toPrimitive(Short[] arr)
Shorts
into an array of according shorts.public static byte[] toPrimitive(Byte[] arr)
Bytes
into an array of according bytes.public static boolean[] toPrimitive(Boolean[] arr)
Booleans
into an array of according booleans.public static char[] toPrimitive(Character[] arr)
Characters
into an array of according chars.public static Object unWrapArray(Object[] wrappedArray)
wrappedArray - an array with a wrapper as component type
as e.g. new Integer[][] {}.
May also be null.null if wrappedArray == null.
an array with the same length as wrappedArray.
The type of the components is the wrapped elementary type
of the type of the components of wrappedArray.
Also the entries are those of wrappedArray
just unwrapped.IllegalArgumentException - if the entry type of wrappedArray is no wrapper
as e.g. for new int[][] {} and for
new Object[][] {}.public static Comparator<Object[]> getComparator(Comparator<Object> atomic)
ArraysExt.ArrayComparator
which implements a kind of lexical ordering on arrays
based on the ordering of the components
defined by atomic.atomic - a Comparator for the components of arrays.Comparator for arrays.Copyright © 2012–2018 Simuline Organization (l2r). All rights reserved.