org.openide.util 8.15.1

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>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class WeakSet<E>
extends AbstractSet<E>
implements Cloneable, Serializable

This class provides storage functionality with Weak-referenced entries and new method putIfAbsent. Set implementation is backed by a hash table. It also provides method resize for changing capacity of internal hash table (can be used for reducing memory occupied by empty set which previously had big number of objects, but they were GCed) Access to set is not thread safe.

See Also:
putIfAbsent(Object), resize(int), Serialized Form

Constructor Summary
WeakSet()
          Constructs a new, empty WeakSet with the default initial capacity (16) and load factor (0.75).
WeakSet(Collection<? extends E> s)
          Constructs a new WeakSet with the same mappings as the specified map.
WeakSet(int initialCapacity)
          Constructs a new, empty WeakSet with the given initial capacity and the default load factor (0.75).
WeakSet(int initialCapacity, float loadFactor)
          Constructs a new, empty WeakSet with the given initial capacity and the given load factor.
 
Method Summary
 boolean add(E e)
           
 void clear()
           
 Object clone()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 int hashCode()
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 E putIfAbsent(E e)
          Put object in this set if equal one is not yet in set.
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 void resize(int newCapacity)
          compact set if it is empty by setting new capacity
 boolean retainAll(Collection<?> c)
           
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
           
 
Methods inherited from class java.util.AbstractCollection
addAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll
 

Constructor Detail

WeakSet

public WeakSet(int initialCapacity,
               float loadFactor)
Constructs a new, empty WeakSet with the given initial capacity and the given load factor.

Parameters:
initialCapacity - The initial capacity of the WeakSet
loadFactor - The load factor of the WeakSet
Throws:
IllegalArgumentException - if the initial capacity is negative, or if the load factor is nonpositive.

WeakSet

public WeakSet(int initialCapacity)
Constructs a new, empty WeakSet with the given initial capacity and the default load factor (0.75).

Parameters:
initialCapacity - The initial capacity of the WeakSet
Throws:
IllegalArgumentException - if the initial capacity is negative

WeakSet

public WeakSet()
Constructs a new, empty WeakSet with the default initial capacity (16) and load factor (0.75).


WeakSet

public WeakSet(Collection<? extends E> s)
Constructs a new WeakSet with the same mappings as the specified map. The WeakSet is created with the default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.

Parameters:
s - the map whose mappings are to be placed in this map
Throws:
NullPointerException - if the specified map is null
Method Detail

clear

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

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractCollection<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class AbstractCollection<E>

remove

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

resize

public void resize(int newCapacity)
compact set if it is empty by setting new capacity

Parameters:
newCapacity - new capacity
Since:
8.11

add

public boolean add(E e)
Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class AbstractCollection<E>
See Also:
putIfAbsent(E)

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>

toArray

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

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface Set<E>
Overrides:
toArray in class AbstractCollection<E>

toString

public String toString()
Overrides:
toString in class AbstractCollection<E>

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface Set<E>
Overrides:
hashCode in class AbstractSet<E>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Specified by:
equals in interface Set<E>
Overrides:
equals in class AbstractSet<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface Set<E>
Overrides:
containsAll in class AbstractCollection<E>

removeAll

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

retainAll

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

putIfAbsent

public E putIfAbsent(E e)
Put object in this set if equal one is not yet in set. Returns previous set entry if equal object is already in set.
  WeakSet<MyClass> set = new WeakSet<MyClass>();
  ...
  MyClass sharedValue = set.putIfAbsent(new MyClass("abc));
 

Parameters:
e - object to put in set.
Returns:
the previous set entry equals with e, or passed object e if there were not entry in set.
Since:
8.11

clone

public Object clone()
Overrides:
clone in class Object

org.openide.util 8.15.1

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.