com.evanmclean.evlib.util
Class Colls

java.lang.Object
  extended by com.evanmclean.evlib.util.Colls

public final class Colls
extends Object

Factory for creating collection objects with a bit of short-hand (plus a few other utilities). See this article about how it works.

Quick example:

ArrayList<String> arrlist = CollFactory.newArrayList()

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Method Summary
static
<E> ArrayList<E>
newArrayList()
           
static
<E> ArrayList<E>
newArrayList(Collection<? extends E> coll)
           
static
<E> ArrayList<E>
newArrayList(int initial_capacity)
           
static
<K extends Enum<K>,V>
EnumMap<K,V>
newEnumMap(Class<K> key_type)
           
static
<K extends Enum<K>,V>
EnumMap<K,V>
newEnumMap(EnumMap<K,? extends V> map)
           
static
<K extends Enum<K>,V>
EnumMap<K,V>
newEnumMap(Map<K,? extends V> map)
           
static
<K,V> HashMap<K,V>
newHashMap()
           
static
<K,V> HashMap<K,V>
newHashMap(int initial_capacity)
           
static
<K,V> HashMap<K,V>
newHashMap(int initial_capacity, float load_factor)
           
static
<K,V> HashMap<K,V>
newHashMap(Map<? extends K,? extends V> map)
           
static
<V> HashSet<V>
newHashSet()
           
static
<V> HashSet<V>
newHashSet(Collection<? extends V> coll)
           
static
<V> HashSet<V>
newHashSet(int initial_capacity)
           
static
<V> HashSet<V>
newHashSet(int initial_capacity, float load_factor)
           
static
<K,V> Hashtable<K,V>
newHashtable()
           
static
<K,V> Hashtable<K,V>
newHashtable(int initial_capacity)
           
static
<K,V> Hashtable<K,V>
newHashtable(int initial_capacity, float load_factor)
           
static
<K,V> Hashtable<K,V>
newHashtable(Map<? extends K,? extends V> map)
           
static
<K,V> IdentityHashMap<K,V>
newIdentityHashMap()
           
static
<K,V> IdentityHashMap<K,V>
newIdentityHashMap(int expected_max_size)
           
static
<K,V> IdentityHashMap<K,V>
newIdentityHashMap(Map<? extends K,? extends V> map)
           
static
<K,V> LinkedHashMap<K,V>
newLinkedHashMap()
           
static
<K,V> LinkedHashMap<K,V>
newLinkedHashMap(int initial_capacity)
           
static
<K,V> LinkedHashMap<K,V>
newLinkedHashMap(int initial_capacity, float load_factor)
           
static
<K,V> LinkedHashMap<K,V>
newLinkedHashMap(int initial_capacity, float load_factor, boolean access_order)
           
static
<K,V> LinkedHashMap<K,V>
newLinkedHashMap(Map<? extends K,? extends V> map)
           
static
<V> LinkedHashSet<V>
newLinkedHashSet()
           
static
<V> LinkedHashSet<V>
newLinkedHashSet(Collection<? extends V> coll)
           
static
<V> LinkedHashSet<V>
newLinkedHashSet(int initial_capacity)
           
static
<V> LinkedHashSet<V>
newLinkedHashSet(int initial_capacity, float load_factor)
           
static
<V> LinkedList<V>
newLinkedList()
           
static
<V> LinkedList<V>
newLinkedList(Collection<? extends V> coll)
           
static
<V> PriorityQueue<V>
newPriorityQueue()
           
static
<V> PriorityQueue<V>
newPriorityQueue(Collection<? extends V> coll)
           
static
<V> PriorityQueue<V>
newPriorityQueue(int initial_capacity)
           
static
<V> PriorityQueue<V>
newPriorityQueue(int initial_capacity, Comparator<? super V> comparator)
           
static
<V> PriorityQueue<V>
newPriorityQueue(PriorityQueue<? extends V> queue)
           
static
<V> PriorityQueue<V>
newPriorityQueue(SortedSet<? extends V> set)
           
static
<K,V> TreeMap<K,V>
newTreeMap()
           
static
<K,V> TreeMap<K,V>
newTreeMap(Comparator<? super K> comparator)
           
static
<K,V> TreeMap<K,V>
newTreeMap(Map<? extends K,? extends V> map)
           
static
<K,V> TreeMap<K,V>
newTreeMap(SortedMap<? extends K,? extends V> map)
           
static
<V> TreeMapIgnoreCase<V>
newTreeMapIgnoreCase()
           
static
<V> TreeMapIgnoreCase<V>
newTreeMapIgnoreCase(Map<String,? extends V> map)
           
static
<V> TreeSet<V>
newTreeSet()
           
static
<V> TreeSet<V>
newTreeSet(Collection<? extends V> coll)
           
static
<V> TreeSet<V>
newTreeSet(Comparator<? super V> comparator)
           
static
<V> TreeSet<V>
newTreeSet(SortedSet<V> set)
           
static
<E> Vector<E>
newVector()
           
static
<E> Vector<E>
newVector(Collection<? extends E> coll)
           
static
<E> Vector<E>
newVector(int initial_capacity)
           
static
<E> Vector<E>
newVector(int initial_capacity, int capacity_increment)
           
static
<K,V> WeakHashMap<K,V>
newWeakHashMap()
           
static
<K,V> WeakHashMap<K,V>
newWeakHashMap(int initial_capacity)
           
static
<K,V> WeakHashMap<K,V>
newWeakHashMap(int initial_capacity, float load_factor)
           
static
<K,V> WeakHashMap<K,V>
newWeakHashMap(Map<? extends K,? extends V> map)
           
static
<T,E extends Collection<T>>
E
nullIfEmpty(E coll)
          Returns the collection, list, map, set, etc if it is not empty, otherwise returns null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newArrayList

public static <E> ArrayList<E> newArrayList()

newArrayList

public static <E> ArrayList<E> newArrayList(Collection<? extends E> coll)

newArrayList

public static <E> ArrayList<E> newArrayList(int initial_capacity)

newEnumMap

public static <K extends Enum<K>,V> EnumMap<K,V> newEnumMap(Class<K> key_type)

newEnumMap

public static <K extends Enum<K>,V> EnumMap<K,V> newEnumMap(EnumMap<K,? extends V> map)

newEnumMap

public static <K extends Enum<K>,V> EnumMap<K,V> newEnumMap(Map<K,? extends V> map)

newHashMap

public static <K,V> HashMap<K,V> newHashMap()

newHashMap

public static <K,V> HashMap<K,V> newHashMap(int initial_capacity)

newHashMap

public static <K,V> HashMap<K,V> newHashMap(int initial_capacity,
                                            float load_factor)

newHashMap

public static <K,V> HashMap<K,V> newHashMap(Map<? extends K,? extends V> map)

newHashSet

public static <V> HashSet<V> newHashSet()

newHashSet

public static <V> HashSet<V> newHashSet(Collection<? extends V> coll)

newHashSet

public static <V> HashSet<V> newHashSet(int initial_capacity)

newHashSet

public static <V> HashSet<V> newHashSet(int initial_capacity,
                                        float load_factor)

newHashtable

public static <K,V> Hashtable<K,V> newHashtable()

newHashtable

public static <K,V> Hashtable<K,V> newHashtable(int initial_capacity)

newHashtable

public static <K,V> Hashtable<K,V> newHashtable(int initial_capacity,
                                                float load_factor)

newHashtable

public static <K,V> Hashtable<K,V> newHashtable(Map<? extends K,? extends V> map)

newIdentityHashMap

public static <K,V> IdentityHashMap<K,V> newIdentityHashMap()

newIdentityHashMap

public static <K,V> IdentityHashMap<K,V> newIdentityHashMap(int expected_max_size)

newIdentityHashMap

public static <K,V> IdentityHashMap<K,V> newIdentityHashMap(Map<? extends K,? extends V> map)

newLinkedHashMap

public static <K,V> LinkedHashMap<K,V> newLinkedHashMap()

newLinkedHashMap

public static <K,V> LinkedHashMap<K,V> newLinkedHashMap(int initial_capacity)

newLinkedHashMap

public static <K,V> LinkedHashMap<K,V> newLinkedHashMap(int initial_capacity,
                                                        float load_factor)

newLinkedHashMap

public static <K,V> LinkedHashMap<K,V> newLinkedHashMap(int initial_capacity,
                                                        float load_factor,
                                                        boolean access_order)

newLinkedHashMap

public static <K,V> LinkedHashMap<K,V> newLinkedHashMap(Map<? extends K,? extends V> map)

newLinkedHashSet

public static <V> LinkedHashSet<V> newLinkedHashSet()

newLinkedHashSet

public static <V> LinkedHashSet<V> newLinkedHashSet(Collection<? extends V> coll)

newLinkedHashSet

public static <V> LinkedHashSet<V> newLinkedHashSet(int initial_capacity)

newLinkedHashSet

public static <V> LinkedHashSet<V> newLinkedHashSet(int initial_capacity,
                                                    float load_factor)

newLinkedList

public static <V> LinkedList<V> newLinkedList()

newLinkedList

public static <V> LinkedList<V> newLinkedList(Collection<? extends V> coll)

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue()

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue(Collection<? extends V> coll)

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue(int initial_capacity)

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue(int initial_capacity,
                                                    Comparator<? super V> comparator)

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue(PriorityQueue<? extends V> queue)

newPriorityQueue

public static <V> PriorityQueue<V> newPriorityQueue(SortedSet<? extends V> set)

newTreeMap

public static <K,V> TreeMap<K,V> newTreeMap()

newTreeMap

public static <K,V> TreeMap<K,V> newTreeMap(Comparator<? super K> comparator)

newTreeMap

public static <K,V> TreeMap<K,V> newTreeMap(Map<? extends K,? extends V> map)

newTreeMap

public static <K,V> TreeMap<K,V> newTreeMap(SortedMap<? extends K,? extends V> map)

newTreeMapIgnoreCase

public static <V> TreeMapIgnoreCase<V> newTreeMapIgnoreCase()

newTreeMapIgnoreCase

public static <V> TreeMapIgnoreCase<V> newTreeMapIgnoreCase(Map<String,? extends V> map)

newTreeSet

public static <V> TreeSet<V> newTreeSet()

newTreeSet

public static <V> TreeSet<V> newTreeSet(Collection<? extends V> coll)

newTreeSet

public static <V> TreeSet<V> newTreeSet(Comparator<? super V> comparator)

newTreeSet

public static <V> TreeSet<V> newTreeSet(SortedSet<V> set)

newVector

public static <E> Vector<E> newVector()

newVector

public static <E> Vector<E> newVector(Collection<? extends E> coll)

newVector

public static <E> Vector<E> newVector(int initial_capacity)

newVector

public static <E> Vector<E> newVector(int initial_capacity,
                                      int capacity_increment)

newWeakHashMap

public static <K,V> WeakHashMap<K,V> newWeakHashMap()

newWeakHashMap

public static <K,V> WeakHashMap<K,V> newWeakHashMap(int initial_capacity)

newWeakHashMap

public static <K,V> WeakHashMap<K,V> newWeakHashMap(int initial_capacity,
                                                    float load_factor)

newWeakHashMap

public static <K,V> WeakHashMap<K,V> newWeakHashMap(Map<? extends K,? extends V> map)

nullIfEmpty

public static <T,E extends Collection<T>> E nullIfEmpty(E coll)
Returns the collection, list, map, set, etc if it is not empty, otherwise returns null.

Parameters:
coll - The container object to examine.
Returns:
The collection unless it is null or empty.