public final class CollectionsPlume
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CollectionsPlume.EnumerationIterator<T>
Converts an Enumeration into an Iterator.
|
static class |
CollectionsPlume.FilteredIterator<T>
An iterator that only returns elements that match the given Filter.
|
static class |
CollectionsPlume.IteratorEnumeration<T>
Converts an Iterator into an Enumeration.
|
static class |
CollectionsPlume.MergedIterator<T>
An Iterator that returns the elements in each of its argument Iterators, in turn.
|
static class |
CollectionsPlume.MergedIterator2<T>
An Iterator that returns first the elements returned by its first argument, then the elements
returned by its second argument.
|
static class |
CollectionsPlume.RemoveFirstAndLastIterator<T>
Returns an iterator just like its argument, except that the first and last elements are
removed.
|
| Modifier and Type | Method and Description |
|---|---|
static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> |
createCombinations(int arity,
int start,
int cnt)
Returns a list of lists of each combination (with repetition, but not permutations) of integers
from start to cnt (inclusive) over arity dimensions.
|
static <T> java.util.List<java.util.List<T>> |
createCombinations(int dims,
int start,
java.util.List<T> objs)
Returns a list of lists of each combination (with repetition, but not permutations) of the
specified objects starting at index
start over dims dimensions, for dims
> 0. |
static boolean |
deepEquals(@Nullable java.lang.Object o1,
@Nullable java.lang.Object o2)
Determines deep equality for the elements.
|
static @Nullable java.lang.Object |
getFromSet(java.util.Set<?> set,
java.lang.Object key)
Return the object in this set that is equal to key.
|
static <K> @Nullable java.lang.Integer |
incrementMap(java.util.Map<K,java.lang.Integer> m,
K key)
Increment the Integer which is indexed by key in the Map.
|
static <K> @Nullable java.lang.Integer |
incrementMap(java.util.Map<K,java.lang.Integer> m,
K key,
int count)
Increment the Integer which is indexed by key in the Map.
|
static <T> java.lang.Iterable<T> |
iteratorToIterable(java.util.Iterator<T> source)
Converts an Iterator to an Iterable.
|
static <T> java.util.ArrayList<T> |
makeArrayList(java.util.Enumeration<T> e)
Returns a vector containing the elements of the enumeration.
|
static <K,V> void |
mapToString(java.lang.Appendable sb,
java.util.Map<K,V> m,
java.lang.String linePrefix)
Write a multi-line representation of the map into the given Appendable (e.g., a StringBuilder).
|
static <K,V> java.lang.String |
mapToString(java.util.Map<K,V> m)
Returns a multi-line string representation of a map.
|
static <T> java.util.List<T> |
randomElements(java.util.Iterator<T> itor,
int numElts)
Return a List containing numElts randomly chosen elements from the iterator, or all the
elements of the iterator if there are fewer.
|
static <T> java.util.List<T> |
randomElements(java.util.Iterator<T> itor,
int numElts,
java.util.Random random)
Return a List containing numElts randomly chosen elements from the iterator, or all the
elements of the iterator if there are fewer.
|
static <T> java.util.List<T> |
removeDuplicates(java.util.List<T> l)
Return a copy of the list with duplicates removed.
|
static <K extends java.lang.Comparable<? super K>,V> |
sortedKeySet(java.util.Map<K,V> m)
Returns a sorted version of m.keySet().
|
static <K,V> java.util.Collection<K> |
sortedKeySet(java.util.Map<K,V> m,
java.util.Comparator<K> comparator)
Returns a sorted version of m.keySet().
|
static <T> java.util.List<T> |
sortList(java.util.List<T> l,
java.util.Comparator<? super T> c)
Return the sorted version of the list.
|
public static <T> java.util.List<T> sortList(java.util.List<T> l,
java.util.Comparator<? super T> c)
Collections.sort(List<T>, Comparator<? super T>).T - type of elements of the listl - a list to sortc - a sorted version of the listpublic static <T> java.util.List<T> removeDuplicates(java.util.List<T> l)
T - type of elements of the listl - a list to remove duplicates from@Pure
public static boolean deepEquals(@Nullable java.lang.Object o1,
@Nullable java.lang.Object o2)
o1 - first value to compareo2 - second value to comparepublic static <T> java.util.ArrayList<T> makeArrayList(java.util.Enumeration<T> e)
T - type of the enumeration and vector elementse - an enumeration to convert to a ArrayListpublic static <T> java.util.List<java.util.List<T>> createCombinations(int dims,
int start,
java.util.List<T> objs)
start over dims dimensions, for dims
> 0.
For example, createCombinations(1, 0, {a, b, c}) returns a 3-element list of singleton lists:
{a}, {b}, {c}
And createCombinations(2, 0, {a, b, c}) returns a 6-element list of 2-element lists:
{a, a}, {a, b}, {a, c}
{b, b}, {b, c},
{c, c}
T - type of the input list elements, and type of the innermost output list elementsdims - number of dimensions: that is, size of each innermost liststart - initial indexobjs - list of elements to create combinations ofpublic static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> createCombinations(int arity,
int start,
int cnt)
For example, createCombinations(1, 0, 2) returns a 3-element list of singleton lists:
{0}, {1}, {2}
And createCombinations(2, 10, 2) returns a 6-element list of 2-element lists:
{10, 10}, {10, 11}, {10, 12}, {11, 11}, {11, 12}, {12, 12}
The length of the list is (cnt multichoose arity), which is ((cnt + arity - 1) choose arity).arity - size of each innermost liststart - initial valuecnt - maximum element valuepublic static <T> java.lang.Iterable<T> iteratorToIterable(java.util.Iterator<T> source)
T - the element typesource - the Iterator to be converted to Iterablepublic static <T> java.util.List<T> randomElements(java.util.Iterator<T> itor,
int numElts)
T - type of the iterator elementsitor - elements to be randomly selected fromnumElts - number of elements to selectpublic static <T> java.util.List<T> randomElements(java.util.Iterator<T> itor,
int numElts,
java.util.Random random)
T - type of the iterator elementsitor - elements to be randomly selected fromnumElts - number of elements to selectrandom - the Random instance to use to make selectionspublic static <K> @Nullable java.lang.Integer incrementMap(java.util.Map<K,java.lang.Integer> m,
K key)
K - type of keys in the mapm - map from K to Integerkey - the key whose value will be incrementedjava.lang.Error - if the key is in the Map but maps to a non-Integerpublic static <K> @Nullable java.lang.Integer incrementMap(java.util.Map<K,java.lang.Integer> m,
K key,
int count)
count if not
currently mapped.K - type of keys in the mapm - map from K to Integerkey - the key whose value will be incrementedcount - how much to increment the value byjava.lang.Error - if the key is in the Map but maps to a non-Integerpublic static <K,V> java.lang.String mapToString(java.util.Map<K,V> m)
K - type of map keysV - type of map valuesm - map to be converted to a stringpublic static <K,V> void mapToString(java.lang.Appendable sb,
java.util.Map<K,V> m,
java.lang.String linePrefix)
K - type of map keysV - type of map valuessb - an Appendable (such as StringBuilder) to which to write a multi-line string
representation of mm - map to be converted to a stringlinePrefix - prefix to write at the beginning of each linepublic static <K extends java.lang.Comparable<? super K>,V> java.util.Collection<K> sortedKeySet(java.util.Map<K,V> m)
K - type of the map keysV - type of the map valuesm - a map whose keyset will be sortedpublic static <K,V> java.util.Collection<K> sortedKeySet(java.util.Map<K,V> m,
java.util.Comparator<K> comparator)
K - type of the map keysV - type of the map valuesm - a map whose keyset will be sortedcomparator - the Comparator to use for sortingpublic static @Nullable java.lang.Object getFromSet(java.util.Set<?> set,
java.lang.Object key)
set - a set in which to look up the valuekey - the value to look up in the set