|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.CollectionUtils
public class CollectionUtils
Collection of useful static methods for working with Collections. Includes methods to increment counts in maps and cast list/map elements to common types.
Method Summary | ||
---|---|---|
static List |
asList(double[] a)
|
|
static List |
asList(int[] a)
|
|
static List |
asList(Object... args)
Returns a new List containing the specified objects. |
|
static Set |
asSet(Object[] o)
Returns a new Set containing all the objects in the specified array. |
|
static boolean |
containsObject(Collection c,
Object o)
Checks whether a Collection contains a specified Object. |
|
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 |
getIndex(List l,
Object o)
Returns the index of the first occurrence in the list of the specified object, using object identity (==) not equality as the criterion for object presence. |
|
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 Map |
getMapFromString(String s,
Class keyClass,
Class valueClass,
MapFactory mapFactory)
|
|
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. |
|
static boolean |
isSubList(List l1,
List l)
Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l, and for every e1 < e2 in l1, there is an e1 < e2 occurrence in l). |
|
static Collection |
loadCollection(File file,
Class c,
CollectionFactory cf)
|
|
static Collection |
loadCollection(String filename,
Class c,
CollectionFactory cf)
|
|
static void |
main(String[] args)
|
|
static
|
makeList(T e)
Returns a new List containing the given object. |
|
static
|
makeList(T e1,
T e2)
Returns a new List containing the given objects. |
|
static
|
makeList(T e1,
T e2,
T e3)
Returns a new List containing the given objects. |
|
static boolean |
removeObject(List l,
Object o)
Removes the first occurrence in the list of the specified object, using object identity (==) not equality as the criterion for object presence. |
|
static
|
sampleWithoutReplacement(Collection<E> c,
int n)
Samples without replacement from a collection |
|
static
|
sampleWithoutReplacement(Collection<E> c,
int n,
Random r)
Samples without replacement from a collection, using your own Random number generator |
|
static
|
sampleWithReplacement(Collection<E> c,
int n)
Samples with replacement from a collection |
|
static
|
sampleWithReplacement(Collection<E> c,
int n,
Random r)
Samples with replacement from a collection, using your own Random number generator |
|
static String |
toVerticalString(Map m)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean incrementCount(Map map, Object key, int delta)
map
- Map from keys to Integer values representing key countskey
- key in map for Integer to incrementdelta
- amount to change Integer value count by
public static boolean incrementCount(Map map, Object key)
incrementCount(Map,Object,int)
public static String getString(List list, int index)
public static Integer getInteger(List list, int index)
public static int getInt(List list, int index)
public static Double getDouble(List list, int index)
public static double getdouble(List list, int index)
public static boolean getBoolean(List list, int index)
public static String getString(Map map, Object key)
public static Integer getInteger(Map map, Object key)
public static int getInt(Map list, Object key)
public static Double getDouble(Map map, Object key)
public static double getdouble(Map map, Object key)
public static boolean getBoolean(Map map, Object key)
public static List asList(int[] a)
public static List asList(double[] a)
public static List asList(Object... args)
public static <T> List<T> makeList(T e)
public static <T> List<T> makeList(T e1, T e2)
public static <T> List<T> makeList(T e1, T e2, T e3)
public static Set asSet(Object[] o)
public static Collection loadCollection(String filename, Class c, CollectionFactory cf) throws Exception
filename
- the path to the file to load the List fromc
- the Class to instantiate each member of the List. Must have a String constructor.cf
-
Exception
public static Collection loadCollection(File file, Class c, CollectionFactory cf) throws Exception
file
- the file to load the List fromc
- the Class to instantiate each member of the List. Must have a String constructor.
Exception
public static Map getMapFromString(String s, Class keyClass, Class valueClass, MapFactory mapFactory) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InvocationTargetException
InstantiationException
public static boolean containsObject(Collection c, Object o)
public static boolean removeObject(List l, Object o)
l
- The List
from which to remove the objecto
- The object to be removed.
public static int getIndex(List l, Object o)
l
- The List
to find the object in.o
- The sought-after object.
public static <E> Collection<E> sampleWithoutReplacement(Collection<E> c, int n)
c
- The collection to be sampled fromn
- The number of samples to take
public static <E> Collection<E> sampleWithoutReplacement(Collection<E> c, int n, Random r)
Random
number generator
c
- The collection to be sampled fromn
- The number of samples to taker
- the random number generator
public static <E> Collection<E> sampleWithReplacement(Collection<E> c, int n)
c
- The collection to be sampled fromn
- The number of samples to take
public static <E> Collection<E> sampleWithReplacement(Collection<E> c, int n, Random r)
Random
number generator
c
- The collection to be sampled fromn
- The number of samples to taker
- the random number generator
public static boolean isSubList(List l1, List l)
l
- l1
-
public static String toVerticalString(Map m)
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |