deegree 2.3 (2010/04/09 10:10 build-4-official)

org.deegree.framework.util
Class CollectionUtils

java.lang.Object
  extended by org.deegree.framework.util.CollectionUtils

public class CollectionUtils
extends Object

CollectionUtils contains some functionality missing in Arrays and Collections.

Version:
$Revision: 20893 $, $Date: 2009-11-19 14:31:51 +0100 (Do, 19. Nov 2009) $
Author:
Andreas Schmitz, last edited by: $Author: aschmitz $

Nested Class Summary
static interface CollectionUtils.Folder<T>
          Folder
static interface CollectionUtils.Mapper<T,U>
          Mapper gives a name to a simple function.
static interface CollectionUtils.Predicate<T>
          Predicate defines a boolean predicate function interface.
 
Field Summary
static CollectionUtils.Mapper<String,Object> TOSTRINGS
           
 
Constructor Summary
CollectionUtils()
           
 
Method Summary
static LinkedList<Integer> asList(int[] vals)
           
static
<T> String
collectionToString(Collection<T> col, String sep)
           
static
<T> boolean
contains(Collection<T> col, T obj)
           
static
<T> boolean
contains(T[] array, T obj)
           
static
<T> boolean
containsAllEqual(Collection<T> col, Collection<T> other)
          Attention: runs in n*n
static
<T> boolean
containsEqual(Collection<T> col, T obj)
           
static
<T> LinkedList<T>
filter(Collection<T> col, CollectionUtils.Predicate<T> pred)
           
static
<T> T
find(Collection<T> col, CollectionUtils.Predicate<T> pred)
           
static
<T> T
find(T[] array, CollectionUtils.Predicate<T> pred)
           
static
<T> T
fold(T identity, Collection<T> col, CollectionUtils.Folder<T> folder)
           
static
<T> T
last(T[] ts)
           
static
<T,U> LinkedList<T>
map(Collection<U> col, CollectionUtils.Mapper<T,U> mapper)
          Wraps a for loop and the creation of a new list.
static
<T,U> LinkedList<T>
map(U[] col, CollectionUtils.Mapper<T,U> mapper)
          Wraps a for loop and the creation of a new list.
static
<T,U> LinkedHashMap<T,U>
unzip(Collection<Pair<T,U>> col)
          Not quite zip...
static
<T,U> LinkedList<Pair<T,U>>
zip(Map<T,U> map)
          Not quite unzip...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOSTRINGS

public static final CollectionUtils.Mapper<String,Object> TOSTRINGS
Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

collectionToString

public static <T> String collectionToString(Collection<T> col,
                                            String sep)
Type Parameters:
T -
Parameters:
col - may not contain null values
sep - the separating string
Returns:
a comma separated list of #toString values

map

public static <T,U> LinkedList<T> map(U[] col,
                                      CollectionUtils.Mapper<T,U> mapper)
Wraps a for loop and the creation of a new list.

Type Parameters:
T -
U -
Parameters:
col -
mapper -
Returns:
a list where the mapper has been applied to each element in the map

map

public static <T,U> LinkedList<T> map(Collection<U> col,
                                      CollectionUtils.Mapper<T,U> mapper)
Wraps a for loop and the creation of a new list.

Type Parameters:
T -
U -
Parameters:
col -
mapper -
Returns:
a list where the mapper has been applied to each element in the map

contains

public static <T> boolean contains(T[] array,
                                   T obj)
Type Parameters:
T -
Parameters:
array -
obj -
Returns:
true, if the object is contained within the array

contains

public static <T> boolean contains(Collection<T> col,
                                   T obj)
Type Parameters:
T -
Parameters:
col -
obj -
Returns:
true, if the object is contained within the collection

containsEqual

public static <T> boolean containsEqual(Collection<T> col,
                                        T obj)
Type Parameters:
T -
Parameters:
col -
obj -
Returns:
true, if an equal object is contained

containsAllEqual

public static <T> boolean containsAllEqual(Collection<T> col,
                                           Collection<T> other)
Attention: runs in n*n

Type Parameters:
T -
Parameters:
col -
other -
Returns:
true, if all elements in col have an equal in other

find

public static <T> T find(T[] array,
                         CollectionUtils.Predicate<T> pred)
Type Parameters:
T -
Parameters:
array -
pred -
Returns:
the first object for which the predicate is true, or null

find

public static <T> T find(Collection<T> col,
                         CollectionUtils.Predicate<T> pred)
Type Parameters:
T -
Parameters:
col -
pred -
Returns:
the first object for which the predicate is true, or null

filter

public static <T> LinkedList<T> filter(Collection<T> col,
                                       CollectionUtils.Predicate<T> pred)
Type Parameters:
T -
Parameters:
col -
pred -
Returns:
only those T, for which the pred is true

fold

public static <T> T fold(T identity,
                         Collection<T> col,
                         CollectionUtils.Folder<T> folder)
Type Parameters:
T -
Parameters:
identity -
col -
folder -
Returns:
the folded value

asList

public static LinkedList<Integer> asList(int[] vals)
Parameters:
vals -
Returns:
the array as list

unzip

public static <T,U> LinkedHashMap<T,U> unzip(Collection<Pair<T,U>> col)
Not quite zip...

Type Parameters:
T -
U -
Parameters:
col -
Returns:
a map with the first pair components mapping to the second

zip

public static <T,U> LinkedList<Pair<T,U>> zip(Map<T,U> map)
Not quite unzip...

Type Parameters:
T -
U -
Parameters:
map -
Returns:
a list with the keys paired with their values

last

public static <T> T last(T[] ts)
Type Parameters:
T -
Parameters:
ts -
Returns:
the last element or null

deegree 2.3 (2010/04/09 10:10 build-4-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org