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

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by edu.rice.cs.plt.collect.AbstractPredicateSet<Pair<T1,T2>>
              extended by edu.rice.cs.plt.collect.AbstractRelation<T1,T2>
                  extended by edu.rice.cs.plt.collect.AbstractInjectiveRelation<T1,T2>
All Implemented Interfaces:
InjectiveRelation<T1,T2>, PredicateSet<Pair<T1,T2>>, Relation<T1,T2>, SizedIterable<Pair<T1,T2>>, Predicate<java.lang.Object>, Predicate2<T1,T2>, java.lang.Iterable<Pair<T1,T2>>, java.util.Collection<Pair<T1,T2>>, java.util.Set<Pair<T1,T2>>
Direct Known Subclasses:
IndexedInjectiveRelation

public abstract class AbstractInjectiveRelation<T1,T2>
extends AbstractRelation<T1,T2>
implements InjectiveRelation<T1,T2>

An abstract parent class for implementations of InjectiveRelation. Subclasses must provide isStatic(), injectionMap(), firstSet(), and matchFirst(T1). To support mutation, they must also override AbstractRelation.add(Object, Object) and AbstractRelation.remove(Object, Object). For best performance, they may also override AbstractCollection.clear().


Nested Class Summary
protected  class AbstractInjectiveRelation.InverseInjectiveRelation
          An inverse of the enclosing relation.
 
Nested classes/interfaces inherited from class edu.rice.cs.plt.collect.AbstractRelation
AbstractRelation.InverseRelation
 
Constructor Summary
AbstractInjectiveRelation()
           
 
Method Summary
 T1 antecedent(T2 second)
          Returns injectionMap().get(first).
 boolean contains(java.lang.Object obj)
          Checks for the given entry in functionMap().
 boolean contains(T1 first, T2 second)
          Checks for the given entry in functionMap().
 boolean containsSecond(T2 second)
          Returns injectionMap().containsKey(second).
abstract  PredicateSet<T1> firstSet()
          The set of firsts.
 boolean hasFixedSize()
          Returns injectionMap().keySet().hasFixedSize().
abstract  LambdaMap<T2,T1> injectionMap()
          A map view of the relation, mapping seconds to firsts.
 FunctionalRelation<T2,T1> inverse()
          Returns an AbstractInjectiveRelation.InverseInjectiveRelation.
 boolean isEmpty()
          Returns injectionMap().isEmpty().
 boolean isInfinite()
          Returns injectionMap().keySet().isInfinite().
abstract  boolean isStatic()
          true if this iterable is unchanging.
 java.util.Iterator<Pair<T1,T2>> iterator()
          Produces an iterator based on injectionMap().entrySet().
abstract  PredicateSet<T2> matchFirst(T1 first)
          The set of seconds corresponding to a specific first.
 PredicateSet<T1> matchSecond(T2 second)
          Returns a set that queries and manipulates the mapping from second in injectionMap().
 PredicateSet<T2> secondSet()
          Returns injectionMap().keySet().
 int size()
          Returns injectionMap().size().
 int size(int bound)
          Returns injectionMap().keySet().size(bound).
 
Methods inherited from class edu.rice.cs.plt.collect.AbstractRelation
add, add, containsFirst, excludeFirsts, excludeSeconds, remove, remove
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, retainAll, 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.InjectiveRelation
add, add
 
Methods inherited from interface edu.rice.cs.plt.collect.Relation
containsFirst, excludeFirsts, excludeSeconds, remove, remove
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AbstractInjectiveRelation

public AbstractInjectiveRelation()
Method Detail

isStatic

public abstract boolean isStatic()
Description copied from interface: SizedIterable
true if this iterable is unchanging. This implies that hasFixedSize() is true, and that iterator() will always return the same (either == or equal() and immutable) elements in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if two objects are equal, they will never become inequal, and vice versa.)

Specified by:
isStatic in interface SizedIterable<Pair<T1,T2>>
Specified by:
isStatic in class AbstractRelation<T1,T2>

injectionMap

public abstract 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>

firstSet

public abstract 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>
Specified by:
firstSet in class AbstractRelation<T1,T2>

matchFirst

public abstract PredicateSet<T2> matchFirst(T1 first)
Description copied from interface: Relation
The set of seconds corresponding to a specific first. Need not allow mutation, but must reflect subsequent changes.

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

isEmpty

public boolean isEmpty()
Returns injectionMap().isEmpty().

Specified by:
isEmpty in interface SizedIterable<Pair<T1,T2>>
Specified by:
isEmpty in interface java.util.Collection<Pair<T1,T2>>
Specified by:
isEmpty in interface java.util.Set<Pair<T1,T2>>
Overrides:
isEmpty in class AbstractPredicateSet<Pair<T1,T2>>

size

public int size()
Returns injectionMap().size().

Specified by:
size in interface SizedIterable<Pair<T1,T2>>
Specified by:
size in interface java.util.Collection<Pair<T1,T2>>
Specified by:
size in interface java.util.Set<Pair<T1,T2>>
Overrides:
size in class AbstractPredicateSet<Pair<T1,T2>>

size

public int size(int bound)
Returns injectionMap().keySet().size(bound).

Specified by:
size in interface SizedIterable<Pair<T1,T2>>
Overrides:
size in class AbstractPredicateSet<Pair<T1,T2>>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

public boolean isInfinite()
Returns injectionMap().keySet().isInfinite().

Specified by:
isInfinite in interface SizedIterable<Pair<T1,T2>>
Specified by:
isInfinite in class AbstractRelation<T1,T2>

hasFixedSize

public boolean hasFixedSize()
Returns injectionMap().keySet().hasFixedSize().

Specified by:
hasFixedSize in interface SizedIterable<Pair<T1,T2>>
Specified by:
hasFixedSize in class AbstractRelation<T1,T2>

contains

public boolean contains(T1 first,
                        T2 second)
Checks for the given entry in functionMap().

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

contains

public boolean contains(java.lang.Object obj)
Checks for the given entry in functionMap().

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

iterator

public java.util.Iterator<Pair<T1,T2>> iterator()
Produces an iterator based on injectionMap().entrySet().

Specified by:
iterator in interface java.lang.Iterable<Pair<T1,T2>>
Specified by:
iterator in interface java.util.Collection<Pair<T1,T2>>
Specified by:
iterator in interface java.util.Set<Pair<T1,T2>>
Specified by:
iterator in class AbstractRelation<T1,T2>

secondSet

public PredicateSet<T2> secondSet()
Returns injectionMap().keySet().

Specified by:
secondSet in interface Relation<T1,T2>
Specified by:
secondSet in class AbstractRelation<T1,T2>

containsSecond

public boolean containsSecond(T2 second)
Returns injectionMap().containsKey(second).

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

matchSecond

public PredicateSet<T1> matchSecond(T2 second)
Returns a set that queries and manipulates the mapping from second in injectionMap().

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

antecedent

public T1 antecedent(T2 second)
Returns injectionMap().get(first).

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

inverse

public FunctionalRelation<T2,T1> inverse()
Returns an AbstractInjectiveRelation.InverseInjectiveRelation.

Specified by:
inverse in interface InjectiveRelation<T1,T2>
Specified by:
inverse in interface Relation<T1,T2>
Overrides:
inverse in class AbstractRelation<T1,T2>