org.jppf.utils
Class CollectionUtils

java.lang.Object
  extended by org.jppf.utils.CollectionUtils

public final class CollectionUtils
extends Object

This class provides a set of utility methods for manipulating and converting collections and arrays.

Author:
Laurent Cohen

Method Summary
static
<T> T[]
concatArrays(T[]... arrays)
          Concatenate a set of array into a single array.
static
<T,U> String
formatSizeMapInfo(String name, Map<T,List<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 a List.
static
<T,U> void
putInListMap(T key, U value, Map<T,List<U>> map)
          Add an element in a map whose values are lists of elements.
static
<T,U> void
removeFromListMap(T key, U value, Map<T,List<U>> map)
          Remove an element from a map whose values are lists of elements.
static
<T> Set<T>
set(T... array)
          Convert an array into a Set.
static
<T,U> int
sizeOfListMap(Map<T,List<U>> map)
          Get the total number of elements in a map whose values are lists of elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

set

public static <T> Set<T> set(T... array)
Convert an array into a Set.

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.

list

public static <T> List<T> list(T... array)
Convert an array into a List.

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.

putInListMap

public static <T,U> void putInListMap(T key,
                                      U value,
                                      Map<T,List<U>> map)
Add an element in a map whose values are lists of elements.

Type Parameters:
T - the type of the keys in the map.
U - the type of the elements in the lists.
Parameters:
key - the key for the value to add.
value - the value to add.
map - the map in which ot add the key/value pair.

removeFromListMap

public static <T,U> void removeFromListMap(T key,
                                           U value,
                                           Map<T,List<U>> map)
Remove an element from a map whose values are lists of elements.

Type Parameters:
T - the type of the keys in the map.
U - the type of the elements in the lists.
Parameters:
key - the key for the value to remove.
value - the value to remove.
map - the map from which to remove the key/value pair.

sizeOfListMap

public static <T,U> int sizeOfListMap(Map<T,List<U>> map)
Get the total number of elements in a map whose values are lists of elements.

Type Parameters:
T - the type of the keys in the map.
U - the type of the elements in the lists.
Parameters:
map - the map of which to get the size.
Returns:
the size of the map as an int value.

formatSizeMapInfo

public static <T,U> String formatSizeMapInfo(String name,
                                             Map<T,List<U>> map)
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

public 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.

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.


Copyright © 2005-2010 JPPF Team.