edu.rice.cs.plt.collect
Class CollectUtil

java.lang.Object
  extended by edu.rice.cs.plt.collect.CollectUtil

public final class CollectUtil
extends java.lang.Object


Field Summary
static Predicate2<java.util.Set<?>,java.lang.Object> SET_CONTENTS_PREDICATE
          A predicate that accepts Set-Object pairs such that the given object is contained by the set.
static Order<java.lang.String> STRING_PREFIX_ORDER
          A partial order checking whether the first element is a prefix of the second; implemented with String.contains(java.lang.CharSequence).
static Order<java.lang.Iterable<?>> SUBSET_ORDER
          A partial order checking whether the first element is a subset of the second; implemented with IterUtil.containsAll(java.lang.Iterable, java.lang.Iterable) and Collection.containsAll(java.util.Collection).
static Order<java.lang.String> SUBSTRING_ORDER
          A partial order checking whether the first element is a substring of the second; implemented with String.contains(java.lang.CharSequence).
 
Method Summary
static
<E> boolean
addAll(java.util.Collection<E> c, java.lang.Iterable<? extends E> elts)
          Add the given elements to a collection.
static
<T> Thunk<java.util.List<T>>
arrayListFactory()
          Get a factory that produces ArrayLists by invoking the empty ArrayList constructor.
static
<T> Thunk<java.util.List<T>>
arrayListFactory(int initialCapacity)
          Get a factory that produces ArrayLists with the given initial capacity.
static
<T> java.util.Collection<T>
asCollection(java.lang.Iterable<T> iter)
          Convert the given Iterable to a Collection.
static
<K,V> LambdaMap<K,V>
asLambdaMap(java.util.Map<K,V> m)
          Convert the given Map to a LambdaMap.
static
<K,V> java.util.Map<K,V>
asMap(java.util.Dictionary<K,V> d)
          Convert a Dictionary to a Map.
static
<T> PredicateSet<T>
asPredicateSet(java.lang.Iterable<T> iter)
          Convert the given Iterable to a PredicateSet.
static
<T> java.util.Set<T>
asSet(java.lang.Iterable<T> iter)
          Convert the given Iterable to a Set.
static
<T> TotalOrder<T>
asTotalOrder(java.util.Comparator<? super T> comp)
          Wrap a Comparator as a TotalOrder.
static
<T> Option<T>
castIfContains(java.util.Collection<? extends T> c, java.lang.Object obj)
          Cast the given object to a collection element type if that object is contained by the collection.
static
<T1,T2> Relation<T1,T2>
complement(Relation<T1,T2> domain, Relation<? super T1,? super T2> excluded)
          Produce the complement of a relation in a domain, or, equivalently, the difference of two relations.
static
<T1,T2> Relation<T1,T2>
complement(Relation<T1,T2> domain, T1 first, T2 second)
          Produce the complement of a singleton in a domain relation, or, equivalently, a relation with a certain entry removed.
static
<T> PredicateSet<T>
complement(java.util.Set<? extends T> domain, java.util.Set<?> excluded)
          Produce the complement of a set in a domain, or, equivalently, the difference of two sets.
static
<T> PredicateSet<T>
complement(java.util.Set<? extends T> domain, T excluded)
          Produce the complement of a singleton in a domain set, or, equivalently, a set with a certain element removed.
static
<K,X,V> LambdaMap<K,V>
compose(java.util.Map<? extends K,? extends X> left, java.util.Map<? super X,? extends V> right)
          Produce a lazy transitive composition of two maps.
static
<T1,T2,T3> Relation<T1,T3>
compose(Relation<T1,T2> left, Relation<T2,T3> right)
          Produce a lazy transitive composition of two relations.
static
<T> java.util.List<T>
composeMaxLists(java.lang.Iterable<? extends T> vals1, java.lang.Iterable<? extends T> vals2, Order<? super T> order)
          Get the maximal elements of the given lists, each known to be a list of maximal elements, based on the given order.
static
<T> java.util.List<T>
composeMinLists(java.lang.Iterable<? extends T> vals1, java.lang.Iterable<? extends T> vals2, Order<? super T> order)
          Get the minimal elements of the given lists, each known to be a list of minimal elements, based on the given order.
static
<K,V> java.util.Map<K,V>
conditionalSnapshot(java.util.Map<K,V> map, int threshold)
          Produce a snapshot of set if its composite size is greater than the given threshold.
static
<T1,T2> Relation<T1,T2>
conditionalSnapshot(Relation<T1,T2> rel, int threshold)
          Produce a snapshot of set if its composite size is greater than the given threshold.
static
<T> java.lang.Iterable<T>
conditionalSnapshot(java.util.Set<T> set, int threshold)
          Produce a snapshot of set if its composite size is greater than the given threshold.
static boolean containsAll(java.util.Collection<?> c, java.lang.Iterable<?> subset)
          Test whether a collection contains all the elements of a list.
static boolean containsAny(java.util.Collection<?> c, java.lang.Iterable<?> candidates)
          Test whether a collection contains some element of a list.
static
<T> Thunk<java.util.List<T>>
copyOnWriteArrayListFactory()
          Get a factory that produces CopyOnWriteArraySets by invoking the empty CopyOnWriteArraySet constructor.
static
<T> Thunk<java.util.Set<T>>
copyOnWriteArraySetFactory()
          Get a factory that produces CopyOnWriteArraySets by invoking the empty CopyOnWriteArraySet constructor.
static
<T1,T2> Relation<T1,T2>
cross(java.util.Set<? extends T1> left, java.util.Set<? extends T2> right)
          Produce the lazy cartesian (or cross) product of two sets.
static
<T> java.util.List<T>
emptyList()
          Produce an immutable empty list.
static
<K,V> EmptyMap<K,V>
emptyMap()
          Produce an immutable empty map.
static
<T1,T2> EmptyRelation<T1,T2>
emptyRelation()
          Produce an immutable empty relation.
static
<T> EmptySet<T>
emptySet()
          Produce an immutable empty set.
static
<T1,T2> Relation<T1,T2>
filter(Relation<T1,T2> relation, Predicate2<? super T1,? super T2> pred)
          Lazily filter the given relation.
static
<T> PredicateSet<T>
filter(java.util.Set<? extends T> set, Predicate<? super T> predicate)
          Lazily filter the given set.
static
<T> java.util.Set<T>
functionClosure(java.util.Set<? extends T> base, Lambda<? super T,? extends T> function)
          Produce the set containing the elements in base and all values produced an arbitrary number of applications of function to one of these elements.
static
<T> java.util.Set<T>
functionClosure(T base, Lambda<? super T,? extends T> function)
          Produce the set containing base and all values produced an arbitrary number of applications of function to base.
static
<T> java.util.Set<T>
graphClosure(java.util.Set<? extends T> base, Lambda<? super T,? extends java.lang.Iterable<? extends T>> neighbors)
          Produce the set of all nodes reachable from the elements in base in a directed graph defined by neighbors.
static
<T> java.util.Set<T>
graphClosure(T base, Lambda<? super T,? extends java.lang.Iterable<? extends T>> neighbors)
          Produce the set of all nodes reachable from base in a directed graph defined by neighbors.
static
<K,V> Thunk<java.util.Map<K,V>>
hashMapFactory()
          Get a factory that produces HashMaps by invoking the empty HashMap constructor.
static
<K,V> Thunk<java.util.Map<K,V>>
hashMapFactory(int initialCapacity)
          Get a factory that produces HashMaps with the given initial capacity.
static
<T> Thunk<java.util.Set<T>>
hashSetFactory()
          Get a factory that produces HashSets by invoking the empty HashSet constructor.
static
<T> Thunk<java.util.Set<T>>
hashSetFactory(int initialCapacity)
          Get a factory that produces HashSets with the given initial capacity.
static
<K,V> java.util.Map<K,V>
immutable(java.util.Map<? extends K,? extends V> map)
          Wrap a map in an immutable wrapper.
static
<T1,T2> ImmutableRelation<T1,T2>
immutable(Relation<T1,T2> r)
          Wrap a relation in an immutable wrapper.
static
<T> PredicateSet<T>
immutable(java.util.Set<? extends T> set)
          Wrap a set in an immutable wrapper.
static
<T1,T2> Relation<T1,T2>
intersection(Relation<T1,T2> r1, Relation<T1,T2> r2)
          Produce a lazy intersection of two relations.
static
<T> PredicateSet<T>
intersection(java.util.Set<?> s1, java.util.Set<? extends T> s2)
          Produce a lazy intersection of two sets.
static
<T> TotalOrder<T>
inverse(java.util.Comparator<? super T> ord)
          Create an inverse of the given comparator (or TotalOrder).
static
<T> Order<T>
inverse(Order<? super T> ord)
          Create an inverse of the given order.
static
<K,V> Thunk<java.util.Map<K,V>>
linkedHashMapFactory()
          Get a factory that produces LinkedHashMaps by invoking the empty LinkedHashMap constructor.
static
<K,V> Thunk<java.util.Map<K,V>>
linkedHashMapFactory(int initialCapacity)
          Get a factory that produces LinkedHashMaps with the given initial capacity.
static
<T> Thunk<java.util.Set<T>>
linkedHashSetFactory()
          Get a factory that produces LinkedHashSets by invoking the empty LinkedHashSet constructor.
static
<T> Thunk<java.util.Set<T>>
linkedHashSetFactory(int initialCapacity)
          Get a factory that produces LinkedHashSets with the given initial capacity.
static
<T> Thunk<java.util.List<T>>
linkedListFactory()
          Get a factory that produces LinkedLists by invoking the empty LinkedList constructor.
static
<T> java.util.ArrayList<T>
makeArrayList(java.lang.Iterable<? extends T> iter)
          Make an ArrayList with the given elements.
static
<T> ConsList<T>
makeConsList(java.lang.Iterable<? extends T> iter)
          Make a ConsList with the given elements.
static
<T> java.util.LinkedList<T>
makeLinkedList(java.lang.Iterable<? extends T> iter)
          Make a LinkedList with the given elements.
static
<T> java.util.List<T>
makeList(java.lang.Iterable<? extends T> iter)
          Make an ArrayList with the given elements.
static
<T1,T2> Relation<T1,T2>
makeRelation(java.lang.Iterable<? extends Pair<? extends T1,? extends T2>> pairs)
          Create an immutable Relation based on the given elements.
static
<T> PredicateSet<T>
makeSet(java.lang.Iterable<? extends T> elements)
          Create an immutable PredicateSet based on the given elements.
static
<T> PredicateSet<T>
makeSet(Option<? extends T> opt)
          Produce an empty or singleton set based on the given Option.
static
<T> PredicateSet<T>
makeSet(T... elements)
          Create an immutable PredicateSet based on the given elements.
static
<T> java.util.List<T>
maxList(java.lang.Iterable<? extends T> vals, Order<? super T> order)
          Get the maximal elements of the given list, based on the given order.
static
<T> java.util.List<T>
minList(java.lang.Iterable<? extends T> vals, Order<? super T> order)
          Get the minimal elements of the given list, based on the given order.
static
<T extends java.lang.Comparable<? super T>>
TotalOrder<T>
naturalOrder()
          Get a TotalOrder based on the natural (compareTo-based) order associated with the given type.
static
<T> java.util.Set<T>
partialFunctionClosure(java.util.Set<? extends T> base, Lambda<? super T,? extends Option<? extends T>> function)
          Produce the set containing the elements in base and all values produced an arbitrary number of applications of function to one of these elements.
static
<T> java.util.Set<T>
partialFunctionClosure(T base, Lambda<? super T,? extends Option<? extends T>> function)
          Produce the set containing base and all values produced an arbitrary number of applications of function to base.
static boolean removeAll(java.util.Collection<?> c, java.lang.Iterable<?> elts)
          Remove the given elements from a collection.
static boolean retainAll(java.util.Collection<?> c, java.lang.Iterable<?> elts)
          Remove all but the given elements from a collection.
static
<T> SingletonSet<T>
singleton(T elt)
          Create an immutable singleton set.
static
<T1,T2> SingletonRelation<T1,T2>
singleton(T1 first, T2 second)
          Create an immutable singleton relation.
static
<K,V> SingletonMap<K,V>
singletonMap(K key, V value)
          Create an immutable singleton map.
static
<T> java.util.List<T>
snapshot(java.util.List<? extends T> list)
          Alias for makeArrayList(java.lang.Iterable).
static
<K,V> LambdaMap<K,V>
snapshot(java.util.Map<? extends K,? extends V> map)
          Invoke the HashMap#HashMap(Map) constructor, and wrap the result as a LambdaMap.
static
<T1,T2> Relation<T1,T2>
snapshot(Relation<? extends T1,? extends T2> relation)
          Alias for makeRelation(java.lang.Iterable>).
static
<T> PredicateSet<T>
snapshot(java.util.Set<? extends T> set)
          Alias for makeSet(T...).
static
<T> SnapshotSynchronizedList<T>
snapshotSynchronized(java.util.List<T> l)
          Wrap l as a thread-safe list that produces snapshots to support concurrent iteration.
static
<T> SnapshotSynchronizedSet<T>
snapshotSynchronized(java.util.Set<T> s)
          Wrap s as a thread-safe set that produces snapshots to support concurrent iteration.
static
<K extends java.lang.Comparable<? super K>,V>
Thunk<java.util.Map<K,V>>
treeMapFactory()
          Get a factory that produces TreeMaps sorted according to the elements' natural order.
static
<K,V> Thunk<java.util.Map<K,V>>
treeMapFactory(java.util.Comparator<? super K> comparator)
          Get a factory that produces TreeMaps sorted according to the given comparator.
static
<T extends java.lang.Comparable<? super T>>
Thunk<java.util.Set<T>>
treeSetFactory()
          Get a factory that produces TreeSets sorted according to the elements' natural order.
static
<T> Thunk<java.util.Set<T>>
treeSetFactory(java.util.Comparator<? super T> comparator)
          Get a factory that produces TreeSets sorted according to the given comparator.
static
<K,V> LambdaMap<K,V>
union(java.util.Map<? extends K,? extends V> parent, java.util.Map<? extends K,? extends V> child)
          Produce a lazy union of two maps, with mappings in child shadowing those in parent.
static
<T1,T2> Relation<T1,T2>
union(Relation<T1,T2> r1, Relation<T1,T2> r2)
          Produce a lazy union of two relations.
static
<T1,T2> Relation<T1,T2>
union(Relation<T1,T2> rel, T1 first, T2 second)
          Produce a lazy union of a relation with an additional singleton entry.
static
<T> PredicateSet<T>
union(java.util.Set<? extends T> s1, java.util.Set<? extends T> s2)
          Produce a lazy union of two sets.
static
<T> PredicateSet<T>
union(java.util.Set<? extends T> set, T elt)
          Produce a lazy union of a set with an additional singleton element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SET_CONTENTS_PREDICATE

public static final Predicate2<java.util.Set<?>,java.lang.Object> SET_CONTENTS_PREDICATE
A predicate that accepts Set-Object pairs such that the given object is contained by the set.


SUBSET_ORDER

public static final Order<java.lang.Iterable<?>> SUBSET_ORDER
A partial order checking whether the first element is a subset of the second; implemented with IterUtil.containsAll(java.lang.Iterable, java.lang.Iterable) and Collection.containsAll(java.util.Collection).


SUBSTRING_ORDER

public static final Order<java.lang.String> SUBSTRING_ORDER
A partial order checking whether the first element is a substring of the second; implemented with String.contains(java.lang.CharSequence).


STRING_PREFIX_ORDER

public static final Order<java.lang.String> STRING_PREFIX_ORDER
A partial order checking whether the first element is a prefix of the second; implemented with String.contains(java.lang.CharSequence).

Method Detail

hashSetFactory

public static <T> Thunk<java.util.Set<T>> hashSetFactory()
Get a factory that produces HashSets by invoking the empty HashSet constructor.

See Also:
HashSet.HashSet()

hashSetFactory

public static <T> Thunk<java.util.Set<T>> hashSetFactory(int initialCapacity)
Get a factory that produces HashSets with the given initial capacity.

See Also:
HashSet.HashSet(int)

linkedHashSetFactory

public static <T> Thunk<java.util.Set<T>> linkedHashSetFactory()
Get a factory that produces LinkedHashSets by invoking the empty LinkedHashSet constructor.

See Also:
LinkedHashSet.LinkedHashSet()

linkedHashSetFactory

public static <T> Thunk<java.util.Set<T>> linkedHashSetFactory(int initialCapacity)
Get a factory that produces LinkedHashSets with the given initial capacity.

See Also:
LinkedHashSet.LinkedHashSet(int)

treeSetFactory

public static <T extends java.lang.Comparable<? super T>> Thunk<java.util.Set<T>> treeSetFactory()
Get a factory that produces TreeSets sorted according to the elements' natural order.

See Also:
TreeSet.TreeSet()

treeSetFactory

public static <T> Thunk<java.util.Set<T>> treeSetFactory(java.util.Comparator<? super T> comparator)
Get a factory that produces TreeSets sorted according to the given comparator.

See Also:
TreeSet.TreeSet(Comparator)

copyOnWriteArraySetFactory

public static <T> Thunk<java.util.Set<T>> copyOnWriteArraySetFactory()
Get a factory that produces CopyOnWriteArraySets by invoking the empty CopyOnWriteArraySet constructor.

See Also:
CopyOnWriteArraySet.CopyOnWriteArraySet()

hashMapFactory

public static <K,V> Thunk<java.util.Map<K,V>> hashMapFactory()
Get a factory that produces HashMaps by invoking the empty HashMap constructor.

See Also:
HashMap.HashMap()

hashMapFactory

public static <K,V> Thunk<java.util.Map<K,V>> hashMapFactory(int initialCapacity)
Get a factory that produces HashMaps with the given initial capacity.

See Also:
HashMap.HashMap(int)

linkedHashMapFactory

public static <K,V> Thunk<java.util.Map<K,V>> linkedHashMapFactory()
Get a factory that produces LinkedHashMaps by invoking the empty LinkedHashMap constructor.

See Also:
LinkedHashMap.LinkedHashMap()

linkedHashMapFactory

public static <K,V> Thunk<java.util.Map<K,V>> linkedHashMapFactory(int initialCapacity)
Get a factory that produces LinkedHashMaps with the given initial capacity.

See Also:
LinkedHashMap.LinkedHashMap(int)

treeMapFactory

public static <K extends java.lang.Comparable<? super K>,V> Thunk<java.util.Map<K,V>> treeMapFactory()
Get a factory that produces TreeMaps sorted according to the elements' natural order.

See Also:
TreeMap.TreeMap()

treeMapFactory

public static <K,V> Thunk<java.util.Map<K,V>> treeMapFactory(java.util.Comparator<? super K> comparator)
Get a factory that produces TreeMaps sorted according to the given comparator.

See Also:
TreeMap.TreeMap(Comparator)

arrayListFactory

public static <T> Thunk<java.util.List<T>> arrayListFactory()
Get a factory that produces ArrayLists by invoking the empty ArrayList constructor.

See Also:
ArrayList.ArrayList()

arrayListFactory

public static <T> Thunk<java.util.List<T>> arrayListFactory(int initialCapacity)
Get a factory that produces ArrayLists with the given initial capacity.

See Also:
ArrayList.ArrayList(int)

linkedListFactory

public static <T> Thunk<java.util.List<T>> linkedListFactory()
Get a factory that produces LinkedLists by invoking the empty LinkedList constructor.

See Also:
LinkedList.LinkedList()

copyOnWriteArrayListFactory

public static <T> Thunk<java.util.List<T>> copyOnWriteArrayListFactory()
Get a factory that produces CopyOnWriteArraySets by invoking the empty CopyOnWriteArraySet constructor.

See Also:
CopyOnWriteArraySet.CopyOnWriteArraySet()

makeSet

public static <T> PredicateSet<T> makeSet(T... elements)
Create an immutable PredicateSet based on the given elements. May depend on a valid hashCode() implementation.


makeSet

public static <T> PredicateSet<T> makeSet(java.lang.Iterable<? extends T> elements)
Create an immutable PredicateSet based on the given elements. May depend on a valid hashCode() implementation.


makeSet

public static <T> PredicateSet<T> makeSet(Option<? extends T> opt)
Produce an empty or singleton set based on the given Option.


makeRelation

public static <T1,T2> Relation<T1,T2> makeRelation(java.lang.Iterable<? extends Pair<? extends T1,? extends T2>> pairs)
Create an immutable Relation based on the given elements. May depend on a valid hashCode() implementation.


makeList

public static <T> java.util.List<T> makeList(java.lang.Iterable<? extends T> iter)
Make an ArrayList with the given elements.


makeArrayList

public static <T> java.util.ArrayList<T> makeArrayList(java.lang.Iterable<? extends T> iter)
Make an ArrayList with the given elements.


makeLinkedList

public static <T> java.util.LinkedList<T> makeLinkedList(java.lang.Iterable<? extends T> iter)
Make a LinkedList with the given elements.


makeConsList

public static <T> ConsList<T> makeConsList(java.lang.Iterable<? extends T> iter)
Make a ConsList with the given elements.


emptyList

public static <T> java.util.List<T> emptyList()
Produce an immutable empty list. Equivalent to Collections.emptyList(); defined here for Java 1.4 compatibility.


emptySet

public static <T> EmptySet<T> emptySet()
Produce an immutable empty set. Similar to Collections.emptySet(), but the result here is a PredicateSet. Also defined for Java 1.4 compatibility.


emptyMap

public static <K,V> EmptyMap<K,V> emptyMap()
Produce an immutable empty map. Similar to Collections.emptyMap(), but the result here is a LambdaMap. Also defined for Java 1.4 compatibility.


emptyRelation

public static <T1,T2> EmptyRelation<T1,T2> emptyRelation()
Produce an immutable empty relation.


singleton

public static <T> SingletonSet<T> singleton(T elt)
Create an immutable singleton set. Similar to Collections.singleton(T), but produces a PredicateSet.


singleton

public static <T1,T2> SingletonRelation<T1,T2> singleton(T1 first,
                                                         T2 second)
Create an immutable singleton relation.


singletonMap

public static <K,V> SingletonMap<K,V> singletonMap(K key,
                                                   V value)
Create an immutable singleton map. Similar to Collections.singletonMap(K, V), but produces a LambdaMap.


asSet

public static <T> java.util.Set<T> asSet(java.lang.Iterable<T> iter)
Convert the given Iterable to a Set. If it already is a Set, cast it as such. Otherwise, create an IterableSet.


asPredicateSet

public static <T> PredicateSet<T> asPredicateSet(java.lang.Iterable<T> iter)
Convert the given Iterable to a PredicateSet. If it already is a PredicateSet, cast it as such. If it is a Set, produce a DelegatingSet. Otherwise, create an IterableSet.


asCollection

public static <T> java.util.Collection<T> asCollection(java.lang.Iterable<T> iter)
Convert the given Iterable to a Collection. If it already is a Collection, cast it as such. Otherwise, create an IterableCollection.


asLambdaMap

public static <K,V> LambdaMap<K,V> asLambdaMap(java.util.Map<K,V> m)
Convert the given Map to a LambdaMap. If it already is a LambdaMap, cast it as such. Otherwise, create a DelegatingMap.


asMap

public static <K,V> java.util.Map<K,V> asMap(java.util.Dictionary<K,V> d)
Convert a Dictionary to a Map. If it is a Hashtable, cast it as a Map. Otherwise, create a DictionaryMap.


immutable

public static <T> PredicateSet<T> immutable(java.util.Set<? extends T> set)
Wrap a set in an immutable wrapper. Similar to Collections.unmodifiableSet(java.util.Set), but produces a PredicateSet.


immutable

public static <K,V> java.util.Map<K,V> immutable(java.util.Map<? extends K,? extends V> map)
Wrap a map in an immutable wrapper. Similar to Collections.unmodifiableMap(java.util.Map), but produces a LambdaMap.


immutable

public static <T1,T2> ImmutableRelation<T1,T2> immutable(Relation<T1,T2> r)
Wrap a relation in an immutable wrapper. Analogous to Collections.unmodifiableSet(java.util.Set).


snapshot

public static <T> PredicateSet<T> snapshot(java.util.Set<? extends T> set)
Alias for makeSet(T...).


conditionalSnapshot

public static <T> java.lang.Iterable<T> conditionalSnapshot(java.util.Set<T> set,
                                                            int threshold)
Produce a snapshot of set if its composite size is greater than the given threshold.

See Also:
ObjectUtil.compositeSize(java.lang.Object)

snapshot

public static <T1,T2> Relation<T1,T2> snapshot(Relation<? extends T1,? extends T2> relation)
Alias for makeRelation(java.lang.Iterable>).


conditionalSnapshot

public static <T1,T2> Relation<T1,T2> conditionalSnapshot(Relation<T1,T2> rel,
                                                          int threshold)
Produce a snapshot of set if its composite size is greater than the given threshold.

See Also:
ObjectUtil.compositeSize(java.lang.Object)

snapshot

public static <K,V> LambdaMap<K,V> snapshot(java.util.Map<? extends K,? extends V> map)
Invoke the HashMap#HashMap(Map) constructor, and wrap the result as a LambdaMap.


conditionalSnapshot

public static <K,V> java.util.Map<K,V> conditionalSnapshot(java.util.Map<K,V> map,
                                                           int threshold)
Produce a snapshot of set if its composite size is greater than the given threshold.

See Also:
ObjectUtil.compositeSize(java.lang.Object)

snapshot

public static <T> java.util.List<T> snapshot(java.util.List<? extends T> list)
Alias for makeArrayList(java.lang.Iterable).


snapshotSynchronized

public static <T> SnapshotSynchronizedSet<T> snapshotSynchronized(java.util.Set<T> s)
Wrap s as a thread-safe set that produces snapshots to support concurrent iteration.

See Also:
SnapshotSynchronizedSet

snapshotSynchronized

public static <T> SnapshotSynchronizedList<T> snapshotSynchronized(java.util.List<T> l)
Wrap l as a thread-safe list that produces snapshots to support concurrent iteration.

See Also:
SnapshotSynchronizedList

union

public static <T> PredicateSet<T> union(java.util.Set<? extends T> s1,
                                        java.util.Set<? extends T> s2)
Produce a lazy union of two sets. Size-related operations have poor performance.


union

public static <T> PredicateSet<T> union(java.util.Set<? extends T> set,
                                        T elt)
Produce a lazy union of a set with an additional singleton element.


intersection

public static <T> PredicateSet<T> intersection(java.util.Set<?> s1,
                                               java.util.Set<? extends T> s2)
Produce a lazy intersection of two sets. Size-related operations have poor performance.


complement

public static <T> PredicateSet<T> complement(java.util.Set<? extends T> domain,
                                             java.util.Set<?> excluded)
Produce the complement of a set in a domain, or, equivalently, the difference of two sets. Size-related operations have poor performance.


complement

public static <T> PredicateSet<T> complement(java.util.Set<? extends T> domain,
                                             T excluded)
Produce the complement of a singleton in a domain set, or, equivalently, a set with a certain element removed.


filter

public static <T> PredicateSet<T> filter(java.util.Set<? extends T> set,
                                         Predicate<? super T> predicate)
Lazily filter the given set. Size-related operations have poor performance.


cross

public static <T1,T2> Relation<T1,T2> cross(java.util.Set<? extends T1> left,
                                            java.util.Set<? extends T2> right)
Produce the lazy cartesian (or cross) product of two sets.


union

public static <T1,T2> Relation<T1,T2> union(Relation<T1,T2> r1,
                                            Relation<T1,T2> r2)
Produce a lazy union of two relations. Size-related operations have poor performance.


union

public static <T1,T2> Relation<T1,T2> union(Relation<T1,T2> rel,
                                            T1 first,
                                            T2 second)
Produce a lazy union of a relation with an additional singleton entry.


intersection

public static <T1,T2> Relation<T1,T2> intersection(Relation<T1,T2> r1,
                                                   Relation<T1,T2> r2)
Produce a lazy intersection of two relations. Size-related operations have poor performance.


complement

public static <T1,T2> Relation<T1,T2> complement(Relation<T1,T2> domain,
                                                 Relation<? super T1,? super T2> excluded)
Produce the complement of a relation in a domain, or, equivalently, the difference of two relations. Size-related operations have poor performance.


complement

public static <T1,T2> Relation<T1,T2> complement(Relation<T1,T2> domain,
                                                 T1 first,
                                                 T2 second)
Produce the complement of a singleton in a domain relation, or, equivalently, a relation with a certain entry removed.


compose

public static <T1,T2,T3> Relation<T1,T3> compose(Relation<T1,T2> left,
                                                 Relation<T2,T3> right)
Produce a lazy transitive composition of two relations. Size-related operations have poor performance.


filter

public static <T1,T2> Relation<T1,T2> filter(Relation<T1,T2> relation,
                                             Predicate2<? super T1,? super T2> pred)
Lazily filter the given relation. Size-related operations have poor performance.


union

public static <K,V> LambdaMap<K,V> union(java.util.Map<? extends K,? extends V> parent,
                                         java.util.Map<? extends K,? extends V> child)
Produce a lazy union of two maps, with mappings in child shadowing those in parent. Size-related operations have poor performance.


compose

public static <K,X,V> LambdaMap<K,V> compose(java.util.Map<? extends K,? extends X> left,
                                             java.util.Map<? super X,? extends V> right)
Produce a lazy transitive composition of two maps. Size-related operations have poor performance.


castIfContains

public static <T> Option<T> castIfContains(java.util.Collection<? extends T> c,
                                           java.lang.Object obj)
Cast the given object to a collection element type if that object is contained by the collection. Assumes the collection is faithful to its specification: an object is contained by the collection if and only if it appears as an element of the Iterator<T> produced by its iterator() method (the implication being that the object must have type T).


containsAny

public static boolean containsAny(java.util.Collection<?> c,
                                  java.lang.Iterable<?> candidates)
Test whether a collection contains some element of a list.

See Also:
Collection.containsAll(java.util.Collection), IterUtil.or(java.lang.Iterable, edu.rice.cs.plt.lambda.Predicate)

containsAll

public static boolean containsAll(java.util.Collection<?> c,
                                  java.lang.Iterable<?> subset)
Test whether a collection contains all the elements of a list. Unlike Collection.containsAll(java.util.Collection), defined for arbitrary Iterables. When possible, delegates to c.containsAll().

See Also:
IterUtil.and(java.lang.Iterable, edu.rice.cs.plt.lambda.Predicate), IterUtil.containsAll(java.lang.Iterable, java.lang.Iterable)

addAll

public static <E> boolean addAll(java.util.Collection<E> c,
                                 java.lang.Iterable<? extends E> elts)
Add the given elements to a collection. Unlike Collection.addAll(java.util.Collection), defined for arbitrary Iterables. When possible, delegates to c.addAll().

Returns:
true if c changed as a result of the call

removeAll

public static boolean removeAll(java.util.Collection<?> c,
                                java.lang.Iterable<?> elts)
Remove the given elements from a collection. Unlike Collection.removeAll(java.util.Collection), defined for arbitrary Iterables. When possible, delegates to c.removeAll().

Returns:
true if c changed as a result of the call

retainAll

public static boolean retainAll(java.util.Collection<?> c,
                                java.lang.Iterable<?> elts)
Remove all but the given elements from a collection. Unlike Collection.retainAll(java.util.Collection), defined for arbitrary Iterables. When possible, delegates to c.retainAll().

Returns:
true if c changed as a result of the call

functionClosure

public static <T> java.util.Set<T> functionClosure(T base,
                                                   Lambda<? super T,? extends T> function)
Produce the set containing base and all values produced an arbitrary number of applications of function to base.


functionClosure

public static <T> java.util.Set<T> functionClosure(java.util.Set<? extends T> base,
                                                   Lambda<? super T,? extends T> function)
Produce the set containing the elements in base and all values produced an arbitrary number of applications of function to one of these elements.


partialFunctionClosure

public static <T> java.util.Set<T> partialFunctionClosure(T base,
                                                          Lambda<? super T,? extends Option<? extends T>> function)
Produce the set containing base and all values produced an arbitrary number of applications of function to base.


partialFunctionClosure

public static <T> java.util.Set<T> partialFunctionClosure(java.util.Set<? extends T> base,
                                                          Lambda<? super T,? extends Option<? extends T>> function)
Produce the set containing the elements in base and all values produced an arbitrary number of applications of function to one of these elements.


graphClosure

public static <T> java.util.Set<T> graphClosure(T base,
                                                Lambda<? super T,? extends java.lang.Iterable<? extends T>> neighbors)
Produce the set of all nodes reachable from base in a directed graph defined by neighbors.


graphClosure

public static <T> java.util.Set<T> graphClosure(java.util.Set<? extends T> base,
                                                Lambda<? super T,? extends java.lang.Iterable<? extends T>> neighbors)
Produce the set of all nodes reachable from the elements in base in a directed graph defined by neighbors.


maxList

public static <T> java.util.List<T> maxList(java.lang.Iterable<? extends T> vals,
                                            Order<? super T> order)
Get the maximal elements of the given list, based on the given order. All elements in vals either appear in the result or precede some element in the result. Where two elements are equivalent (each precedes the other), the second will always be discarded.


composeMaxLists

public static <T> java.util.List<T> composeMaxLists(java.lang.Iterable<? extends T> vals1,
                                                    java.lang.Iterable<? extends T> vals2,
                                                    Order<? super T> order)
Get the maximal elements of the given lists, each known to be a list of maximal elements, based on the given order. The result is the same as maxList(IterUtil.compose(vals1, vals2), order), but the implementation is more efficient, because it can avoid performing redundant comparisons.


minList

public static <T> java.util.List<T> minList(java.lang.Iterable<? extends T> vals,
                                            Order<? super T> order)
Get the minimal elements of the given list, based on the given order. All elements in vals either appear in the result or are preceded by some element in the result. Where two elements are equivalent (each precedes the other), the second will always be discarded.


composeMinLists

public static <T> java.util.List<T> composeMinLists(java.lang.Iterable<? extends T> vals1,
                                                    java.lang.Iterable<? extends T> vals2,
                                                    Order<? super T> order)
Get the minimal elements of the given lists, each known to be a list of minimal elements, based on the given order. The result is the same as minList(IterUtil.compose(vals1, vals2), order), but the implementation is more efficient, because it can avoid performing redundant comparisons.


naturalOrder

public static <T extends java.lang.Comparable<? super T>> TotalOrder<T> naturalOrder()
Get a TotalOrder based on the natural (compareTo-based) order associated with the given type.


asTotalOrder

public static <T> TotalOrder<T> asTotalOrder(java.util.Comparator<? super T> comp)
Wrap a Comparator as a TotalOrder.


inverse

public static <T> Order<T> inverse(Order<? super T> ord)
Create an inverse of the given order.


inverse

public static <T> TotalOrder<T> inverse(java.util.Comparator<? super T> ord)
Create an inverse of the given comparator (or TotalOrder).