deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.framework.util
Class CollectionUtils

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

public class CollectionUtils
extends java.lang.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<java.lang.String,java.lang.Object> TOSTRINGS
           
 
Constructor Summary
CollectionUtils()
           
 
Method Summary
static java.util.LinkedList<java.lang.Integer> asList(int[] vals)
           
static
<T> java.lang.String
collectionToString(java.util.Collection<T> col, java.lang.String sep)
           
static
<T> boolean
contains(java.util.Collection<T> col, T obj)
           
static
<T> boolean
contains(T[] array, T obj)
           
static
<T> boolean
containsAllEqual(java.util.Collection<T> col, java.util.Collection<T> other)
          Attention: runs in n*n
static
<T> boolean
containsEqual(java.util.Collection<T> col, T obj)
           
static
<T> java.util.LinkedList<T>
filter(java.util.Collection<T> col, CollectionUtils.Predicate<T> pred)
           
static
<T> T
find(java.util.Collection<T> col, CollectionUtils.Predicate<T> pred)
           
static
<T> T
find(T[] array, CollectionUtils.Predicate<T> pred)
           
static
<T> T
fold(T identity, java.util.Collection<T> col, CollectionUtils.Folder<T> folder)
           
static
<T> T
last(T[] ts)
           
static
<T,U> java.util.LinkedList<T>
map(java.util.Collection<U> col, CollectionUtils.Mapper<T,U> mapper)
          Wraps a for loop and the creation of a new list.
static
<T,U> java.util.LinkedList<T>
map(U[] col, CollectionUtils.Mapper<T,U> mapper)
          Wraps a for loop and the creation of a new list.
static
<T,U> java.util.LinkedHashMap<T,U>
unzip(java.util.Collection<Pair<T,U>> col)
          Not quite zip...
static
<T,U> java.util.LinkedList<Pair<T,U>>
zip(java.util.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<java.lang.String,java.lang.Object> TOSTRINGS
Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

collectionToString

public static <T> java.lang.String collectionToString(java.util.Collection<T> col,
                                                      java.lang.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> java.util.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> java.util.LinkedList<T> map(java.util.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(java.util.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(java.util.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(java.util.Collection<T> col,
                                           java.util.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(java.util.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> java.util.LinkedList<T> filter(java.util.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,
                         java.util.Collection<T> col,
                         CollectionUtils.Folder<T> folder)
Type Parameters:
T -
Parameters:
identity -
col -
folder -
Returns:
the folded value

asList

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

unzip

public static <T,U> java.util.LinkedHashMap<T,U> unzip(java.util.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> java.util.LinkedList<Pair<T,U>> zip(java.util.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.5 (2011/06/29 09:44 build-8-official)

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