Package org.jppf.utils.collections
Class CollectionUtils
java.lang.Object
org.jppf.utils.collections.CollectionUtils
This class provides a set of utility methods for manipulating and converting
collections and arrays.
- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]array(T... elts) Return the parameters as an array.static <T> T[]concatArrays(Class<T> clazz, T[]... arrays) Concatenate a set of array into a single array.static <T> T[]concatArrays(T[]... arrays) Concatenate a set of array into a single array.static <T,U> String formatSizeMapInfo(String name, CollectionMap<T, U> map) Format a string with size information about a map whose values are lists of elements.static <T> List<T>getAllElements(List<T> source, int start, int size) Generate a list that contains the specified number of elements of the specified list, starting at the specified position in the specified list.static <T> List<T>list(T... array) Convert an array into aList.static Object[]Return the parameters as an array of Objects.static <K,V> String prettyPrint(CollectionMap<K, V> map) Print the content of a collection map in an easily readable way.static <T> Set<T>set(T... array) Convert an array into aSet.static <T> Set<T>Convert an array into aSet.
-
Method Details
-
set
Convert an array into aSet.- Type Parameters:
T- the type of the elements in the array.- Parameters:
array- the array to convert.- Returns:
- a set of elements with the same type as that of the array element type.
-
setOf
Convert an array into aSet.- Type Parameters:
T- the type of the elements in the array.- Parameters:
clazz- the class of the elements of the set to produce.array- the array to convert.- Returns:
- a set of elements with the same type as that of the array element type.
-
list
Convert an array into aList.- Type Parameters:
T- the type of the elements in the array.- Parameters:
array- the array to convert.- Returns:
- a list of elements with the same type as that of the array element type.
-
concatArrays
public static <T> T[] concatArrays(T[]... arrays) Concatenate a set of array into a single array.- Type Parameters:
T- the element type of the arrays to concatenate.- Parameters:
arrays- the arrays to concatenate.- Returns:
- an array whose size is the sum of the sizes of all the input arrays, and whose elements are all the elements found in all the input arrays.
-
concatArrays
Concatenate a set of array into a single array.- Type Parameters:
T- the element type of the arrays to concatenate.- Parameters:
clazz- the class of the elements of the array.arrays- the arrays to concatenate.- Returns:
- an array whose size is the sum of the sizes of all the input arrays, and whose elements are all the elements found in all the input arrays.
-
formatSizeMapInfo
Format a string with size information about a map whose values are lists of elements.- Type Parameters:
T- the type of the keys in the map.U- the type of the values in the map.- Parameters:
name- an arbitrary name given to the map.map- the map from which to get size information.- Returns:
- a string containing information about the number of elements in the map.
-
getAllElements
Generate a list that contains the specified number of elements of the specified list, starting at the specified position in the specified list.- Type Parameters:
T- the type of the elements in the list.- Parameters:
source- the list from which to get the elements.start- the start position in the source list.size- the number of elements to get from the source list.- Returns:
- the resulting list.
-
array
Return the parameters as an array.- Type Parameters:
T- the ytpe of the elements in the array. Inferred as the common supertype of all the elements.- Parameters:
elts- the elements of the array.- Returns:
- an array of the specified type.
-
objects
Return the parameters as an array of Objects.- Parameters:
elts- the elements of the array.- Returns:
- an array of
Objectinstances.
-
prettyPrint
Print the content of a collection map in an easily readable way.- Type Parameters:
K- the type of the keys in the map.V- the type of the values in the map.- Parameters:
map- the map to print.- Returns:
- a string with the map elements properly indented and formatted.
-