edu.rice.cs.plt.collect
Class ImmutableRelation<T1,T2>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by edu.rice.cs.plt.collect.DelegatingCollection<T>
          extended by edu.rice.cs.plt.collect.DelegatingSet<Pair<T1,T2>>
              extended by edu.rice.cs.plt.collect.DelegatingRelation<T1,T2>
                  extended by edu.rice.cs.plt.collect.ImmutableRelation<T1,T2>
All Implemented Interfaces:
PredicateSet<Pair<T1,T2>>, Relation<T1,T2>, SizedIterable<Pair<T1,T2>>, Predicate<Object>, Predicate2<T1,T2>, Composite, Serializable, Iterable<Pair<T1,T2>>, Collection<Pair<T1,T2>>, Set<Pair<T1,T2>>

public class ImmutableRelation<T1,T2>
extends DelegatingRelation<T1,T2>

Wraps a relation in an immutable interface. Analogous to Collections.unmodifiableMap(java.util.Map). Note that only only this interface with the data is immutable -- if the original data structure is mutable, a client with direct access to that structure can still mutate it. Subclasses can invoke the overridden methods in AbstractCollection to use the default implementations there by invoking, for example, DelegatingCollection.abstractCollectionAddAll(java.util.Collection) (see AbstractCollection for details on the default implementations).

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.rice.cs.plt.collect.DelegatingRelation
_delegate
 
Constructor Summary
ImmutableRelation(Relation<T1,T2> relation)
           
 
Method Summary
 boolean add(Pair<T1,T2> o)
          Add Pair.make(p.first(), p.second()) to the set.
 boolean add(T1 first, T2 second)
          Add Pair.make(first, second) to the set.
 boolean addAll(Collection<? extends Pair<T1,T2>> c)
           
 void clear()
           
 boolean contains(T1 first, T2 second)
          Whether Pair.make(first, second) appears in the set.
 boolean containsFirst(T1 first)
          Whether a pair with the given first value appears in the set.
 boolean containsSecond(T2 second)
          Whether a pair with the given second value appears in the set.
 PredicateSet<T2> excludeFirsts()
          The set of seconds for which there exists a (first, second) pair in the relation.
 PredicateSet<T1> excludeSeconds()
          The set of firsts for which there exists a (first, second) pair in the relation.
 PredicateSet<T1> firstSet()
          The set of firsts.
 Relation<T2,T1> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
static
<T1,T2> ImmutableRelation<T1,T2>
make(Relation<T1,T2> relation)
          Call the constructor (allows T1 and T2 to be inferred).
 PredicateSet<T2> matchFirst(T1 first)
          The set of seconds corresponding to a specific first.
 PredicateSet<T1> matchSecond(T2 second)
          The set of firsts corresponding to a specific second.
 boolean remove(Object o)
          If o is a pair, remove Pair.make(o.first(), o.second()) from the set.
 boolean remove(T1 first, T2 second)
          Remove Pair.make(first, second) from the set.
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 PredicateSet<T2> secondSet()
          The set of seconds.
 
Methods inherited from class edu.rice.cs.plt.collect.DelegatingRelation
hasFixedSize, isInfinite, isStatic, size
 
Methods inherited from class edu.rice.cs.plt.collect.DelegatingSet
equals, hashCode
 
Methods inherited from class edu.rice.cs.plt.collect.DelegatingCollection
abstractCollectionAddAll, abstractCollectionClear, abstractCollectionContains, abstractCollectionContainsAll, abstractCollectionIsEmpty, abstractCollectionRemove, abstractCollectionRemoveAll, abstractCollectionRetainAll, abstractCollectionToArray, abstractCollectionToArray, compositeHeight, compositeSize, contains, containsAll, isEmpty, iterator, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.plt.collect.Relation
contains
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, isEmpty, iterator, size, toArray, toArray
 
Methods inherited from interface edu.rice.cs.plt.iter.SizedIterable
isEmpty, size
 

Constructor Detail

ImmutableRelation

public ImmutableRelation(Relation<T1,T2> relation)
Method Detail

add

public boolean add(Pair<T1,T2> o)
Description copied from interface: Relation
Add Pair.make(p.first(), p.second()) to the set. (That is, the pair that is added is not an instance of some subclass of Pair.)

Specified by:
add in interface Relation<T1,T2>
Specified by:
add in interface Collection<Pair<T1,T2>>
Specified by:
add in interface Set<Pair<T1,T2>>
Overrides:
add in class DelegatingCollection<Pair<T1,T2>>

remove

public boolean remove(Object o)
Description copied from interface: Relation
If o is a pair, remove Pair.make(o.first(), o.second()) from the set. (That is, equality is always defined according to the Pair class's equals method, not that of some subclass.)

Specified by:
remove in interface Relation<T1,T2>
Specified by:
remove in interface Collection<Pair<T1,T2>>
Specified by:
remove in interface Set<Pair<T1,T2>>
Overrides:
remove in class DelegatingCollection<Pair<T1,T2>>

addAll

public boolean addAll(Collection<? extends Pair<T1,T2>> c)
Specified by:
addAll in interface Collection<Pair<T1,T2>>
Specified by:
addAll in interface Set<Pair<T1,T2>>
Overrides:
addAll in class DelegatingCollection<Pair<T1,T2>>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<Pair<T1,T2>>
Specified by:
retainAll in interface Set<Pair<T1,T2>>
Overrides:
retainAll in class DelegatingCollection<Pair<T1,T2>>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<Pair<T1,T2>>
Specified by:
removeAll in interface Set<Pair<T1,T2>>
Overrides:
removeAll in class DelegatingCollection<Pair<T1,T2>>

clear

public void clear()
Specified by:
clear in interface Collection<Pair<T1,T2>>
Specified by:
clear in interface Set<Pair<T1,T2>>
Overrides:
clear in class DelegatingCollection<Pair<T1,T2>>

contains

public boolean contains(T1 first,
                        T2 second)
Description copied from interface: Relation
Whether Pair.make(first, second) appears in the set.

Specified by:
contains in interface Relation<T1,T2>
Specified by:
contains in interface Predicate2<T1,T2>
Overrides:
contains in class DelegatingRelation<T1,T2>

add

public boolean add(T1 first,
                   T2 second)
Description copied from interface: Relation
Add Pair.make(first, second) to the set.

Specified by:
add in interface Relation<T1,T2>
Overrides:
add in class DelegatingRelation<T1,T2>

remove

public boolean remove(T1 first,
                      T2 second)
Description copied from interface: Relation
Remove Pair.make(first, second) from the set.

Specified by:
remove in interface Relation<T1,T2>
Overrides:
remove in class DelegatingRelation<T1,T2>

inverse

public Relation<T2,T1> inverse()
Description copied from interface: Relation
Produce the inverse of the relation, derived by swapping the elements of each pair. Need not allow mutation, but must reflect subsequent changes.

Specified by:
inverse in interface Relation<T1,T2>
Overrides:
inverse in class DelegatingRelation<T1,T2>

firstSet

public PredicateSet<T1> firstSet()
Description copied from interface: Relation
The set of firsts. Need not allow mutation, but must reflect subsequent changes.

Specified by:
firstSet in interface Relation<T1,T2>
Overrides:
firstSet in class DelegatingRelation<T1,T2>

containsFirst

public boolean containsFirst(T1 first)
Description copied from interface: Relation
Whether a pair with the given first value appears in the set.

Specified by:
containsFirst in interface Relation<T1,T2>
Overrides:
containsFirst in class DelegatingRelation<T1,T2>

matchFirst

public PredicateSet<T2> matchFirst(T1 first)
Description copied from interface: Relation
The set of seconds corresponding to a specific first. Need not allow mutation, but must reflect subsequent changes.

Specified by:
matchFirst in interface Relation<T1,T2>
Overrides:
matchFirst in class DelegatingRelation<T1,T2>

excludeFirsts

public PredicateSet<T2> excludeFirsts()
Description copied from interface: Relation
The set of seconds for which there exists a (first, second) pair in the relation. Equivalent to Relation.secondSet(), but defined redundantly for consistency with higher-arity relations. Need not allow mutation, but must reflect subsequent changes.

Specified by:
excludeFirsts in interface Relation<T1,T2>
Overrides:
excludeFirsts in class DelegatingRelation<T1,T2>

secondSet

public PredicateSet<T2> secondSet()
Description copied from interface: Relation
The set of seconds. Need not allow mutation, but must reflect subsequent changes.

Specified by:
secondSet in interface Relation<T1,T2>
Overrides:
secondSet in class DelegatingRelation<T1,T2>

containsSecond

public boolean containsSecond(T2 second)
Description copied from interface: Relation
Whether a pair with the given second value appears in the set.

Specified by:
containsSecond in interface Relation<T1,T2>
Overrides:
containsSecond in class DelegatingRelation<T1,T2>

matchSecond

public PredicateSet<T1> matchSecond(T2 second)
Description copied from interface: Relation
The set of firsts corresponding to a specific second. Need not allow mutation, but must reflect subsequent changes.

Specified by:
matchSecond in interface Relation<T1,T2>
Overrides:
matchSecond in class DelegatingRelation<T1,T2>

excludeSeconds

public PredicateSet<T1> excludeSeconds()
Description copied from interface: Relation
The set of firsts for which there exists a (first, second) pair in the relation. Equivalent to Relation.firstSet(), but defined redundantly for consistency with higher-arity relations. Need not allow mutation, but must reflect subsequent changes.

Specified by:
excludeSeconds in interface Relation<T1,T2>
Overrides:
excludeSeconds in class DelegatingRelation<T1,T2>

make

public static <T1,T2> ImmutableRelation<T1,T2> make(Relation<T1,T2> relation)
Call the constructor (allows T1 and T2 to be inferred).