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

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<E>
                  extended by edu.rice.cs.plt.collect.IntersectionSet<E>
All Implemented Interfaces:
PredicateSet<E>, SizedIterable<E>, Predicate<java.lang.Object>, Composite, java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

public class IntersectionSet<E>
extends FilteredSet<E>

The intersection of two sets, lazily constructed and updated dynamically. This improves on a general FilteredSet by taking advantage of the fact that the predicate used for filtering is also a set.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.rice.cs.plt.collect.FilteredSet
_pred, _set
 
Constructor Summary
IntersectionSet(java.util.Set<?> set1, java.util.Set<? extends E> set2)
          To guarantee that the intersection is a set of E, only one of the arguments must be a set of Es.
 
Method Summary
 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.
 
Methods inherited from class edu.rice.cs.plt.collect.FilteredSet
compositeHeight, compositeSize, contains, containsAll, iterator
 
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
 

Constructor Detail

IntersectionSet

public IntersectionSet(java.util.Set<?> set1,
                       java.util.Set<? extends E> set2)
To guarantee that the intersection is a set of E, only one of the arguments must be a set of Es. We arbitrarily choose set2. For best performance of FilteredSet.iterator(), AbstractPredicateSet.size(), and isEmpty(), set2 should be the smaller of the two sets (this is not handled automatically because calculating sizes may be expensive).

Method Detail

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>
Overrides:
isInfinite in class FilteredSet<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>
Overrides:
hasFixedSize in class FilteredSet<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>
Overrides:
isStatic in class FilteredSet<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 java.util.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>
Overrides:
isEmpty in class FilteredSet<E>