|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface FunctionalRelation<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 |
|---|
T2 value(T1 first)
first, or null if there is none.
value in interface Lambda<T1,T2>LambdaMap<T1,T2> functionMap()
boolean add(Pair<T1,T2> pair)
add in interface Collection<Pair<T1,T2>>add in interface Relation<T1,T2>add in interface Set<Pair<T1,T2>>IllegalArgumentException - If containsFirst(pair.first()) but not contains(pair).
boolean add(T1 first,
T2 second)
Pair.make(first, second) to the set. If the pair violates the cardinality constraint,
throw an exception.
add in interface Relation<T1,T2>IllegalArgumentException - If containsFirst(first) but not contains(first, second).Relation<T2,T1> inverse()
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.
inverse in interface Relation<T1,T2>PredicateSet<T2> matchFirst(T1 first)
matchFirst in interface Relation<T1,T2>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||