com.vividsolutions.jump.util
Class CollectionUtil

java.lang.Object
  extended by com.vividsolutions.jump.util.CollectionUtil

public class CollectionUtil
extends java.lang.Object


Constructor Summary
CollectionUtil()
           
 
Method Summary
static void addIfNotNull(java.lang.Object item, java.util.Collection collection)
           
static java.util.Collection collect(java.util.Collection collection, Block block)
          The Smalltalk #collect method.
static java.util.List combinations(java.util.List original)
          Returns a List of Lists: all combinations of the elements of the given List.
static java.util.List combinations(java.util.List original, int maxCombinationSize)
          Returns a List of Lists: all combinations of the elements of the given List.
static java.util.List combinations(java.util.List original, int maxCombinationSize, java.lang.Object mandatoryItem)
          Returns a List of Lists: all combinations of the elements of the given List.
static java.util.Collection concatenate(java.util.Collection collections)
           
static boolean containsReference(java.lang.Object[] objects, java.lang.Object o)
           
static java.util.Map createMap(java.lang.Class mapClass, java.lang.Object[] alternatingKeysAndValues)
           
static java.util.Map createMap(java.lang.Object[] alternatingKeysAndValues)
           
static java.util.Collection filterByClass(java.util.Collection collection, java.lang.Class c)
          Modifies and returns the collection.
static java.lang.Object get(java.lang.Class c, java.util.Map map)
           
static java.lang.Object ifNotIn(java.lang.Object o, java.util.Collection c, java.lang.Object alternative)
           
static int indexOf(java.lang.Object o, java.lang.Object[] objects)
           
static java.util.Map inverse(java.util.Map map)
           
static java.util.List[] keysAndCorrespondingValues(java.util.Map map)
          The nth key corresponds to the nth value
static java.util.List list(java.lang.Object a, java.lang.Object b)
           
static java.lang.Object randomElement(java.util.List list)
           
static java.util.Collection removeDuplicates(java.util.Collection original)
          Brute force, for when HashSet and TreeSet won't work (e.g.
static void removeKeys(java.util.Collection keys, java.util.Map map)
           
static void resize(java.util.List list, int newSize)
           
static java.util.List reverse(java.util.List list)
           
static java.util.SortedSet reverseSortedSet(int[] ints)
           
static java.util.Collection select(java.util.Collection collection, Block block)
          The Smalltalk #select method.
static void setIfNull(int i, java.util.List list, java.lang.String value)
           
static java.util.Collection stretch(java.util.Collection source, java.util.Collection destination, int destinationSize)
          Data is evenly discarded or duplicated to attain the new size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

list

public static java.util.List list(java.lang.Object a,
                                  java.lang.Object b)

combinations

public static java.util.List combinations(java.util.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

inverse

public static java.util.Map inverse(java.util.Map map)

combinations

public static java.util.List combinations(java.util.List original,
                                          int maxCombinationSize,
                                          java.lang.Object mandatoryItem)
Returns a List of Lists: all combinations of the elements of the given List.

Parameters:
maxCombinationSize - combinations larger than this value are discarded
mandatoryItem - an item that all returned combinations must contain, or null to leave unspecified

combinations

public static java.util.List combinations(java.util.List original)
Returns a List of Lists: all combinations of the elements of the given List.


removeKeys

public static void removeKeys(java.util.Collection keys,
                              java.util.Map map)

keysAndCorrespondingValues

public static java.util.List[] keysAndCorrespondingValues(java.util.Map map)
The nth key corresponds to the nth value


concatenate

public static java.util.Collection concatenate(java.util.Collection collections)

randomElement

public static java.lang.Object randomElement(java.util.List list)

reverseSortedSet

public static java.util.SortedSet reverseSortedSet(int[] ints)

reverse

public static java.util.List reverse(java.util.List list)

stretch

public static java.util.Collection stretch(java.util.Collection source,
                                           java.util.Collection destination,
                                           int destinationSize)
Data is evenly discarded or duplicated to attain the new size


ifNotIn

public static java.lang.Object ifNotIn(java.lang.Object o,
                                       java.util.Collection c,
                                       java.lang.Object alternative)

setIfNull

public static void setIfNull(int i,
                             java.util.List list,
                             java.lang.String value)

resize

public static void resize(java.util.List list,
                          int newSize)

containsReference

public static boolean containsReference(java.lang.Object[] objects,
                                        java.lang.Object o)

indexOf

public static int indexOf(java.lang.Object o,
                          java.lang.Object[] objects)

removeDuplicates

public static java.util.Collection removeDuplicates(java.util.Collection 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(java.lang.Object item,
                                java.util.Collection collection)

filterByClass

public static java.util.Collection filterByClass(java.util.Collection collection,
                                                 java.lang.Class c)
Modifies and returns the collection.


createMap

public static java.util.Map createMap(java.lang.Object[] alternatingKeysAndValues)

createMap

public static java.util.Map createMap(java.lang.Class mapClass,
                                      java.lang.Object[] alternatingKeysAndValues)

collect

public static java.util.Collection collect(java.util.Collection collection,
                                           Block block)
The Smalltalk #collect method.


select

public static java.util.Collection select(java.util.Collection collection,
                                          Block block)
The Smalltalk #select method.


get

public static java.lang.Object get(java.lang.Class c,
                                   java.util.Map map)