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

java.lang.Object
  extended by edu.rice.cs.plt.collect.EmptyCollection<Pair<T1,T2>>
      extended by edu.rice.cs.plt.collect.EmptyRelation<T1,T2>
All Implemented Interfaces:
FunctionalRelation<T1,T2>, InjectiveRelation<T1,T2>, OneToOneRelation<T1,T2>, PredicateSet<Pair<T1,T2>>, Relation<T1,T2>, SizedIterable<Pair<T1,T2>>, Lambda<T1,T2>, Predicate<java.lang.Object>, Predicate2<T1,T2>, java.io.Serializable, java.lang.Iterable<Pair<T1,T2>>, java.util.Collection<Pair<T1,T2>>, java.util.Set<Pair<T1,T2>>

public final class EmptyRelation<T1,T2>
extends EmptyCollection<Pair<T1,T2>>
implements OneToOneRelation<T1,T2>, java.io.Serializable

An immutable, empty, one-to-one relation.

See Also:
Serialized Form

Field Summary
static EmptyRelation<java.lang.Object,java.lang.Object> INSTANCE
           
 
Method Summary
 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.
 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.
 boolean equals(java.lang.Object o)
           
 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.
 LambdaMap<T1,T2> functionMap()
          A map view of the relation, mapping firsts to seconds.
 int hashCode()
           
 LambdaMap<T2,T1> injectionMap()
          A map view of the relation, mapping seconds to firsts.
 OneToOneRelation<T2,T1> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
static
<T1,T2> EmptyRelation<T1,T2>
make()
          Return a singleton, cast to the appropriate type.
 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(T1 first, T2 second)
          Remove Pair.make(first, second) from the set.
 PredicateSet<T2> secondSet()
          The set of seconds.
 T2 value(T1 first)
          Produce the second corresponding to first, or null if there is none.
 
Methods inherited from class edu.rice.cs.plt.collect.EmptyCollection
add, addAll, clear, contains, containsAll, hasFixedSize, isEmpty, isInfinite, isStatic, iterator, remove, removeAll, retainAll, size, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.plt.collect.OneToOneRelation
add
 
Methods inherited from interface edu.rice.cs.plt.collect.Relation
contains, remove
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface edu.rice.cs.plt.iter.SizedIterable
hasFixedSize, isEmpty, isInfinite, isStatic, size, size
 

Field Detail

INSTANCE

public static final EmptyRelation<java.lang.Object,java.lang.Object> INSTANCE
Method Detail

contains

public boolean contains(T1 first,
                        T2 second)
Description copied from interface: Relation
Whether Pair.make(first, second) appears in the set.

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

add

public boolean add(T1 first,
                   T2 second)
Description copied from interface: OneToOneRelation
Add Pair.make(first, second) to the set. If the pair violates the cardinality constraint, throw an exception.

Specified by:
add in interface FunctionalRelation<T1,T2>
Specified by:
add in interface InjectiveRelation<T1,T2>
Specified by:
add in interface OneToOneRelation<T1,T2>
Specified by:
add in interface Relation<T1,T2>

remove

public boolean remove(T1 first,
                      T2 second)
Description copied from interface: Relation
Remove Pair.make(first, second) from the set.

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

inverse

public OneToOneRelation<T2,T1> inverse()
Description copied from interface: OneToOneRelation
Produce the inverse of the relation, derived by swapping the elements of each pair. Note that the inverse is one-to-one. Need not allow mutation, but must reflect subsequent changes.

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

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,T2>

containsFirst

public boolean containsFirst(T1 first)
Description copied from interface: Relation
Whether a pair with the given first value appears in the set.

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

matchFirst

public PredicateSet<T2> matchFirst(T1 first)
Description copied from interface: FunctionalRelation
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 FunctionalRelation<T1,T2>
Specified by:
matchFirst in interface Relation<T1,T2>

excludeFirsts

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

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

secondSet

public PredicateSet<T2> 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,T2>

containsSecond

public boolean containsSecond(T2 second)
Description copied from interface: Relation
Whether a pair with the given second value appears in the set.

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

matchSecond

public PredicateSet<T1> matchSecond(T2 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 InjectiveRelation<T1,T2>
Specified by:
matchSecond in interface Relation<T1,T2>

excludeSeconds

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

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

value

public T2 value(T1 first)
Description copied from interface: FunctionalRelation
Produce the second corresponding to first, or null if there is none.

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

antecedent

public T1 antecedent(T2 second)
Description copied from interface: InjectiveRelation
Produce the first corresponding to second, or null if there is none.

Specified by:
antecedent in interface InjectiveRelation<T1,T2>

functionMap

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

Specified by:
functionMap in interface FunctionalRelation<T1,T2>

injectionMap

public LambdaMap<T2,T1> injectionMap()
Description copied from interface: InjectiveRelation
A map view of the relation, mapping seconds to firsts. Need not allow mutation, but must reflect subsequent changes.

Specified by:
injectionMap in interface InjectiveRelation<T1,T2>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<Pair<T1,T2>>
Specified by:
equals in interface java.util.Set<Pair<T1,T2>>
Specified by:
equals in class EmptyCollection<Pair<T1,T2>>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<Pair<T1,T2>>
Specified by:
hashCode in interface java.util.Set<Pair<T1,T2>>
Specified by:
hashCode in class EmptyCollection<Pair<T1,T2>>

make

public static <T1,T2> EmptyRelation<T1,T2> make()
Return a singleton, cast to the appropriate type.