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 .equals()
, given that the intent of this class
is to track actual Object instances. However, the methods removeAll(Collection)
and retainAll(Collection)
use the
contains()
method of the argument
Collection
.
Constructor and Description |
---|
ReapableCollection()
Creates a new
ReapableCollection using the
default Reaper . |
ReapableCollection(Reaper reaper)
Creates a new
ReapableCollection with the
specified Reaper . |
Modifier and Type | Method and Description |
---|---|
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()
Informs this
Reapable that it has at least one
reference which has been reclaimed. |
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() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public ReapableCollection()
ReapableCollection
using the
default Reaper
.public int size()
size
in interface Collection
public boolean isEmpty()
true
if this collection contains no
elements; a false
return value doesn't signify
anything meaningful.isEmpty
in interface Collection
public boolean add(Object object)
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.add
in interface Collection
public boolean remove(Object object)
true
is returned.remove
in interface Collection
public boolean contains(Object object)
contains
in interface Collection
public Iterator iterator()
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!iterator
in interface Iterable
iterator
in interface Collection
public void clear()
clear
in interface Collection
public boolean addAll(Collection collection)
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.addAll
in interface Collection
public boolean removeAll(Collection collection)
contains()
method of the argument collection.removeAll
in interface Collection
public boolean retainAll(Collection collection)
contains()
method of the argument collection.retainAll
in interface Collection
public boolean containsAll(Collection collection)
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.containsAll
in interface Collection
public Object[] toArray()
toArray
in interface Collection
public Object[] toArray(Object[] array)
toArray
in interface Collection
See the Plexus project home, hosted by SourceForge.
Copyright ? 1994-2006, by Phoenix Software Technologists, Inc. and others. All Rights Reserved. Use is subject to license terms.