org.jaitools
Class CollectionFactory

java.lang.Object
  extended by org.jaitools.CollectionFactory

public class CollectionFactory
extends Object

Convenience methods to create generic collections following the DRY (Don't Repeat Yourself) principle. Examples of use:


 // simple
 List<Integer> list1 = CollectionFactory.list();
 
 // nested
 List<List<String>> list2 = CollectionFactory.list();
 
 // a multi-map
 Map<String, List<Integer>> multiMap = CollectionFactory.map();
 

Since:
1.0
Version:
$Id$
Author:
Michael Bedward

Constructor Summary
CollectionFactory()
           
 
Method Summary
static
<T> List<T>
list()
          Returns a new List object.
static
<K,V> Map<K,V>
map()
          Returns a new Map object.
static
<K,V> Map<K,V>
orderedMap()
          Returns a new Map object that maintains insertion order.
static
<T> Set<T>
orderedSet()
          Returns a new Set instance that maintains the insertion order of its elements.
static
<T> Set<T>
set()
          Returns a new Set instance.
static
<K,V> SortedMap<K,V>
sortedMap()
          Returns a new SortedMap object.
static
<T> SortedSet<T>
sortedSet()
          Returns a new SortedSet instance.
static
<T> Stack<T>
stack()
          Returns a new Stack object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionFactory

public CollectionFactory()
Method Detail

map

public static <K,V> Map<K,V> map()
Returns a new Map object. The returned object is a HashMap.

Example of use:


 Map<Foo, Bar> myMap = CollectionFactory.map();
 

Type Parameters:
K - key type
V - value type
Returns:
a new Map<K,V> instance

orderedMap

public static <K,V> Map<K,V> orderedMap()
Returns a new Map object that maintains insertion order. The returned object is a LinkedHashMap.

Example of use:


 Map<Foo, Bar> myMap = CollectionFactory.orderedMap();
 

Type Parameters:
K - key type
V - value type
Returns:
a new Map<K,V> instance

sortedMap

public static <K,V> SortedMap<K,V> sortedMap()
Returns a new SortedMap object. Key type K must implement Comparable. The returned object is a TreeMap.

Example of use:


 Map<Foo, Bar> myMap = CollectionFactory.sortedMap();
 

Type Parameters:
K - key type
V - value type
Returns:
a new SortedMap<K,V> instance

list

public static <T> List<T> list()
Returns a new List object. The returned object is an ArrayList.

Example of use:


 List<Foo> myList = CollectionFactory.list();
 

Type Parameters:
T - element type
Returns:
a new List<T> instance

stack

public static <T> Stack<T> stack()
Returns a new Stack object.

Example of use:


 Stack<Foo> myStack = CollectionFactory.stack();
 

Type Parameters:
T - element type
Returns:
a new Stack<T> instance

set

public static <T> Set<T> set()
Returns a new Set instance. The returned object is a HashSet.

Example of use:


 Set<Foo> mySet = CollectionFactory.set();
 

Type Parameters:
T - element type
Returns:
a new HashSet<T> instance

orderedSet

public static <T> Set<T> orderedSet()
Returns a new Set instance that maintains the insertion order of its elements.

Example of use:


 Set<Foo> mySet = CollectionFactory.set();
 

Type Parameters:
T - element type
Returns:
a new LinkedHashSet<T> instance

sortedSet

public static <T> SortedSet<T> sortedSet()
Returns a new SortedSet instance. The type T must implement Comparable. The returned object is a TreeSet.

Example of use:


 Set<MyObject> foo = CollectionFactory.sortedSet();
 

Type Parameters:
T - element type
Returns:
a new TreeSet<T> instance


Copyright © 2009-2013. All Rights Reserved.