org.eel.kitchen.util
Class CollectionUtils

java.lang.Object
  extended by org.eel.kitchen.util.CollectionUtils

public final class CollectionUtils
extends Object

Utilities to provide simple generics equivalents to some of Apache's commons-collection package (which still doesn't use generics as of 2011!)


Constructor Summary
CollectionUtils()
           
 
Method Summary
static
<K,V> Map<K,V>
toMap(Iterator<Map.Entry<K,V>> iterator)
          Generics equivalent of commons-collections' IteratorUtils.toMap()
static
<T> Set<T>
toSet(Iterator<T> iterator)
          Return a "type-safe" set
static
<K,V> SortedMap<K,V>
toSortedMap(Iterator<Map.Entry<K,V>> iterator)
          Like #toMap, but returns a SortedMap instead of a plain Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

toMap

public static <K,V> Map<K,V> toMap(Iterator<Map.Entry<K,V>> iterator)

Generics equivalent of commons-collections' IteratorUtils.toMap()

Type Parameters:
K - keys type
V - values type
Parameters:
iterator - The entry iterator to build the map out of
Returns:
a type-safe HashMap

toSortedMap

public static <K,V> SortedMap<K,V> toSortedMap(Iterator<Map.Entry<K,V>> iterator)
Like #toMap, but returns a SortedMap instead of a plain Map. Note that it returns a TreeMap, which is not thread-safe (we don't need it in our context anyway).

Type Parameters:
K - keys type
V - values type
Parameters:
iterator - The entry iterator to build the map out of
Returns:
a type-safe TreeMap

toSet

public static <T> Set<T> toSet(Iterator<T> iterator)

Return a "type-safe" set

Type Parameters:
T - elements type
Parameters:
iterator - the iterator to build the set out of
Returns:
a type-safe HashSet


Copyright © 2012. All Rights Reserved.