|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.util.CollectionUtils
public final class CollectionUtils
A static class that provides utility methods for working with
Collection
s and arrays. No instances of this class can be
created, only the static members should be used.
Field Summary | |
---|---|
static String |
SEPARATOR
Default separator used to flatten array if no other separator is specified: " " (a single space). |
Method Summary | ||
---|---|---|
static
|
arrayAsSet(T[] array)
Wraps an array into a set. |
|
static boolean[] |
asBooleanArray(Object[] objArray)
Converts an object array into a boolean array, calling Util.asBoolean(Object) on each element. |
|
static byte[] |
asByteArray(Object[] objArray)
Converts an object array into a byte array, calling Util.asByte(Object) on each element. |
|
static char[] |
asCharArray(Object[] objArray)
Converts an object array into a char array, calling Util.asChar(Object) on each element. |
|
static double[] |
asDoubleArray(Object[] objArray)
Converts an object array into a double array, calling Util.asDouble(Object) on each element. |
|
static float[] |
asFloatArray(Object[] objArray)
Converts an object array into a float array, calling Util.asFloat(Object) on each element. |
|
static int[] |
asIntArray(Object[] objArray)
Converts an object array into an integer array, calling Util.asInt(Object) on each element. |
|
static long[] |
asLongArray(Object[] objArray)
Converts an object array into a long array, calling Util.asLong(Object) on each element. |
|
static short[] |
asShortArray(Object[] objArray)
Converts an object array into a short array, calling Util.asShort(Object) on each element. |
|
static String[] |
asStringArray(Object[] objArray)
Converts an object array into a String array, calling Util.asString(Object) on each element. |
|
static void |
combineArrays(Object[] array1,
Object[] array2,
Object[] targetArray)
Combines two array into a target array, inserting all elements of the first array and then all elements of the second array in the target array. |
|
static String |
flatten(boolean[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(byte[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(char[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(double[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(float[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(int[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(long[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(Object[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static String |
flatten(Object[] array,
String separator)
Flattens the elements of the provided array into a single string, separating elements by the provided separator. |
|
static String |
flatten(short[] array)
Flattens the elements of the provided array into a single string, separating elements by a space character. |
|
static
|
lastN(List<? extends T> list,
int number)
Copied the last n elements from a list into a new list (or all elements, if the size of the input list is smaller or equal to n). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SEPARATOR
Method Detail |
---|
public static <T> Set<T> arrayAsSet(T[] array)
array
- the array to wrap
public static boolean[] asBooleanArray(Object[] objArray) throws IllegalArgumentException
Util.asBoolean(Object)
on each element.
objArray
- the array of objects to convert
IllegalArgumentException
- if an object's toString()
output cannot be parsed as a booleanpublic static byte[] asByteArray(Object[] objArray) throws NumberFormatException
Util.asByte(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable bytepublic static char[] asCharArray(Object[] objArray) throws IndexOutOfBoundsException
Util.asChar(Object)
on each element.
objArray
- the array of objects to convert
IndexOutOfBoundsException
- if the object's toString()
output is the empty string (after trimming outer whitespace)public static double[] asDoubleArray(Object[] objArray) throws NumberFormatException
Util.asDouble(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable doublepublic static float[] asFloatArray(Object[] objArray) throws NumberFormatException
Util.asFloat(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable floatpublic static int[] asIntArray(Object[] objArray) throws NumberFormatException
Util.asInt(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable intpublic static long[] asLongArray(Object[] objArray) throws NumberFormatException
Util.asLong(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable longpublic static short[] asShortArray(Object[] objArray) throws NumberFormatException
Util.asShort(Object)
on each element.
objArray
- the array of objects to convert
NumberFormatException
- if an object's toString()
output does not contain a parsable shortpublic static String[] asStringArray(Object[] objArray)
Util.asString(Object)
on each element.
objArray
- the array of objects to convert
public static void combineArrays(Object[] array1, Object[] array2, Object[] targetArray)
array1
- the first array to copyarray2
- the second array to copytargetArray
- the array to copy the two other array into; the
type of this array must be suitable to accept elements from both array;
the length of this array must be equal or greater than
array1.length + array2.length
public static String flatten(boolean[] array)
array
- the array of values to join
public static String flatten(byte[] array)
array
- the array of values to join
public static String flatten(char[] array)
array
- the array of values to join
public static String flatten(double[] array)
array
- the array of values to join
public static String flatten(float[] array)
array
- the array of values to join
public static String flatten(int[] array)
array
- the array of values to join
public static String flatten(long[] array)
array
- the array of values to join
public static String flatten(Object[] array)
array
- the array of values to join
public static String flatten(Object[] array, String separator)
array
- the array of values to joinseparator
- the separator string to use
public static String flatten(short[] array)
array
- the array of values to join
public static <T> ArrayList<T> lastN(List<? extends T> list, int number)
If number
is 0 or negative or if the original list is
null
or empty, an empty list is returned.
Note that this is somewhat inefficient if the input list is a
LinkedList
because repeated calls to
List.get(int)
are necessary (unless the whole list is copied).
list
- the input listnumber
- the number of elements to copy
list
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |