|
J avolution v5.5 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.util.FastCollection<E>
javolution.util.FastSet<E>
public class FastSet<E>
This class represents a set collection backed by a FastMap
;
smooth capacity increase and no rehashing ever performed.
FastSet
, as for any FastCollection
sub-class, supports
thread-safe fast iterations without using iterators. For example:
for (FastSet.Record r = set.head(), end = set.tail(); (r = r.getNext()) != end;) {
Object value = set.valueOf(r);
}
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javolution.util.FastCollection |
---|
FastCollection.Record |
Constructor Summary | |
---|---|
FastSet()
Creates a set of small initial capacity. |
|
FastSet(int capacity)
Creates a set of specified initial capacity; unless the set size reaches the specified capacity, operations on this set will not allocate memory (no lazy object creation). |
|
FastSet(java.util.Set<? extends E> elements)
Creates a set containing the specified elements, in the order they are returned by the set iterator. |
|
FastSet(java.lang.String id)
Creates a persistent set associated to the specified unique identifier (convenience method). |
Method Summary | ||
---|---|---|
boolean |
add(E value)
Adds the specified value to this set if it is not already present. |
|
void |
clear()
Removes all of the values from this collection (optional operation). |
|
boolean |
contains(java.lang.Object o)
Indicates if this collection contains the specified value. |
|
void |
delete(FastCollection.Record record)
Deletes the specified record from this collection. |
|
FastComparator<? super E> |
getValueComparator()
Returns the value comparator for this collection (default FastComparator.DEFAULT ). |
|
FastCollection.Record |
head()
Returns the head record of this collection; it is the record such as head().getNext() holds the first collection value. |
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this set (allocated on the stack when executed in a StackContext ). |
|
static
|
newInstance()
Returns a new, preallocated or recycled set instance
(on the stack when executing in a StackContext ). |
|
static void |
recycle(FastSet instance)
Recycles a set instance immediately
(on the stack when executing in a StackContext ). |
|
boolean |
remove(java.lang.Object o)
Removes the first occurrence in this collection of the specified value (optional operation). |
|
void |
reset()
Resets the internal state of this object to its default values. |
|
FastSet<E> |
setValueComparator(FastComparator<? super E> comparator)
Sets the comparator to use for value equality. |
|
int |
size()
Returns the number of elements in this set (its cardinality). |
|
FastCollection.Record |
tail()
Returns the tail record of this collection; it is the record such as tail().getPrevious() holds the last collection value. |
|
java.util.Set<E> |
unmodifiable()
Returns the unmodifiable view associated to this collection. |
|
E |
valueOf(FastCollection.Record record)
Returns the collection value for the specified record. |
Methods inherited from class javolution.util.FastCollection |
---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, shared, toArray, toArray, toString, toText |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
Constructor Detail |
---|
public FastSet()
public FastSet(java.lang.String id)
id
- the unique identifier for this map.
java.lang.IllegalArgumentException
- if the identifier is not unique.PersistentContext.Reference
public FastSet(int capacity)
capacity
- the initial capacity.public FastSet(java.util.Set<? extends E> elements)
elements
- the elements to be placed into this fast set.Method Detail |
---|
public static <E> FastSet<E> newInstance()
recycled
set instance
(on the stack when executing in a StackContext
).
public static void recycle(FastSet instance)
instance
immediately
(on the stack when executing in a StackContext
).
public final int size()
size
in interface java.util.Collection<E>
size
in interface java.util.Set<E>
size
in class FastCollection<E>
public final boolean add(E value)
add
in interface java.util.Collection<E>
add
in interface java.util.Set<E>
add
in class FastCollection<E>
value
- the value to be added to this set.
true
if this set did not already contain the
specified element.
java.lang.NullPointerException
- if the value is null
.public java.util.Iterator<E> iterator()
StackContext
).
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.Set<E>
iterator
in class FastCollection<E>
public java.util.Set<E> unmodifiable()
FastCollection
UnsupportedOperationException
being thrown.
unmodifiable
in class FastCollection<E>
public final void clear()
FastCollection
clear
in interface java.util.Collection<E>
clear
in interface java.util.Set<E>
clear
in class FastCollection<E>
public final boolean contains(java.lang.Object o)
FastCollection
contains
in interface java.util.Collection<E>
contains
in interface java.util.Set<E>
contains
in class FastCollection<E>
o
- the value whose presence in this collection
is to be tested.
true
if this collection contains the specified
value;false
otherwise.public final boolean remove(java.lang.Object o)
FastCollection
remove
in interface java.util.Collection<E>
remove
in interface java.util.Set<E>
remove
in class FastCollection<E>
o
- the value to be removed from this collection.
true
if this collection contained the specified
value; false
otherwise.public FastSet<E> setValueComparator(FastComparator<? super E> comparator)
comparator
- the value comparator.
this
public FastComparator<? super E> getValueComparator()
FastCollection
FastComparator.DEFAULT
).
getValueComparator
in class FastCollection<E>
public void reset()
Reusable
reset
in interface Reusable
public final FastCollection.Record head()
FastCollection
head().getNext()
holds the first collection value.
head
in class FastCollection<E>
public final FastCollection.Record tail()
FastCollection
tail().getPrevious()
holds the last collection value.
tail
in class FastCollection<E>
public final E valueOf(FastCollection.Record record)
FastCollection
valueOf
in class FastCollection<E>
record
- the record whose current value is returned.
public final void delete(FastCollection.Record record)
FastCollection
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).
delete
in class FastCollection<E>
record
- the record to be removed.
|
J avolution v5.5 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |