Package com.vividsolutions.jump.util
Class CollectionUtil
- java.lang.Object
-
- com.vividsolutions.jump.util.CollectionUtil
-
public class CollectionUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description CollectionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddIfNotNull(Object item, Collection collection)static <T,R>
Collection<R>collect(Collection<T> collection, Block block)The Smalltalk #collect method.static <T> List<List<T>>combinations(List<T> original)Returns a List of Lists: all combinations of the elements of the given List.static <T> List<List<T>>combinations(List<T> original, int maxCombinationSize, T mandatoryItem)Returns a List of Lists: all combinations of the elements of the given List.static Listcombinations(List original, int maxCombinationSize)Returns a List of Lists: all combinations of the elements of the given List.static <T> Collection<T>concatenate(Collection<? extends Collection<T>> collections)static <T> Collection<T>concatenate(Collection<T> a, Collection<T> b)static booleancontainsReference(Object[] objects, Object o)static Map<Object,Object>createMap(Class mapClass, Object[] alternatingKeysAndValues)static MapcreateMap(Object[] alternatingKeysAndValues)static CollectionfilterByClass(Collection collection, Class c)Modifies and returns the collection.static Objectget(Class<?> c, Map<Class<?>,? extends Object> map)Search an object associated to the class c or one of its parent in the associative mapstatic ObjectifNotIn(Object o, Collection c, Object alternative)static intindexOf(Object o, Object[] objects)static <U,V>
Map<V,U>inverse(Map<U,V> map)static List[]keysAndCorrespondingValues(Map map)The nth key corresponds to the nth valuestatic <T> List<T>list(T a, T b)static ObjectrandomElement(List list)static <T> Collection<T>removeDuplicates(Collection<T> original)Brute force, for when HashSet and TreeSet won't work (e.g.static <U,V>
voidremoveKeys(Collection<U> keys, Map<U,V> map)static voidresize(List list, int newSize)static Listreverse(List list)static SortedSet<Integer>reverseSortedSet(int[] ints)static <T> Collection<T>select(Collection<T> collection, Block block)The Smalltalk #select method.static voidsetIfNull(int i, List<String> list, String value)static <T> Collectionstretch(Collection<T> source, Collection<T> destination, int destinationSize)Data is evenly discarded or duplicated to attain the new size
-
-
-
Method Detail
-
concatenate
public static <T> Collection<T> concatenate(Collection<T> a, Collection<T> b)
-
list
public static <T> List<T> list(T a, T b)
-
combinations
public static List combinations(List original, int maxCombinationSize)
Returns a List of Lists: all combinations of the elements of the given List.- Parameters:
maxCombinationSize- combinations larger than this value are discarded
-
combinations
public static <T> List<List<T>> combinations(List<T> original, int maxCombinationSize, T mandatoryItem)
Returns a List of Lists: all combinations of the elements of the given List.- Parameters:
maxCombinationSize- combinations larger than this value are discardedmandatoryItem- an item that all returned combinations must contain, or null to leave unspecified
-
combinations
public static <T> List<List<T>> combinations(List<T> original)
Returns a List of Lists: all combinations of the elements of the given List.
-
removeKeys
public static <U,V> void removeKeys(Collection<U> keys, Map<U,V> map)
-
keysAndCorrespondingValues
public static List[] keysAndCorrespondingValues(Map map)
The nth key corresponds to the nth value
-
concatenate
public static <T> Collection<T> concatenate(Collection<? extends Collection<T>> collections)
-
stretch
public static <T> Collection stretch(Collection<T> source, Collection<T> destination, int destinationSize)
Data is evenly discarded or duplicated to attain the new size
-
ifNotIn
public static Object ifNotIn(Object o, Collection c, Object alternative)
-
resize
public static void resize(List list, int newSize)
-
removeDuplicates
public static <T> Collection<T> removeDuplicates(Collection<T> original)
Brute force, for when HashSet and TreeSet won't work (e.g. #hashCode implementation isn't appropriate). The original Collection is not modified.
-
addIfNotNull
public static void addIfNotNull(Object item, Collection collection)
-
filterByClass
public static Collection filterByClass(Collection collection, Class c)
Modifies and returns the collection.
-
createMap
public static Map<Object,Object> createMap(Class mapClass, Object[] alternatingKeysAndValues)
-
collect
public static <T,R> Collection<R> collect(Collection<T> collection, Block block)
The Smalltalk #collect method.
-
select
public static <T> Collection<T> select(Collection<T> collection, Block block)
The Smalltalk #select method.
-
get
public static Object get(Class<?> c, Map<Class<?>,? extends Object> map)
Search an object associated to the class c or one of its parent in the associative map- Parameters:
c- the class used as a keymap- the associative map in which the research is made- Returns:
- an object or null if no object is associated to class c or one of its parent
-
-