deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

org.deegree.commons.utils
Class CollectionUtils

java.lang.Object
  extended by org.deegree.commons.utils.CollectionUtils

public class CollectionUtils
extends Object

CollectionUtils

Version:
$Revision: 21302 $, $Date: 2009-12-08 09:30:46 +0100 (Di, 08 Dez 2009) $
Author:
Andreas Schmitz, last edited by: $Author: aschmitz $

Nested Class Summary
static interface CollectionUtils.Mapper<T,U>
          Mapper gives a name to a simple function.
static interface CollectionUtils.Reducer<T>
          Reducer
 
Field Summary
static CollectionUtils.Reducer<Boolean> AND
           
static CollectionUtils.Mapper<String,double[]> DOUBLE_PRINTER
          Use like this: System.out.println(map(List object, DOUBLE_PRINTER)) Unfortunately, a generic version for all primitive-arrays is not possible...
 
Constructor Summary
CollectionUtils()
           
 
Method Summary
static
<T> CollectionUtils.Mapper<String,T[]>
getArrayPrinter()
           
static
<T> CollectionUtils.Mapper<Boolean,T>
getInstanceofMapper(Class<?> c)
           
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> T
reduce(T identity, Collection<T> col, CollectionUtils.Reducer<T> reducer)
           
static
<T> List<T>
removeDuplicates(List<T> list)
           
static
<T,U> Pair<ArrayList<T>,ArrayList<U>>
unzip(Collection<Pair<T,U>> col)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOUBLE_PRINTER

public static final CollectionUtils.Mapper<String,double[]> DOUBLE_PRINTER
Use like this: System.out.println(map(List object, DOUBLE_PRINTER)) Unfortunately, a generic version for all primitive-arrays is not possible...


AND

public static final CollectionUtils.Reducer<Boolean> AND
Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

getArrayPrinter

public static <T> CollectionUtils.Mapper<String,T[]> getArrayPrinter()
Type Parameters:
T -
Returns:
a mapper to output an object array

getInstanceofMapper

public static <T> CollectionUtils.Mapper<Boolean,T> getInstanceofMapper(Class<?> c)
Type Parameters:
T -
Parameters:
c -
Returns:
a list of booleans, true if u instanceof c

removeDuplicates

public static <T> List<T> removeDuplicates(List<T> list)
Type Parameters:
T -
Parameters:
list -
Returns:
removes any duplicates in the list. Keeps the first occurrence of duplicates.

unzip

public static <T,U> Pair<ArrayList<T>,ArrayList<U>> unzip(Collection<Pair<T,U>> col)
Type Parameters:
T -
U -
Parameters:
col -
Returns:
two separate lists

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

reduce

public static <T> T reduce(T identity,
                           Collection<T> col,
                           CollectionUtils.Reducer<T> reducer)
Type Parameters:
T -
Parameters:
identity -
col -
reducer -
Returns:
the folded value

deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

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

]]>