|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.util.CollUtils
public final class CollUtils
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
|
addAll(Collection<T> coll,
E[] array)
Convenience method that adds all members of an array to a collection. |
|
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 boolean[] |
asBooleanArray(String input)
Converts a string into a boolean array, calling Util.asBoolean(char) on each character. |
|
static char[] |
asCharArray(Object[] objArray)
Converts an object array into a char array, calling Util.asChar(Object) on each element. |
|
static char[] |
asCharArray(String input)
Converts a string array into a char array. |
|
static double[] |
asDoubleArray(Object[] objArray)
Converts an object array into a double array, calling Util.asDouble(Object) on each element. |
|
static double[] |
asDoubleArray(String input)
Converts a string into a double array, by splitting on whitespace and calling asDoubleArray(Object[]) on the result. |
|
static float[] |
asFloatArray(Object[] objArray)
Converts an object array into a float array, calling Util.asFloat(Object) on each element. |
|
static float[] |
asFloatArray(String input)
Converts a string into a float array, by splitting on whitespace and calling asFloatArray(Object[]) on the result. |
|
static int[] |
asIntArray(Object[] objArray)
Converts an object array into an integer array, calling Util.asInt(Object) on each element. |
|
static int[] |
asIntArray(String input)
Converts a string into an integer array, by splitting on whitespace and calling asIntArray(Object[]) on the result. |
|
static long[] |
asLongArray(Object[] objArray)
Converts an object array into a long array, calling Util.asLong(Object) on each element. |
|
static long[] |
asLongArray(String input)
Converts a string into a long array, by splitting on whitespace and calling asLongArray(Object[]) on the result. |
|
static short[] |
asShortArray(Object[] objArray)
Converts an object array into a short array, calling Util.asShort(Object) on each element. |
|
static short[] |
asShortArray(String input)
Converts a string into a short array, by splitting on whitespace and calling asShortArray(Object[]) on the result. |
|
static String[] |
asStringArray(Object[] objArray)
Converts an object array into a String array, calling Util.asString(Object) on each element. |
|
static String[] |
asStringArray(String input)
Converts a string into an array of whitespace-separated tokens. |
|
static Set<String> |
asStringSet(Set rawSet)
Converts a raw set into a set of strings, calling the Object.toString() method for each non-null object. |
|
static Set<String> |
asStringSet(String input)
Converts a string into an set of whitespace-separated tokens. |
|
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 of Util.TRUE_CHAR and Util.FALSE_CHAR characters,
without using separator characters. |
|
static String |
flatten(char[] array)
Flattens the elements of the provided array into a single string, without using separator characters. |
|
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(Iterator iterator)
Flattens the objects returned by an iterator into a single string, separating elements by a space character. |
|
static String |
flatten(Iterator iterator,
String separator)
Flattens the objects returned by an iterator into a single string, separating elements by the provided separator. |
|
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). |
|
static
|
removeByIdentity(Collection<T> coll,
T obj)
Removes an object from a collection (if it is present), using identity-based comparisons instead of the equals -based comparisons used by
Collection.remove(Object) . |
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,E extends T> void addAll(Collection<T> coll, E[] array)
T
- the type of the collectionE
- the type of the arraycoll
- the collection to add toarray
- the array to value to addpublic static <T> Set<T> arrayAsSet(T[] array)
T
- the type of the arrayarray
- 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 boolean[] asBooleanArray(String input) throws IllegalArgumentException
Util.asBoolean(char)
on each character.
input
- the input string to convert
IllegalArgumentException
- if one of the characters does not
contain a parsable booleanpublic 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 char[] asCharArray(String input)
String.toCharArray()
.
input
- the input string to convert
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 double[] asDoubleArray(String input) throws NumberFormatException
asDoubleArray(Object[])
on the result.
input
- the input string to convert
NumberFormatException
- if one of the tokens 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 float[] asFloatArray(String input) throws NumberFormatException
asFloatArray(Object[])
on the result.
input
- the input string to convert
NumberFormatException
- if one of the tokens 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 int[] asIntArray(String input) throws NumberFormatException
asIntArray(Object[])
on the result.
input
- the input string to convert
NumberFormatException
- if one of the tokens does not contain a
parsable integerpublic 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 long[] asLongArray(String input) throws NumberFormatException
asLongArray(Object[])
on the result.
input
- the input string to convert
NumberFormatException
- if one of the tokens 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 short[] asShortArray(String input) throws NumberFormatException
asShortArray(Object[])
on the result.
input
- the input string to convert
NumberFormatException
- if one of the tokens 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 String[] asStringArray(String input)
TextUtils.splitString(CharSequence)
.
input
- the input string to convert
public static Set<String> asStringSet(String input)
asShortArray(String)
} into a LinkedHashSet
, so the
original iteration order is preserved (but duplicates will be discarded).
input
- the input string to convert
public static Set<String> asStringSet(Set rawSet)
Object.toString()
method for each non-null
object.
rawSet
- the set 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)
Util.TRUE_CHAR
and Util.FALSE_CHAR
characters,
without using separator characters.
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(Iterator iterator)
iterator
- the iterator over the elements to join
public static String flatten(Iterator iterator, String separator)
iterator
- the iterator over the elements to joinseparator
- the separator string to use
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).
T
- the type of the listlist
- the input listnumber
- the number of elements to copy
list
is null
public static <T> boolean removeByIdentity(Collection<T> coll, T obj)
equals
-based comparisons used by
Collection.remove(Object)
.
T
- the type of the collectioncoll
- the collection to useobj
- the object to remove
true
if the object has been removed from the
collection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |