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

public class SingletonSet<E>
extends AbstractPredicateSet<E>
implements java.io.Serializable

An immutable PredicateSet with a single element.

See Also:
Serialized Form

Constructor Summary
SingletonSet(E elt)
           
 
Method Summary
 boolean add(E o)
           
 boolean addAll(java.util.Collection<? extends E> c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
          Test whether the set contains an object.
static
<T> Lambda<T,SingletonSet<T>>
factory()
           
 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<E> iterator()
           
static
<E> SingletonSet<E>
make(E element)
          Call the constructor (allows E to be inferred)
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection<?> c)
           
 int size()
          Returns size(Integer.MAX_VALUE).
 int size(int bound)
          Computes the size by traversing the iterator (requires linear time).
 java.lang.Object[] toArray()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, toArray
 

Constructor Detail

SingletonSet

public SingletonSet(E elt)
Method Detail

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<E>
Specified by:
contains in interface java.util.Set<E>
Specified by:
contains in class AbstractPredicateSet<E>

iterator

public java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.Set<E>
Specified by:
iterator in class java.util.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>

size

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

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

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<E>
Overrides:
size in class AbstractPredicateSet<E>
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<E>
Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>
Overrides:
isEmpty in class AbstractPredicateSet<E>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>
Overrides:
toArray in class java.util.AbstractCollection<E>

add

public boolean add(E o)
Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.Set<E>
Overrides:
add in class java.util.AbstractCollection<E>

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.Set<E>
Overrides:
addAll in class java.util.AbstractCollection<E>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.Set<E>
Overrides:
remove in class java.util.AbstractCollection<E>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.Set<E>
Overrides:
retainAll in class java.util.AbstractCollection<E>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.Set<E>
Overrides:
removeAll in class java.util.AbstractSet<E>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.Set<E>
Overrides:
clear in class java.util.AbstractCollection<E>

make

public static <E> SingletonSet<E> make(E element)
Call the constructor (allows E to be inferred)


factory

public static <T> Lambda<T,SingletonSet<T>> factory()