edu.rice.cs.plt.collect
Class DelegatingRelation<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>
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>>
Direct Known Subclasses:
ImmutableRelation

public class DelegatingRelation<T1,T2>
extends DelegatingSet<Pair<T1,T2>>
implements Relation<T1,T2>

A relation that delegates all operations to a wrapped relation. Subclasses can be defined that override a few of the methods, while maintaining the default delegation behavior in most cases. Subclasses can also 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
protected  Relation<T1,T2> _delegate
           
 
Constructor Summary
DelegatingRelation(Relation<T1,T2> delegate)
           
 
Method Summary
 boolean add(T1 first, T2 second)
          Add Pair.make(first, second) to the set.
 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.
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 Relation<T2,T1> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 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(T1 first, T2 second)
          Remove Pair.make(first, second) from the set.
 PredicateSet<T2> secondSet()
          The set of seconds.
 int size(int bound)
          Compute the number of elements in the iterable, up to the given bound.
 
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, add, addAll, clear, compositeHeight, compositeSize, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, 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
add, contains, remove
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface edu.rice.cs.plt.iter.SizedIterable
isEmpty, size
 

Field Detail

_delegate

protected final Relation<T1,T2> _delegate
Constructor Detail

DelegatingRelation

public DelegatingRelation(Relation<T1,T2> delegate)
Method Detail

size

public int size(int bound)
Description copied from interface: SizedIterable
Compute the number of elements in the iterable, up to the given bound. If the size is infinite or greater than bound, bound is returned.

Specified by:
size in interface SizedIterable<Pair<T1,T2>>
Overrides:
size in class DelegatingCollection<Pair<T1,T2>>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

public boolean isInfinite()
Description copied from interface: SizedIterable
true if the iterable is known to have infinite size. If true, an iterator over the iterable in its current state will never return false from hasNext().

Specified by:
isInfinite in interface SizedIterable<Pair<T1,T2>>
Overrides:
isInfinite in class DelegatingCollection<Pair<T1,T2>>

hasFixedSize

public boolean hasFixedSize()
Description copied from interface: SizedIterable
true if this iterable is known to have a fixed size. This is the case if the iterable is immutable, or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it is guaranteed to never become finite.

Specified by:
hasFixedSize in interface SizedIterable<Pair<T1,T2>>
Overrides:
hasFixedSize in class DelegatingCollection<Pair<T1,T2>>

isStatic

public boolean isStatic()
Description copied from interface: SizedIterable
true if this iterable is unchanging. This implies that hasFixedSize() is true, and that iterator() will always return the same (either == or equal() and immutable) elements in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if two objects are equal, they will never become inequal, and vice versa.)

Specified by:
isStatic in interface SizedIterable<Pair<T1,T2>>
Overrides:
isStatic 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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>