edu.rice.cs.plt.collect
Class AbstractFunctionalRelation<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.AbstractFunctionalRelation<T1,T2>
All Implemented Interfaces:
FunctionalRelation<T1,T2>, PredicateSet<Pair<T1,T2>>, Relation<T1,T2>, SizedIterable<Pair<T1,T2>>, Lambda<T1,T2>, Predicate<Object>, Predicate2<T1,T2>, Iterable<Pair<T1,T2>>, Collection<Pair<T1,T2>>, Set<Pair<T1,T2>>
Direct Known Subclasses:
AbstractOneToOneRelation, IndexedFunctionalRelation

public abstract class AbstractFunctionalRelation<T1,T2>
extends AbstractRelation<T1,T2>
implements FunctionalRelation<T1,T2>

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

Constructor Detail

AbstractFunctionalRelation

public AbstractFunctionalRelation()
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>

functionMap

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

secondSet

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

matchSecond

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

isEmpty

public boolean isEmpty()
Returns functionMap().isEmpty().

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

size

public int size()
Returns functionMap().size().

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

size

public int size(int bound)
Returns functionMap().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 functionMap().keySet().isInfinite().

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

hasFixedSize

public boolean hasFixedSize()
Returns functionMap().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(Object obj)
Checks for the given entry in functionMap().

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

iterator

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

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

firstSet

public PredicateSet<T1> firstSet()
Returns functionMap().keySet().

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

containsFirst

public boolean containsFirst(T1 first)
Returns functionMap().containsKey(first).

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

matchFirst

public PredicateSet<T2> matchFirst(T1 first)
Returns a set that queries and manipulates the mapping from first in functionMap().

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

value

public T2 value(T1 first)
Returns functionMap().get(first).

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

inverse

public Relation<T2,T1> inverse()
Returns an AbstractFunctionalRelation.InverseFunctionalRelation.

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