|
|||||||||
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
|
addAll(Collection<T> collection,
Iterable<? extends T> items)
Add all the items from an iterable to a collection. |
|
static List<Double> |
asList(double[] a)
|
|
static List<Integer> |
asList(int[] a)
|
|
static List<Object> |
asList(Object... args)
Returns a new List containing the specified objects. |
|
static
|
asSet(T[] o)
Returns a new Set containing all the objects in the specified array. |
|
static
|
compareLists(List<T> list1,
List<T> list2)
|
|
static
|
containsObject(Collection<T> c,
T o)
Checks whether a Collection contains a specified Object. |
|
static
|
getIndex(List<T> l,
T 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
|
getListComparator()
|
|
static
|
getMapFromString(String s,
Class<K> keyClass,
Class<V> valueClass,
MapFactory<K,V> mapFactory)
|
|
static
|
intersection(Set<T> set1,
Set<T> set2)
|
|
static
|
isSubList(List<T> l1,
List<? super T> 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
|
loadCollection(File file,
Class<T> itemClass,
Collection<T> collection)
Adds the items from the file to the collection. |
|
static
|
loadCollection(File file,
Class<T> c,
CollectionFactory<T> cf)
|
|
static
|
loadCollection(String fileName,
Class<T> itemClass,
Collection<T> collection)
Adds the items from the file to the collection. |
|
static
|
loadCollection(String filename,
Class<T> c,
CollectionFactory<T> cf)
|
|
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
|
removeObject(List<T> l,
T o)
Removes the first occurrence in the list of the specified object, using object identity (==) not equality as the criterion for object presence. |
|
static
|
sample(List<E> l,
Random r)
|
|
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
|
sorted(Iterable<T> items)
Return the items of an Iterable as a sorted list. |
|
static
|
toList(Iterable<T> items)
Create a list out of the items in the Iterable. |
|
static
|
toSet(Iterable<T> items)
Create a set out of the items in the Iterable. |
|
static
|
toVerticalString(Map<K,V> m)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static List<Integer> asList(int[] a)
public static List<Double> asList(double[] a)
public static List<Object> 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 <T> Set<T> asSet(T[] o)
public static <T> Set<T> intersection(Set<T> set1, Set<T> set2)
public static <T> Collection<T> loadCollection(String filename, Class<T> c, CollectionFactory<T> 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.
Exception
public static <T> Collection<T> loadCollection(File file, Class<T> c, CollectionFactory<T> 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 <T> void loadCollection(String fileName, Class<T> itemClass, Collection<T> collection) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, IOException
T
- The type of the items.fileName
- The name of the file from which items should be loaded.itemClass
- The class of the items (must have a constructor that accepts a String).collection
- The collection to which items should be added.
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException
IOException
public static <T> void loadCollection(File file, Class<T> itemClass, Collection<T> collection) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, IOException
T
- The type of the items.file
- The file from which items should be loaded.itemClass
- The class of the items (must have a constructor that accepts a String).collection
- The collection to which items should be added.
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException
IOException
public static <K,V> Map<K,V> getMapFromString(String s, Class<K> keyClass, Class<V> valueClass, MapFactory<K,V> mapFactory) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InvocationTargetException
InstantiationException
public static <T> boolean containsObject(Collection<T> c, T o)
public static <T> boolean removeObject(List<T> l, T o)
l
- The List
from which to remove the objecto
- The object to be removed.
public static <T> int getIndex(List<T> l, T 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> E sample(List<E> l, Random r)
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 <T> boolean isSubList(List<T> l1, List<? super T> l)
public static <K,V> String toVerticalString(Map<K,V> m)
public static <T extends Comparable<T>> int compareLists(List<T> list1, List<T> list2)
public static <C extends Comparable<C>> Comparator<List<C>> getListComparator()
public static <T extends Comparable<T>> List<T> sorted(Iterable<T> items)
T
- The type of items in the Iterable.items
- The collection to be sorted.
public static <T> List<T> toList(Iterable<T> items)
T
- The type of items in the Iterable.items
- The items to be made into a list.
public static <T> Set<T> toSet(Iterable<T> items)
T
- The type of items in the Iterable.items
- The items to be made into a set.
public static <T> void addAll(Collection<T> collection, Iterable<? extends T> items)
T
- The type of items in the iterable and the collectioncollection
- The collection to which the items should be added.items
- The items to add to the collection.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |