edu.rice.cs.plt.collect
Class FilteredSet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by edu.rice.cs.plt.collect.AbstractPredicateSet<T>
              extended by edu.rice.cs.plt.collect.FilteredSet<T>
All Implemented Interfaces:
PredicateSet<T>, SizedIterable<T>, Predicate<java.lang.Object>, Composite, java.io.Serializable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>
Direct Known Subclasses:
ComplementSet, IntersectionSet

public class FilteredSet<T>
extends AbstractPredicateSet<T>
implements Composite, java.io.Serializable

A set that contains only those elements contained by both the given set and the given predicate. Note that size operations will take linear time.

See Also:
Serialized Form

Field Summary
protected  Predicate<? super T> _pred
           
protected  java.util.Set<? extends T> _set
           
 
Constructor Summary
FilteredSet(java.util.Set<? extends T> set, Predicate<? super T> predicate)
           
 
Method Summary
 int compositeHeight()
          Get the maximum path length from this node to a leaf.
 int compositeSize()
          Get the number of nodes in the tree rooted at this node.
 boolean contains(java.lang.Object o)
          Test whether the set contains an object.
 boolean containsAll(java.util.Collection<?> objs)
           
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 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.
 java.util.Iterator<T> iterator()
          Traversing the iterator is linear in the size of the original set.
 
Methods inherited from class edu.rice.cs.plt.collect.AbstractPredicateSet
size, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, remove, 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
add, addAll, clear, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

_set

protected final java.util.Set<? extends T> _set

_pred

protected final Predicate<? super T> _pred
Constructor Detail

FilteredSet

public FilteredSet(java.util.Set<? extends T> set,
                   Predicate<? super T> predicate)
Method Detail

compositeHeight

public int compositeHeight()
Description copied from interface: Composite
Get the maximum path length from this node to a leaf.

Specified by:
compositeHeight in interface Composite

compositeSize

public int compositeSize()
Description copied from interface: Composite
Get the number of nodes in the tree rooted at this node. Always 1 or greater.

Specified by:
compositeSize in interface Composite

contains

public boolean contains(java.lang.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 Predicate<java.lang.Object>
Specified by:
contains in interface java.util.Collection<T>
Specified by:
contains in interface java.util.Set<T>
Specified by:
contains in class AbstractPredicateSet<T>

containsAll

public boolean containsAll(java.util.Collection<?> objs)
Specified by:
containsAll in interface java.util.Collection<T>
Specified by:
containsAll in interface java.util.Set<T>
Overrides:
containsAll in class java.util.AbstractCollection<T>

iterator

public java.util.Iterator<T> iterator()
Traversing the iterator is linear in the size of the original set.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in interface java.util.Set<T>
Specified by:
iterator in class java.util.AbstractCollection<T>

isEmpty

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

Specified by:
isEmpty in interface SizedIterable<T>
Specified by:
isEmpty in interface java.util.Collection<T>
Specified by:
isEmpty in interface java.util.Set<T>
Overrides:
isEmpty in class AbstractPredicateSet<T>

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<T>

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<T>

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<T>