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

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by edu.rice.cs.plt.collect.AbstractPredicateSet<Pair<T1,T2>>
              extended by edu.rice.cs.plt.collect.AbstractRelation<T1,T3>
                  extended by edu.rice.cs.plt.collect.ComposedRelation<T1,T2,T3>
All Implemented Interfaces:
PredicateSet<Pair<T1,T3>>, Relation<T1,T3>, SizedIterable<Pair<T1,T3>>, Predicate<Object>, Predicate2<T1,T3>, Serializable, Iterable<Pair<T1,T3>>, Collection<Pair<T1,T3>>, Set<Pair<T1,T3>>

public class ComposedRelation<T1,T2,T3>
extends AbstractRelation<T1,T3>
implements Serializable

The transitive composition of two relations, lazily constructed and dynamically-updated. An entry (x, y) appears in the relation if and only if there is an entry (x, z) in the first relation and (z, y) in the second.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.rice.cs.plt.collect.AbstractRelation
AbstractRelation.InverseRelation
 
Constructor Summary
ComposedRelation(Relation<T1,T2> rel1, Relation<T2,T3> rel2)
           
 
Method Summary
 int compositeHeight()
           
 int compositeSize()
           
 boolean contains(Object o)
          Test whether the set contains an object.
 boolean contains(T1 first, T3 second)
          Tests whether the given objects appear as a pair in this relation.
 PredicateSet<T1> firstSet()
          The set of firsts.
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 boolean isEmpty()
          Returns size(1) == 0.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 Iterator<Pair<T1,T3>> iterator()
          For each element of rel1.firstSet(), iterate over all transitive matches.
 PredicateSet<T3> matchFirst(T1 first)
          The set of seconds corresponding to a specific first.
 PredicateSet<T1> matchSecond(T3 second)
          The set of firsts corresponding to a specific second.
 PredicateSet<T3> secondSet()
          The set of seconds.
 
Methods inherited from class edu.rice.cs.plt.collect.AbstractRelation
add, add, containsFirst, containsSecond, excludeFirsts, excludeSeconds, inverse, remove, remove
 
Methods inherited from class edu.rice.cs.plt.collect.AbstractPredicateSet
size, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, equals, hashCode, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface edu.rice.cs.plt.iter.SizedIterable
size, size
 

Constructor Detail

ComposedRelation

public ComposedRelation(Relation<T1,T2> rel1,
                        Relation<T2,T3> rel2)
Method Detail

compositeHeight

public int compositeHeight()

compositeSize

public int compositeSize()

isEmpty

public boolean isEmpty()
Description copied from class: AbstractPredicateSet
Returns size(1) == 0.

Specified by:
isEmpty in interface SizedIterable<Pair<T1,T3>>
Specified by:
isEmpty in interface Collection<Pair<T1,T3>>
Specified by:
isEmpty in interface Set<Pair<T1,T3>>
Overrides:
isEmpty in class AbstractPredicateSet<Pair<T1,T3>>

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,T3>>
Specified by:
isInfinite in class AbstractRelation<T1,T3>

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,T3>>
Specified by:
hasFixedSize in class AbstractRelation<T1,T3>

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,T3>>
Specified by:
isStatic in class AbstractRelation<T1,T3>

contains

public boolean contains(T1 first,
                        T3 second)
Description copied from class: AbstractRelation
Tests whether the given objects appear as a pair in this relation. Not guaranteed to have types T1 and T2 because the Collection.contains(java.lang.Object) method allows arbitrary objects.

Specified by:
contains in interface Relation<T1,T3>
Specified by:
contains in interface Predicate2<T1,T3>
Specified by:
contains in class AbstractRelation<T1,T3>

contains

public boolean contains(Object o)
Description copied from class: AbstractPredicateSet
Test whether the set contains an object. Overridden here to force subclasses to provide an implementation. The default implementation (AbstractCollection.contains(java.lang.Object)) is a linear search, which is almost always unreasonable for a set.

Specified by:
contains in interface Relation<T1,T3>
Specified by:
contains in interface Predicate<Object>
Specified by:
contains in interface Collection<Pair<T1,T3>>
Specified by:
contains in interface Set<Pair<T1,T3>>
Specified by:
contains in class AbstractRelation<T1,T3>

iterator

public Iterator<Pair<T1,T3>> iterator()
For each element of rel1.firstSet(), iterate over all transitive matches.

Specified by:
iterator in interface Iterable<Pair<T1,T3>>
Specified by:
iterator in interface Collection<Pair<T1,T3>>
Specified by:
iterator in interface Set<Pair<T1,T3>>
Specified by:
iterator in class AbstractRelation<T1,T3>

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,T3>
Specified by:
firstSet in class AbstractRelation<T1,T3>

matchFirst

public PredicateSet<T3> 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,T3>
Specified by:
matchFirst in class AbstractRelation<T1,T3>

secondSet

public PredicateSet<T3> 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,T3>
Specified by:
secondSet in class AbstractRelation<T1,T3>

matchSecond

public PredicateSet<T1> matchSecond(T3 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,T3>
Specified by:
matchSecond in class AbstractRelation<T1,T3>