public class WeakSet extends Object
A WeakSet can also be used as a SoftSet by using the constructor WeakSet(boolean useSoftReferences).
A WeakSet can also be used as a re-usable weak/soft reference - but one that does not allow for the use of queues. To use it in this way use only the get() and set() methods.
A WeakSet/SoftSet is a very good way of re-using resources in a memory efficient way, especially on a native Eve VM because it is backed by a native implementation that does not use Java Objects.
Constructor and Description |
---|
WeakSet() |
WeakSet(boolean useSoftReferences) |
Modifier and Type | Method and Description |
---|---|
void |
add(Object what)
This adds a reference to the set.
|
void |
clear()
This removes all references in the set.
|
boolean |
contains(Object who) |
int |
count()
This counts the number of live references.
|
Iterator |
entries()
Get an Iterator to go through all the entries.
|
Object |
find(ObjectFinder f)
This finds an object int the reference list using the ObjectFinder.
|
Object |
get()
Return the first live value but leave it in the set.
|
Object[] |
getRefs()
Place and return all live references into a new Object array.
|
int |
getRefs(Vector destination)
Add all live references into the destination Vector, without clearing the vector.
|
boolean |
isEmpty()
True to indicate that there are definitely no entries.
|
void |
remove(Object what)
This removes a reference from the set if it is in it.
|
Object |
set(Object obj)
This is used to set the WeakSet to contain a single value.
|
Object |
takeRef()
Remove and return a single live reference from the set,
or return null if no live references could be found.
|
public void add(Object what)
public void remove(Object what)
public void clear()
public int getRefs(Vector destination)
destination
- a non-null destination Vector.public Object find(ObjectFinder f)
public boolean contains(Object who)
public int count()
public boolean isEmpty()
public Iterator entries()
Note that this is a memory inefficient way of doing things.
public Object[] getRefs()
public Object takeRef()
public Object set(Object obj)
obj
- the Object to add to the WeakSet.public Object get()