edu.rice.cs.plt.collect
Interface Relation<T1,T2>

All Superinterfaces:
java.util.Collection<Pair<T1,T2>>, java.lang.Iterable<Pair<T1,T2>>, Predicate<java.lang.Object>, Predicate2<T1,T2>, PredicateSet<Pair<T1,T2>>, java.util.Set<Pair<T1,T2>>, SizedIterable<Pair<T1,T2>>
All Known Subinterfaces:
FunctionalRelation<T1,T2>, InjectiveRelation<T1,T2>, OneToOneRelation<T1,T2>
All Known Implementing Classes:
AbstractFunctionalRelation, AbstractFunctionalRelation.InverseFunctionalRelation, AbstractInjectiveRelation, AbstractInjectiveRelation.InverseInjectiveRelation, AbstractOneToOneRelation, AbstractOneToOneRelation.InverseOneToOneRelation, AbstractRelation, AbstractRelation.InverseRelation, CartesianRelation, ComplementRelation, ComposedRelation, DelegatingRelation, EmptyRelation, FilteredRelation, ImmutableRelation, IndexedFunctionalRelation, IndexedInjectiveRelation, IndexedOneToOneRelation, IndexedRelation, IntersectionRelation, SingletonRelation, UnindexedRelation, UnionRelation

public interface Relation<T1,T2>
extends PredicateSet<Pair<T1,T2>>, Predicate2<T1,T2>

A set of pairs representing a binary relation. Relations can be viewed as generalizations of maps in which keys map to sets of values, and the mapping occurs in both directions.


Method Summary
 boolean add(Pair<T1,T2> pair)
          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 contains(java.lang.Object o)
          Whether the given object appears in 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.
 Relation<T2,T1> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
 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(java.lang.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.
 PredicateSet<T2> secondSet()
          The set of seconds.
 
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
hasFixedSize, isEmpty, isInfinite, isStatic, size, size
 

Method Detail

contains

boolean contains(java.lang.Object o)
Whether the given object appears in the set.

Specified by:
contains in interface java.util.Collection<Pair<T1,T2>>
Specified by:
contains in interface Predicate<java.lang.Object>
Specified by:
contains in interface java.util.Set<Pair<T1,T2>>

contains

boolean contains(T1 first,
                 T2 second)
Whether Pair.make(first, second) appears in the set.

Specified by:
contains in interface Predicate2<T1,T2>

add

boolean add(Pair<T1,T2> pair)
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 java.util.Collection<Pair<T1,T2>>
Specified by:
add in interface java.util.Set<Pair<T1,T2>>

add

boolean add(T1 first,
            T2 second)
Add Pair.make(first, second) to the set.


remove

boolean remove(java.lang.Object o)
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 java.util.Collection<Pair<T1,T2>>
Specified by:
remove in interface java.util.Set<Pair<T1,T2>>

remove

boolean remove(T1 first,
               T2 second)
Remove Pair.make(first, second) from the set.


inverse

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


firstSet

PredicateSet<T1> firstSet()
The set of firsts. Need not allow mutation, but must reflect subsequent changes.


containsFirst

boolean containsFirst(T1 first)
Whether a pair with the given first value appears in the set.


matchFirst

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


excludeFirsts

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


secondSet

PredicateSet<T2> secondSet()
The set of seconds. Need not allow mutation, but must reflect subsequent changes.


containsSecond

boolean containsSecond(T2 second)
Whether a pair with the given second value appears in the set.


matchSecond

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


excludeSeconds

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