org.openide.util
Class WeakSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by org.openide.util.WeakSet<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

public class WeakSet<E>
extends java.util.AbstractSet<E>
implements java.lang.Cloneable, java.io.Serializable

Set which holds its members by using of WeakReferences. MT level: unsafe.

Note: as of JDK 6.0 (b51), you can instead use

 Set<T> s = Collections.newSetFromMap(new WeakHashMap<T, Boolean>());
 

Author:
Ales Novak
See Also:
Serialized Form

Constructor Summary
WeakSet()
          Constructs a new set.
WeakSet(java.util.Collection<? extends E> c)
          Constructs a new set containing the elements in the specified collection.
WeakSet(int initialCapacity)
          Constructs a new, empty set;
WeakSet(int initialCapacity, float loadFactor)
          Constructs a new, empty set;
 
Method Summary
 boolean add(E o)
          Adds the specified element to this set if it is not already present.
 void clear()
          Removes all of the elements from this set.
 java.lang.Object clone()
          Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.
 boolean contains(java.lang.Object o)
          Returns true if this set contains the specified element.
 boolean isEmpty()
          Returns true if this set contains no elements.
 java.util.Iterator<E> iterator()
          Returns an iterator over the elements in this set.
 boolean remove(java.lang.Object o)
          Removes the given element from this set if it is present.
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] array)
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, retainAll
 

Constructor Detail

WeakSet

public WeakSet()
Constructs a new set.


WeakSet

public WeakSet(java.util.Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.

Parameters:
c - a collection to add

WeakSet

public WeakSet(int initialCapacity)
Constructs a new, empty set;

Parameters:
initialCapacity - initial capacity

WeakSet

public WeakSet(int initialCapacity,
               float loadFactor)
Constructs a new, empty set;

Parameters:
initialCapacity - initial capacity
loadFactor - load factor
Method Detail

add

public boolean add(E o)
Adds the specified element to this set if it is not already present.

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>
Parameters:
o - an Object to add

clear

public void clear()
Removes all of the elements from this set.

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>

clone

public java.lang.Object clone()
Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.

Overrides:
clone in class java.lang.Object

contains

public boolean contains(java.lang.Object o)
Returns true if this set contains the specified element.

Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.Set<E>
Overrides:
contains in class java.util.AbstractCollection<E>
Parameters:
o - an Object to examine

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>
Overrides:
isEmpty in class java.util.AbstractCollection<E>

iterator

public java.util.Iterator<E> iterator()
Returns an iterator over the elements in this set.

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>

remove

public boolean remove(java.lang.Object o)
Removes the given element from this set if it is present.

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>
Parameters:
o - an Object to remove
Returns:
true if and only if the Object was successfuly removed.

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.Set<E>
Specified by:
size in class java.util.AbstractCollection<E>
Returns:
the number of elements in this set (its cardinality).

toArray

public <T> T[] toArray(T[] array)
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>

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>

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<E>