|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
org.deegree_impl.model.resources.WeakHashSet
A set of object hold by weak references. This class is used to implements caches.
Nested Class Summary | |
private class |
WeakHashSet.WeakElement
A weak reference to an element. |
Field Summary | |
private int |
count
Number of non-nul elements in table . |
private static long |
HOLD_TIME
Number of millisecond to wait before to rehash the table for reducing its size. |
private long |
lastRehashTime
The timestamp when table was last rehashed. |
private static float |
LOAD_FACTOR
Load factor. |
private static int |
MIN_CAPACITY
Minimal capacity for table . |
private static java.lang.ref.ReferenceQueue |
referenceQueue
List of reference collected by the garbage collector. |
private WeakHashSet.WeakElement[] |
table
Table of weak references. |
private static java.lang.Thread |
thread
Background thread removing references collected by the garbage collector. |
private int |
threshold
The next size value at which to resize. |
Constructor Summary | |
WeakHashSet()
Construct a WeakHashSet . |
Method Summary | |
boolean |
add(java.lang.Object obj)
Adds the specified element to this set if it is not already present. |
void |
clear()
Removes all of the elements from this set. |
boolean |
contains(java.lang.Object obj)
Returns true if this set contains the specified element. |
protected boolean |
equals(java.lang.Object object1,
java.lang.Object object2)
Check two objects for equality. |
java.lang.Object |
get(java.lang.Object obj)
Returns an object equals to the specified object, if present. |
protected int |
hashCode(java.lang.Object object)
Returns a hash code value for the specified object. |
java.lang.Object |
intern(java.lang.Object object)
Returns an object equals to obj if such an object already
exist in this WeakHashSet . |
void |
intern(java.lang.Object[] objects)
Iteratively call intern(Object) for an array of objects.
|
private java.lang.Object |
intern0(java.lang.Object obj)
Returns an object equals to obj if such an object already
exist in this WeakHashSet . |
java.util.Iterator |
iterator()
Returns an iterator over the elements contained in this collection. |
private void |
rehash(boolean augmentation)
Rehash table . |
private void |
remove(WeakHashSet.WeakElement toRemove)
Invoked by WeakHashSet.WeakElement when an element has been collected
by the garbage collector. |
int |
size()
Returns the count of element in this set. |
java.lang.Object[] |
toArray()
Returns a view of this set as an array. |
private boolean |
valid()
Check if this WeakHashSet is valid. |
Methods inherited from class java.util.AbstractSet |
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
addAll, containsAll, isEmpty, remove, retainAll, 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, remove, retainAll, toArray |
Field Detail |
private static final int MIN_CAPACITY
table
.
private static final float LOAD_FACTOR
table
must be rebuild.
private static final java.lang.ref.ReferenceQueue referenceQueue
table
.
private static final java.lang.Thread thread
private WeakHashSet.WeakElement[] table
private int count
table
.
private int threshold
table
.length*#loadFactor
.
private long lastRehashTime
table
was last rehashed. This information
is used to avoir too early table reduction. When the garbage collector
collected a lot of elements, we will wait at least 20 seconds before
rehashing table
in order to avoir to many cycles "reduce",
"expand", "reduce", "expand", etc.
private static final long HOLD_TIME
Constructor Detail |
public WeakHashSet()
WeakHashSet
.
Method Detail |
private void remove(WeakHashSet.WeakElement toRemove)
WeakHashSet.WeakElement
when an element has been collected
by the garbage collector. This method will remove the weak reference
from table
.
private void rehash(boolean augmentation)
table
.
augmentation
- true
if this method is invoked
for augmenting table
, or false
if
it is invoked for making the table smaller.public boolean contains(java.lang.Object obj)
true
if this set contains the specified element.
obj
- Object to be checked for containment in this set.
true
if this set contains the specified element.public final java.lang.Object get(java.lang.Object obj)
obj
,
then this method returns null
.
public boolean add(java.lang.Object obj)
false
.
obj
- Element to be added to this set.
true
if this set did not already
contain the specified element.private java.lang.Object intern0(java.lang.Object obj)
obj
if such an object already
exist in this WeakHashSet
. Otherwise, add obj
to this WeakHashSet
. This method is equivalents to the
following code:
if (object!=null) { final Object current=get(object); if (current!=null) return current; else add(object); } return object;
public final java.lang.Object intern(java.lang.Object object)
obj
if such an object already
exist in this WeakHashSet
. Otherwise, add obj
to this WeakHashSet
. This method is equivalents to the
following code:
if (object!=null) { final Object current=get(object); if (current!=null) return current; else add(object); } return object;
public final void intern(java.lang.Object[] objects)
intern(Object)
for an array of objects.
This method is equivalents to the following code:
for (int i=0; i
public final int size()
public final void clear()
private boolean valid()
WeakHashSet
is valid. This method counts the
number of elements and compare it to count
. If the check fails,
the number of elements is corrected (if we didn't, an // assertionError
would be thrown for every operations after the first error, which make
debugging more difficult). The set is otherwise unchanged, which should
help to get similar behaviour as if // assertions hasn't been turned on.
public final java.lang.Object[] toArray()
public java.util.Iterator iterator()
protected int hashCode(java.lang.Object object)
Object#hashCode
.
Override to compute hash code in a different way.
protected boolean equals(java.lang.Object object1, java.lang.Object object2)
hashCode(Object)
has been overriden.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |