|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ix.util.Collect
public final class Collect
Collection and Map utilities
Fn
,
Strings
,
Util
Nested Class Summary | |
---|---|
static class |
Collect.ShortestFirstComparator
A Comparator that orders shorter Collections before longer ones. |
Method Summary | ||
---|---|---|
static java.util.List |
append(java.util.List a,
java.util.List b)
Returns a new list of the same class as its first argument and that contains the elements of the first list followed by those of the second. |
|
static boolean |
areConsistent(java.util.Map m1,
java.util.Map m2)
Checks whether two maps are consistent. |
|
static boolean |
containsEq(java.util.Collection col,
java.lang.Object item)
Determines whether a collection contains an element == to an object. |
|
static java.util.Collection |
difference(java.util.Collection a,
java.util.Collection b)
Returns a new collection of the same class as its first argument and that contains the elements of the first collection that do not appear in the second. |
|
static java.util.Map |
difference(java.util.Map a,
java.util.Map b)
Returns a map of the same class as its first argument and that contains the entries from the first map that do not appear in the second. |
|
static boolean |
elementsMatch(java.util.List list,
java.lang.Class... classes)
Tests whether each element of the list is an instance of the corresponding class. |
|
static java.lang.String |
elementsToString(java.util.Collection c)
Returns the toString() representation of the elements
of the collection, separated by commas. |
|
static java.lang.String |
elementsToString(java.util.Collection c,
Function1 f)
Returns the toString() representation of the elements
of the collection as transformed by the function and separated by
commas. |
|
static java.util.List |
ensureList(java.util.List list)
Ensures that a value is a List object by returning an empty list if the value is null . |
|
static java.util.Map |
ensureMap(java.util.Map map)
Ensures that a value is a Map object by returning an empty map if the value is null . |
|
static boolean |
equalAsSets(java.util.Collection a,
java.util.Collection b)
Determines whether two collections have the same elements regardless of order. |
|
static boolean |
every(java.util.Collection c,
Predicate1 p)
Tests whether a predicate is true of every element of a collection. |
|
static java.util.Map |
extendMap(java.util.Map m,
java.util.Collection keys,
java.util.Collection values)
Adds entries to a map from a collection of keys and a parallel collection of values. |
|
static java.util.Collection |
filter(java.util.Collection result,
java.util.Collection c,
Predicate1 p)
Returns the result collection after adding the elements of another collection for which the predicate returned true; |
|
static java.util.Collection |
filter(java.util.Collection c,
Predicate1 p)
Returns a new collection of the same class as the original and containing only the elements for which the predicate returned true; |
|
static java.util.Map |
filter(java.util.Map result,
java.util.Map m,
Predicate2 p)
Returns the result map after adding a map's (key, value) entries for which a predicate returns true. |
|
static java.util.Map |
filter(java.util.Map m,
Predicate2 p)
Returns a new map of the same class as the original and containing only the (key, value) entries for which the predicate returned true; |
|
static java.lang.Object |
findIf(java.util.Collection col,
Predicate1 p)
Returns the first element of the collection such that the predicate is true. |
|
static boolean |
haveCommonElements(java.util.Collection a,
java.util.Collection b)
Checks whether two colletions have any elements in common. |
|
static java.util.List |
insertBeforeFirst(java.lang.Object target,
java.util.List list,
java.util.List add)
Returns a same-class copy of a list in which a list of additional elements has been inserted before the first occurrence of a specified target element. |
|
static java.util.Collection |
intersection(java.util.Collection a,
java.util.Collection b)
Returns a new collection of the same class as its first argument and that contains the elements that appear in both collections. |
|
static boolean |
isEmpty(java.util.Collection c)
Returns true iff the collection is either null
or empty. |
|
static boolean |
isEmpty(java.util.Map m)
Returns true iff the Map is either null
or empty. |
|
static java.util.Iterator |
iterator(java.util.Collection c)
Returns the collections's iterator, treating null
as an empty list. |
|
static
|
lastElement(java.util.List<E> list)
Returns the last element of the list, or null if the list is empty. |
|
static
|
makeFixedList(E... elements)
Returns a fixed-length list of the specified elements. |
|
static
|
makeList(E... elements)
Returns an extendable list of the specified elements. |
|
static java.util.Collection |
map(java.util.Collection result,
java.util.Collection c,
Function1 f)
Returns the result collection after adding the values returned by a function applied to each element of another collection. |
|
static java.util.Collection |
map(java.util.Collection c,
Function1 f)
Returns a new collection of the same class as the original and with corresponding elements obtained by calling the specified function. |
|
static java.util.List |
powerset(java.util.List elements)
Returns the powerset of a List in a nice order. |
|
static
|
randomth(java.util.List<E> list,
java.util.Random random)
Returns a random element of the list. |
|
static boolean |
removeAll(java.util.Map a,
java.util.Map b)
Removes all entries from a map that appear in a second map. |
|
static java.util.List |
replaceFirst(java.lang.Object from,
java.lang.Object to,
java.util.List source)
Replaces the first occurrence of an item in a list, returning the modified list. |
|
static boolean |
some(java.util.Collection c,
Predicate1 p)
Tests whether a prediate is true of at least one element of a collection. |
|
static Function1 |
toFunction(java.util.Map m)
Returns a function based on the map. |
|
static java.util.Map |
transposeMap(java.util.Map m)
Returns a map of the same class as the original but with keys and values exchanged. |
|
static java.util.Collection |
union(java.util.Collection a,
java.util.Collection b)
Returns a new collection of the same class as its first argument and that contains the elements that appear in the first collection plus all elements from the second collection that were not already in the first. |
|
static void |
walkTriangle(java.util.List list,
Proc walker)
Performs "triangle iteration" on a list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final boolean isEmpty(java.util.Collection c)
null
or empty.
public static final java.util.Iterator iterator(java.util.Collection c)
null
as an empty list.
public static java.util.List ensureList(java.util.List list)
null
.
public static <E> java.util.List<E> makeList(E... elements)
public static <E> java.util.List<E> makeFixedList(E... elements)
public static <E> E lastElement(java.util.List<E> list)
public static <E> E randomth(java.util.List<E> list, java.util.Random random)
public static boolean elementsMatch(java.util.List list, java.lang.Class... classes)
public static boolean containsEq(java.util.Collection col, java.lang.Object item)
public static java.lang.Object findIf(java.util.Collection col, Predicate1 p)
public static java.util.List replaceFirst(java.lang.Object from, java.lang.Object to, java.util.List source)
public static boolean equalAsSets(java.util.Collection a, java.util.Collection b)
public static boolean haveCommonElements(java.util.Collection a, java.util.Collection b)
For some reason, the Java collections have a containsAll method but no containsAny. This method fills that gap.
public static java.util.Collection intersection(java.util.Collection a, java.util.Collection b)
public static java.util.Collection union(java.util.Collection a, java.util.Collection b)
public static java.util.Collection difference(java.util.Collection a, java.util.Collection b)
public static java.util.List append(java.util.List a, java.util.List b)
public static java.util.List insertBeforeFirst(java.lang.Object target, java.util.List list, java.util.List add)
target
- the item to insert beforelist
- the list to insert intoadd
- the elements to insertpublic static java.util.Collection map(java.util.Collection c, Function1 f)
public static java.util.Collection map(java.util.Collection result, java.util.Collection c, Function1 f)
public static boolean some(java.util.Collection c, Predicate1 p)
public static boolean every(java.util.Collection c, Predicate1 p)
public static java.util.Collection filter(java.util.Collection c, Predicate1 p)
public static java.util.Collection filter(java.util.Collection result, java.util.Collection c, Predicate1 p)
public static java.lang.String elementsToString(java.util.Collection c, Function1 f)
toString()
representation of the elements
of the collection as transformed by the function and separated by
commas.
public static java.lang.String elementsToString(java.util.Collection c)
toString()
representation of the elements
of the collection, separated by commas.
public static void walkTriangle(java.util.List list, Proc walker)
public static java.util.List powerset(java.util.List elements)
[a, b, c]
,
the result will be:
[[], [a], [b], [c], [a, b], [a, c], [b, c], [a, b, c]]
public static final boolean isEmpty(java.util.Map m)
null
or empty.
public static java.util.Map ensureMap(java.util.Map map)
null
.
public static boolean areConsistent(java.util.Map m1, java.util.Map m2)
public static Function1 toFunction(java.util.Map m)
map(Collection, Function1)
and similar methods.
public static java.util.Map extendMap(java.util.Map m, java.util.Collection keys, java.util.Collection values)
java.lang.IllegalArgumentException
- if a key is already present
in the Map or appears more than once in the collection of keys.
AssertionFailure
- if the key and value collections are
of different lengths.public static java.util.Map transposeMap(java.util.Map m)
public static java.util.Map difference(java.util.Map a, java.util.Map b)
removeAll(Map, Map)
on a copy of the first
map.
public static boolean removeAll(java.util.Map a, java.util.Map b)
public static java.util.Map filter(java.util.Map m, Predicate2 p)
public static java.util.Map filter(java.util.Map result, java.util.Map m, Predicate2 p)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |