org.openide.util 6.8.22

org.openide.util
Class WeakSet

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

public class WeakSet
extends AbstractSet
implements Cloneable, 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>());
 

See Also:
Serialized Form

Constructor Summary
WeakSet()
          Constructs a new set.
WeakSet(Collection 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(Object o)
          Adds the specified element to this set if it is not already present.
 void clear()
          Removes all of the elements from this set.
 Object clone()
          Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.
 boolean contains(Object o)
          Returns true if this set contains the specified element.
 boolean isEmpty()
          Returns true if this set contains no elements.
 Iterator iterator()
          Returns an iterator over the elements in this set.
 boolean remove(Object o)
          Removes the given element from this set if it is present.
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] array)
           
 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(Collection 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(Object o)
Adds the specified element to this set if it is not already present.

Specified by:
add in interface Collection
Specified by:
add in interface Set
Overrides:
add in class AbstractCollection
Parameters:
o - an Object to add

clear

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

Specified by:
clear in interface Collection
Specified by:
clear in interface Set
Overrides:
clear in class AbstractCollection

clone

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

Overrides:
clone in class Object

contains

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

Specified by:
contains in interface Collection
Specified by:
contains in interface Set
Overrides:
contains in class AbstractCollection
Parameters:
o - an Object to examine

isEmpty

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

Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface Set
Overrides:
isEmpty in class AbstractCollection

iterator

public Iterator iterator()
Returns an iterator over the elements in this set.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set
Specified by:
iterator in class AbstractCollection

remove

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

Specified by:
remove in interface Collection
Specified by:
remove in interface Set
Overrides:
remove in class AbstractCollection
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 Collection
Specified by:
size in interface Set
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this set (its cardinality).

toArray

public Object[] toArray(Object[] array)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface Set
Overrides:
toArray in class AbstractCollection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface Set
Overrides:
toArray in class AbstractCollection

toString

public String toString()
Overrides:
toString in class AbstractCollection

org.openide.util 6.8.22

Built on July 11 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.