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

All Superinterfaces:
Collection<Pair<T1,T2>>, Iterable<Pair<T1,T2>>, Lambda<T1,T2>, Predicate<Object>, Predicate2<T1,T2>, PredicateSet<Pair<T1,T2>>, Relation<T1,T2>, Set<Pair<T1,T2>>, SizedIterable<Pair<T1,T2>>
All Known Subinterfaces:
OneToOneRelation<T1,T2>
All Known Implementing Classes:
AbstractFunctionalRelation, AbstractInjectiveRelation.InverseInjectiveRelation, AbstractOneToOneRelation, AbstractOneToOneRelation.InverseOneToOneRelation, EmptyRelation, IndexedFunctionalRelation, IndexedOneToOneRelation, SingletonRelation

public interface FunctionalRelation<T1,T2>
extends Relation<T1,T2>, Lambda<T1,T2>

A functional relation: each first (of type T1) corresponds to at most one second (of type T2). This can be viewed as modeling both a function from firsts to seconds and a one-to-many relationship between seconds and firsts. Like a Map, each "key" (first) maps to a single "value" (second); users may prefer using FunctionalRelations, however, where it will also be useful to map from "values" (seconds) to sets of "keys" (firsts).

The similarity with maps suggests that it would be useful for this interface to extend Map. Unfortunately, the hashCode() conventions for Sets and Pairs do not correspond directly to those of Maps (and, in general, the elements of a Relation may be Pairs with arbitrarily-defined hashCode methods).


Method Summary
 boolean add(Pair<T1,T2> pair)
          Add a pair to the set.
 boolean add(T1 first, T2 second)
          Add Pair.make(first, second) to the set.
 LambdaMap<T1,T2> functionMap()
          A map view of the relation, mapping firsts to seconds.
 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.
 T2 value(T1 first)
          Produce the second corresponding to first, or null if there is none.
 
Methods inherited from interface edu.rice.cs.plt.collect.Relation
contains, contains, containsFirst, containsSecond, excludeFirsts, excludeSeconds, firstSet, matchSecond, remove, remove, secondSet
 
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

value

T2 value(T1 first)
Produce the second corresponding to first, or null if there is none.

Specified by:
value in interface Lambda<T1,T2>

functionMap

LambdaMap<T1,T2> functionMap()
A map view of the relation, mapping firsts to seconds. Need not allow mutation, but must reflect subsequent changes.


add

boolean add(Pair<T1,T2> pair)
Add a pair to the set. If the pair violates the cardinality constraint, throw an exception.

Specified by:
add in interface Collection<Pair<T1,T2>>
Specified by:
add in interface Relation<T1,T2>
Specified by:
add in interface Set<Pair<T1,T2>>
Throws:
IllegalArgumentException - If containsFirst(pair.first()) but not contains(pair).

add

boolean add(T1 first,
            T2 second)
Add Pair.make(first, second) to the set. If the pair violates the cardinality constraint, throw an exception.

Specified by:
add in interface Relation<T1,T2>
Throws:
IllegalArgumentException - If containsFirst(first) but not contains(first, second).

inverse

Relation<T2,T1> inverse()
Produce the inverse of the relation, derived by swapping the elements of each pair. The result must be an InjectiveRelation; however, limitations in Java's overriding rules (possible just a javac bug) prevent this assertion from being expressed in the return type, because a OneToOneRelation must be allowed to extend both interfaces. Need not allow mutation, but must reflect subsequent changes.

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

matchFirst

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

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