|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.drools.util.FastCollection
public abstract class FastCollection
This class represents collections which can quickly be iterated over
(forward or backward) in a thread-safe manner without creating new
objects and without using iterators
. For example:[code]
boolean search(Object item, FastCollection c) {
for (Record r = c.head(), end = c.tail(); (r = r.getNext()) != end;) {
if (item.equals(c.valueOf(r))) return true;
}
return false;
}[/code]
Iterations are thread-safe as long as the record
sequence
iterated over is not structurally modified by another thread
(objects can safely be append/prepend during iterations but not
inserted/removed).
Users may provide a read-only view of any FastCollection
instance using the unmodifiable()
method (the view is
thread-safe if iterations are thread-safe). For example:[code]
public class Polynomial {
private final FastTable
Finally, FastCollection
may use custom comparators
for element equality or ordering if the collection is
ordered (e.g. FastTree
).
Nested Class Summary | |
---|---|
static interface |
FastCollection.Record
This interface represents the collection records which can directly be iterated over. |
Constructor Summary | |
---|---|
protected |
FastCollection()
Default constructor. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object value)
Appends the specified value to the end of this collection (optional operation). |
boolean |
addAll(java.util.Collection c)
Appends all of the values in the specified collection to the end of this collection, in the order that they are returned by the specified collection's iterator or the node order if the specified collection is a FastCollection . |
void |
clear()
Removes all of the values from this collection (optional operation). |
boolean |
contains(java.lang.Object value)
Indicates if this collection contains the specified value. |
boolean |
containsAll(java.util.Collection c)
Indicates if this collection contains all of the values of the specified collection. |
abstract void |
delete(FastCollection.Record record)
Deletes the specified record from this collection. |
boolean |
equals(java.lang.Object obj)
Compares the specified object with this collection for equality. |
FastComparator |
getValueComparator()
Returns the value comparator for this collection (default FastComparator.DEFAULT ). |
int |
hashCode()
Returns the hash code for this collection (independent from the collection order; unless this collection is a list instance). |
abstract FastCollection.Record |
head()
Returns the head record of this collection; it is the record such as head().getNext() holds the first collection value. |
boolean |
isEmpty()
Indicates if this collection is empty. |
java.util.Iterator |
iterator()
Returns an iterator over the elements in this collection (allocated on the stack when executed in a PoolContext ). |
boolean |
remove(java.lang.Object value)
Removes the first occurrence in this collection of the specified value (optional operation). |
boolean |
removeAll(java.util.Collection c)
Removes from this collection all the values that are contained in the specified collection. |
boolean |
retainAll(java.util.Collection c)
Retains only the values in this collection that are contained in the specified collection. |
FastCollection |
setValueComparator(FastComparator comparator)
Sets the comparator to use for value equality or ordering if the collection is ordered (e.g. |
abstract int |
size()
Returns the number of values in this collection. |
abstract FastCollection.Record |
tail()
Returns the tail record of this collection; it is the record such as tail().getPrevious() holds the last collection value. |
java.lang.Object[] |
toArray()
Returns a new array allocated on the heap containing all of the values in this collection in proper sequence. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Fills the specified array with the values of this collection in the proper sequence. |
java.lang.String |
toString()
Returns the textual representation of this collection. |
java.util.Collection |
unmodifiable()
Returns the unmodifiable view associated to this collection. |
abstract java.lang.Object |
valueOf(FastCollection.Record record)
Returns the collection value for the specified record. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected FastCollection()
Method Detail |
---|
public abstract int size()
size
in interface java.util.Collection
public abstract FastCollection.Record head()
head().getNext()
holds the first collection value.
public abstract FastCollection.Record tail()
tail().getPrevious()
holds the last collection value.
public abstract java.lang.Object valueOf(FastCollection.Record record)
record
- the record whose current value is returned.
public abstract void delete(FastCollection.Record record)
Implementation must ensure that removing a record from the collection does not affect in any way the records preceding the record being removed (it might affect the next records though, e.g. in a list collection, the indices of the subsequent records will change).
record
- the record to be removed.
java.lang.UnsupportedOperationException
- if not supported.public java.util.Collection unmodifiable()
UnsupportedOperationException
being thrown. The view is
typically part of the collection itself (created only once)
and also an instance of FastCollection
supporting direct
iterations.
public java.util.Iterator iterator()
PoolContext
).
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
public FastCollection setValueComparator(FastComparator comparator)
FastTree
).
comparator
- the value comparator.
this
public FastComparator getValueComparator()
FastComparator.DEFAULT
).
public boolean add(java.lang.Object value)
Note: This default implementation always throws
UnsupportedOperationException
.
add
in interface java.util.Collection
value
- the value to be appended to this collection.
true
(as per the general contract of the
Collection.add
method).
java.lang.UnsupportedOperationException
- if not supported.public boolean remove(java.lang.Object value)
remove
in interface java.util.Collection
value
- the value to be removed from this collection.
true
if this collection contained the specified
value; false
otherwise.
java.lang.UnsupportedOperationException
- if not supported.public void clear()
clear
in interface java.util.Collection
java.lang.UnsupportedOperationException
- if not supported.public final boolean isEmpty()
isEmpty
in interface java.util.Collection
true
if this collection contains no value;
false
otherwise.public boolean contains(java.lang.Object value)
contains
in interface java.util.Collection
value
- the value whose presence in this collection
is to be tested.
true
if this collection contains the specified
value;false
otherwise.public boolean addAll(java.util.Collection c)
FastCollection
.
addAll
in interface java.util.Collection
c
- collection whose values are to be added to this collection.
true
if this collection changed as a result of
the call; false
otherwise.public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
c
- collection to be checked for containment in this collection.
true
if this collection contains all of the values
of the specified collection; false
otherwise.public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
c
- collection that defines which values will be removed from
this collection.
true
if this collection changed as a result of
the call; false
otherwise.public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
c
- collection that defines which values this set will retain.
true
if this collection changed as a result of
the call; false
otherwise.public java.lang.Object[] toArray()
Note: To avoid heap allocation toArray(Object[])
is
recommended.
toArray
in interface java.util.Collection
toArray(new Object[size()])
public java.lang.Object[] toArray(java.lang.Object[] array)
Note: Unlike standard Collection, this method does not try to resize the array using reflection (which might not be supported) if the array is too small. UnsupportedOperationException is raised if the specified array is too small for this collection.
toArray
in interface java.util.Collection
array
- the array into which the values of this collection
are to be stored.
java.lang.UnsupportedOperationException
- if array.length < size()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
true
if and only both collection contains the same values
regardless of the order; unless this collection is a list instance
in which case both collection must be list with the same order.
equals
in interface java.util.Collection
equals
in class java.lang.Object
obj
- the object to be compared for equality with this collection.
true
if the specified object is equal to this
collection; false
otherwise.public int hashCode()
hashCode
in interface java.util.Collection
hashCode
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |