com.phoenixst.collections
public class ReapableCollection extends Object implements Collection, Reapable
Collection
. At any time, elements of an
instance of this class may be removed if there are no longer any
references to them outside of the instance. In particular, many
methods like size and isEmpty may not give
accurate answers, and that information is immediately out of date.
Instances of this class are synchronized where necessary, but the
user is required to synchronize externally during
any iteration.
This Collection
does not permit null
elements, nor will it allow itself to be added.
Most of the methods in this class use reference equality rather
than Since: 1.0 Version: $Revision: 1.14 $ .equals()
, given that the intent of this class
is to track actual Object instances. However, the methods removeAll and retainAll use the
contains()
method of the argument
Collection
.
Constructor Summary | |
---|---|
ReapableCollection()
Creates a new ReapableCollection using the
default Reaper. | |
ReapableCollection(Reaper reaper)
Creates a new ReapableCollection with the
specified Reaper. |
Method Summary | |
---|---|
boolean | add(Object object)
Adds the specified element to this collection, wrapping the
element with a Reference created by the Reaper used to construct this collection. |
boolean | addAll(Collection collection)
Adds all of the elements in the specified collection to this
collection, wrapping each element with a
Reference created by the Reaper used to
construct this collection. |
void | clear() |
boolean | contains(Object object)
Returns true if this collection contains a Reference for the
specified object. |
boolean | containsAll(Collection collection)
Returns true if this collection contains
References for all of the elements in the specified
collection. |
boolean | isEmpty()
Returns true if this collection contains no
elements; a false return value doesn't signify
anything meaningful. |
Iterator | iterator()
Returns an Iterator over the elements in this
collection, which are the referents of uncleared References.
|
void | reap() |
boolean | remove(Object object)
If this collection contains a Reference for the specified
object, the first such Reference found is cleared and
true is returned. |
boolean | removeAll(Collection collection)
Removes all this collection's elements that are also contained
in the specified collection. |
boolean | retainAll(Collection collection)
Retains only this collection's elements that are also
contained in the specified collection. |
int | size()
Returns at most the number of uncleared References currently
in this collection. |
Object[] | toArray()
Returns an array containing all of the elements in this
collection. |
Object[] | toArray(Object[] array)
Returns an array containing all of the elements in this
collection. |
String | toString() |
ReapableCollection
using the
default Reaper.ReapableCollection
with the
specified Reaper. The Reaper
must not
create PhantomReferences
.Reference
created by the Reaper used to construct this collection. This
Collection
does not permit null
elements, nor will it allow itself to be added.Reference
created by the Reaper used to
construct this collection. This Collection
does
not permit null
elements, nor will it allow
itself to be added. If the argument collection is this
collection, nothing happens and false
is
returned.true
if this collection contains
References for all of the elements in the specified
collection. This implementation is O(n*m), where n
is the size of this collection and m is the cost of
iterating over the argument collection.true
if this collection contains no
elements; a false
return value doesn't signify
anything meaningful.Iterator
over the elements in this
collection, which are the referents of uncleared References.
The user must externally synchronize the
Iterator
returned by this method!true
is returned.contains()
method of the argument collection.contains()
method of the argument collection.