edu.stanford.nlp.util
Class CollectionUtils

java.lang.Object
  extended byedu.stanford.nlp.util.CollectionUtils

public class CollectionUtils
extends Object

Collection of useful static methods for working with Collections. Includes methods to increment counts in maps and cast list/map elements to common types.

Author:
Joseph Smarr (jsmarr@stanford.edu)

Method Summary
static boolean getBoolean(List list, int index)
          Returns ((Boolean)list.get(index)).booleanValue().
static boolean getBoolean(Map map, Object key)
          Returns ((Boolean)map.get(key)).booleanValue().
static double getdouble(List list, int index)
          Returns ((Double)list.get(index)).doubleValue().
static Double getDouble(List list, int index)
          Returns (Double)list.get(index).
static double getdouble(Map map, Object key)
          Returns ((Double)map.get(key)).doubleValue().
static Double getDouble(Map map, Object key)
          Returns (Double)map.get(key).
static int getInt(List list, int index)
          Returns ((Integer)list.get(index)).intValue().
static int getInt(Map list, Object key)
          Returns ((Integer)map.get(key)).intValue().
static Integer getInteger(List list, int index)
          Returns (Integer)list.get(index).
static Integer getInteger(Map map, Object key)
          Returns (Integer)map.get(key).
static String getString(List list, int index)
          Returns (String)list.get(index).
static String getString(Map map, Object key)
          Returns (String)map.get(key).
static boolean incrementCount(Map map, Object key)
          Increments the Integer count of the given key in the given Map by 1.
static boolean incrementCount(Map map, Object key, int delta)
          Adds the given delta to the Integer value stored for the given key in the given Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

incrementCount

public static boolean incrementCount(Map map,
                                     Object key,
                                     int delta)
Adds the given delta to the Integer value stored for the given key in the given Map. Returns whether the entry had to be created (i.e., it wasn't in the map), in which case it's inserted with delta as the initial value.

Parameters:
map - Map from keys to Integer values representing key counts
key - key in map for Integer to increment
delta - amount to change Integer value count by
Returns:
whether a new entry for the given key was created in the process (i.e., if it wasn't in the map before).

incrementCount

public static boolean incrementCount(Map map,
                                     Object key)
Increments the Integer count of the given key in the given Map by 1.

See Also:
incrementCount(Map,Object,int)

getString

public static String getString(List list,
                               int index)
Returns (String)list.get(index).


getInteger

public static Integer getInteger(List list,
                                 int index)
Returns (Integer)list.get(index).


getInt

public static int getInt(List list,
                         int index)
Returns ((Integer)list.get(index)).intValue().


getDouble

public static Double getDouble(List list,
                               int index)
Returns (Double)list.get(index).


getdouble

public static double getdouble(List list,
                               int index)
Returns ((Double)list.get(index)).doubleValue().


getBoolean

public static boolean getBoolean(List list,
                                 int index)
Returns ((Boolean)list.get(index)).booleanValue().


getString

public static String getString(Map map,
                               Object key)
Returns (String)map.get(key).


getInteger

public static Integer getInteger(Map map,
                                 Object key)
Returns (Integer)map.get(key).


getInt

public static int getInt(Map list,
                         Object key)
Returns ((Integer)map.get(key)).intValue().


getDouble

public static Double getDouble(Map map,
                               Object key)
Returns (Double)map.get(key).


getdouble

public static double getdouble(Map map,
                               Object key)
Returns ((Double)map.get(key)).doubleValue().


getBoolean

public static boolean getBoolean(Map map,
                                 Object key)
Returns ((Boolean)map.get(key)).booleanValue().



Stanford NLP Group