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

All Superinterfaces:
Collection<Pair<T1,T2>>, Iterable<Pair<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.InverseFunctionalRelation, AbstractInjectiveRelation, AbstractOneToOneRelation, AbstractOneToOneRelation.InverseOneToOneRelation, EmptyRelation, IndexedInjectiveRelation, IndexedOneToOneRelation, SingletonRelation

public interface InjectiveRelation<T1,T2>
extends Relation<T1,T2>

An injective relation: each second (of type T2) corresponds to at most one first (of type T1). This can be viewed as modeling both a one-to-many relationship between firsts and seconds and a function from seconds to firsts.


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.
 T1 antecedent(T2 second)
          Produce the first corresponding to second, or null if there is none.
 LambdaMap<T2,T1> injectionMap()
          A map view of the relation, mapping seconds to firsts.
 FunctionalRelation<T2,T1> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
 PredicateSet<T1> matchSecond(T2 second)
          The set of firsts corresponding to a specific second.
 
Methods inherited from interface edu.rice.cs.plt.collect.Relation
contains, contains, containsFirst, containsSecond, excludeFirsts, excludeSeconds, firstSet, matchFirst, 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

antecedent

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


injectionMap

LambdaMap<T2,T1> injectionMap()
A map view of the relation, mapping seconds to firsts. 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 containsSecond(pair.second()) 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 containsSecond(second) but not contains(first, second).

inverse

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

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

matchSecond

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

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