com.cleancode.util
Class CollectionsPlus

java.lang.Object
  extended by com.cleancode.util.CollectionsPlus

public final class CollectionsPlus
extends Object

Convenience methods for collection handling.

Since:
CleanCode 0.9
Version:
$Revision: 9 $
Author:
Michael Sorens

Field Summary
static String VERSION
          Current version of this class.
 
Method Summary
static
<T> void
fill(Collection<T> c, T[] data)
          A convenience method to initialize a collection from an array.
static
<T> void
fill(Map<T,T> map, T[][] data)
          A convenience method to initialize a map from a two-dimensional array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Current version of this class.

Method Detail

fill

public static <T> void fill(Map<T,T> map,
                            T[][] data)
A convenience method to initialize a map from a two-dimensional array. Each element of the arbitrary length array is itself a two-element array, the first element being the key, and the second being the value for the map.

Type Parameters:
T - Generic-type.
Parameters:
map - the Map to fill
data - the two-dimensional array from which to fill the map

fill

public static <T> void fill(Collection<T> c,
                            T[] data)
A convenience method to initialize a collection from an array. This lets you say, e.g.
   ArrayList a = new ArrayList();
   CollectionsPlus.fill(a, new String[] { "", null, "xyz" });
 
instead of this standard (but little known) language construct:
   ArrayList a = new ArrayList() {
     { add(""); add(null); add("xyz"); }
   };
 
The choice is mostly a matter of style.

Type Parameters:
T - Generic-type.
Parameters:
c - Collection to fill
data - the array from which to fill the collection


CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads