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

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by edu.rice.cs.plt.collect.WeakHashSet<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

public class WeakHashSet<T>
extends AbstractSet<T>

A Set implementation that has similar semantics to WeakHashMap. The elements in this set are weakly held, so when the element is not longer strongly reachable, the element will be removed from the set.


Constructor Summary
WeakHashSet()
          Constructs a new WeakHashSet.
 
Method Summary
 boolean add(T item)
          Adds the given item to the set.
 void clear()
          Removes all items from the set.
 boolean contains(Object o)
          Returns a boolean value indicating whether the given object is a member of the set.
 Iterator<T> iterator()
          Returns an iterator for the elements in the set.
 boolean remove(Object o)
          Removes the given item from the set, if it was in the set.
 int size()
          Returns the number of elements in the WeakHashSet.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, 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, isEmpty, retainAll, toArray, toArray
 

Constructor Detail

WeakHashSet

public WeakHashSet()
Constructs a new WeakHashSet.

Method Detail

size

public int size()
Returns the number of elements in the WeakHashSet. Initially, the WeakHashSet is empty, so size returns 0.

Specified by:
size in interface Collection<T>
Specified by:
size in interface Set<T>
Specified by:
size in class AbstractCollection<T>
Returns:
The number of elements in the set

add

public boolean add(T item)
Adds the given item to the set. If the item is already in the set, it will not be added again.

Specified by:
add in interface Collection<T>
Specified by:
add in interface Set<T>
Overrides:
add in class AbstractCollection<T>
Parameters:
item - The item to add
Returns:
true if the item was not already in the set, false otherwise

clear

public void clear()
Removes all items from the set. After calling clear, size will return 0.

Specified by:
clear in interface Collection<T>
Specified by:
clear in interface Set<T>
Overrides:
clear in class AbstractCollection<T>

contains

public boolean contains(Object o)
Returns a boolean value indicating whether the given object is a member of the set.

Specified by:
contains in interface Collection<T>
Specified by:
contains in interface Set<T>
Overrides:
contains in class AbstractCollection<T>
Parameters:
o - The object to look for
Returns:
true if the object exists in the set, false otherwise

remove

public boolean remove(Object o)
Removes the given item from the set, if it was in the set.

Specified by:
remove in interface Collection<T>
Specified by:
remove in interface Set<T>
Overrides:
remove in class AbstractCollection<T>
Parameters:
o - The item to remove
Returns:
true if the item was in the set and has been removed, otherwise (when the item was not in the set) false

iterator

public Iterator<T> iterator()
Returns an iterator for the elements in the set. The iterator is not guaranteed to be backed by the live set. However, not of the elements will be null. The remove operation is implemented.

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in interface Set<T>
Specified by:
iterator in class AbstractCollection<T>
Returns:
An iterator for the elements of the set