edu.rice.cs.plt.collect
Class AbstractRelation.InverseRelation

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

protected class AbstractRelation.InverseRelation
extends AbstractPredicateSet<Pair<T2,T1>>
implements Relation<T2,T1>, Serializable

An inverse of the enclosing relation, defined in terms of Pair.inverse(). Mutation is supported, with changes reflected in the enclosing relation. Inherits the AbstractSet implementations of AbstractCollection.toArray(), AbstractCollection.toArray(Object[]), AbstractCollection.containsAll(java.util.Collection), AbstractCollection.addAll(java.util.Collection), AbstractCollection.retainAll(java.util.Collection), AbstractSet.removeAll(java.util.Collection), java.util.AbstractSet#toString(), equals(Object), and hashCode(). All other methods delegate to their corresponding methods in the enclosing AbstractRelation (inverting pairs as necessary).

See Also:
Serialized Form

Constructor Summary
protected AbstractRelation.InverseRelation()
           
 
Method Summary
 boolean add(Pair<T2,T1> pair)
          Add Pair.make(p.first(), p.second()) to the set.
 boolean add(T2 f, T1 s)
          Add Pair.make(first, second) to the set.
 void clear()
           
 boolean contains(Object o)
          Test whether the set contains an object.
 boolean contains(T2 f, T1 s)
          Whether Pair.make(first, second) appears in the set.
 boolean containsFirst(T2 f)
          Whether a pair with the given first value appears in the set.
 boolean containsSecond(T1 s)
          Whether a pair with the given second value appears in the set.
 PredicateSet<T1> excludeFirsts()
          The set of seconds for which there exists a (first, second) pair in the relation.
 PredicateSet<T2> excludeSeconds()
          The set of firsts for which there exists a (first, second) pair in the relation.
 PredicateSet<T2> firstSet()
          The set of firsts.
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 Relation<T1,T2> inverse()
          Produce the inverse of the relation, derived by swapping the elements of each pair.
 boolean isEmpty()
          Returns size(1) == 0.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 Iterator<Pair<T2,T1>> iterator()
           
 PredicateSet<T1> matchFirst(T2 f)
          The set of seconds corresponding to a specific first.
 PredicateSet<T2> matchSecond(T1 s)
          The set of firsts corresponding to a specific second.
 boolean remove(Object o)
          If o is a pair, remove Pair.make(o.first(), o.second()) from the set.
 boolean remove(T2 f, T1 s)
          Remove Pair.make(first, second) from the set.
 PredicateSet<T1> secondSet()
          The set of seconds.
 int size()
          Returns size(Integer.MAX_VALUE).
 int size(int bound)
          Computes the size by traversing the iterator (requires linear time).
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AbstractRelation.InverseRelation

protected AbstractRelation.InverseRelation()
Method Detail

size

public int size()
Description copied from class: AbstractPredicateSet
Returns size(Integer.MAX_VALUE).

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

size

public int size(int bound)
Description copied from class: AbstractPredicateSet
Computes the size by traversing the iterator (requires linear time).

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

isEmpty

public boolean isEmpty()
Description copied from class: AbstractPredicateSet
Returns size(1) == 0.

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

isInfinite

public boolean isInfinite()
Description copied from interface: SizedIterable
true if the iterable is known to have infinite size. If true, an iterator over the iterable in its current state will never return false from hasNext().

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

hasFixedSize

public boolean hasFixedSize()
Description copied from interface: SizedIterable
true if this iterable is known to have a fixed size. This is the case if the iterable is immutable, or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it is guaranteed to never become finite.

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

isStatic

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

contains

public boolean contains(Object o)
Description copied from class: AbstractPredicateSet
Test whether the set contains an object. Overridden here to force subclasses to provide an implementation. The default implementation (AbstractCollection.contains(java.lang.Object)) is a linear search, which is almost always unreasonable for a set.

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

iterator

public Iterator<Pair<T2,T1>> iterator()
Specified by:
iterator in interface Iterable<Pair<T2,T1>>
Specified by:
iterator in interface Collection<Pair<T2,T1>>
Specified by:
iterator in interface Set<Pair<T2,T1>>
Specified by:
iterator in class AbstractCollection<Pair<T2,T1>>

add

public boolean add(Pair<T2,T1> pair)
Description copied from interface: Relation
Add Pair.make(p.first(), p.second()) to the set. (That is, the pair that is added is not an instance of some subclass of Pair.)

Specified by:
add in interface Relation<T2,T1>
Specified by:
add in interface Collection<Pair<T2,T1>>
Specified by:
add in interface Set<Pair<T2,T1>>
Overrides:
add in class AbstractCollection<Pair<T2,T1>>

remove

public boolean remove(Object o)
Description copied from interface: Relation
If o is a pair, remove Pair.make(o.first(), o.second()) from the set. (That is, equality is always defined according to the Pair class's equals method, not that of some subclass.)

Specified by:
remove in interface Relation<T2,T1>
Specified by:
remove in interface Collection<Pair<T2,T1>>
Specified by:
remove in interface Set<Pair<T2,T1>>
Overrides:
remove in class AbstractCollection<Pair<T2,T1>>

clear

public void clear()
Specified by:
clear in interface Collection<Pair<T2,T1>>
Specified by:
clear in interface Set<Pair<T2,T1>>
Overrides:
clear in class AbstractCollection<Pair<T2,T1>>

contains

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

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

add

public boolean add(T2 f,
                   T1 s)
Description copied from interface: Relation
Add Pair.make(first, second) to the set.

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

remove

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

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

inverse

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

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

firstSet

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

containsFirst

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

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

matchFirst

public PredicateSet<T1> matchFirst(T2 f)
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<T2,T1>

excludeFirsts

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

secondSet

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

containsSecond

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

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

matchSecond

public PredicateSet<T2> matchSecond(T1 s)
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<T2,T1>

excludeSeconds

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