edu.rice.cs.plt.collect
Class IterableSet<E>

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

public class IterableSet<E>
extends AbstractPredicateSet<E>
implements Composite, Serializable

A Set wrapping an Iterable. Allows iterables to be viewed as sets without creating a copy, and reflects subsequent changes made to the iterable. Does not support mutation. Since duplicate elements must be lazily skipped, most operations (including size() and contains) require a traversal of the iterable, and thus have relatively poor performance.

See Also:
Serialized Form

Constructor Summary
IterableSet(Iterable<? extends E> iter)
           
 
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(Object o)
          Test whether the set contains an object.
 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.
 Iterator<E> iterator()
          Must store all previously-seen elements in order to skip duplicates.
 
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, containsAll, 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, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

IterableSet

public IterableSet(Iterable<? extends E> iter)
Method Detail

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 Predicate<Object>
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Specified by:
contains in class AbstractPredicateSet<E>

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

iterator

public Iterator<E> iterator()
Must store all previously-seen elements in order to skip duplicates. As a result, requires space proportional to the number of next() invocations.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>

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

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

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

isEmpty

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

Specified by:
isEmpty in interface SizedIterable<E>
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractPredicateSet<E>