| |
|
| java.lang.Object javolution.util.FastCollection javolution.util.FastList
All known Subclasses: j2me.util.LinkedList,
FastList | public class FastList extends FastCollection implements List,Reusable(Code) | | This class represents a linked list with real-time behavior;
smooth capacity increase and no memory allocation as long as the
list size does not exceed its initial capacity.
All of the operations perform as could be expected for a doubly-linked
list (
FastList.addLast insertion /
FastList.removeLast() deletion at the end of the list are nonetheless the fastest).
Operations that index into the list will traverse the list from
the begining or the end whichever is closer to the specified index.
Random access operations can be significantly accelerated by
FastList.subList splitting the list into smaller ones.
FastList (as for any
FastCollection sub-class) supports
thread-safe, fast iterations without using iterators.[code]
FastList list = new FastList();
for (FastList.Node n = list.head(), end = list.tail(); (n = n.getNext()) != end;) {
String value = n.getValue(); // No typecast necessary.
}[/code]
FastList are fully
Reusable reusable , they maintain
internal pools of
Node nodes objects. When a node is removed
from its list, it is automatically restored to its pool.
Custom list implementations may override the
FastList.newNode method
in order to return their own
Node implementation (with
additional fields for example).
author: Jean-Marie Dautelle version: 4.2, December 18, 2006 |
Inner Class :public static class Node implements Record,Serializable | |
Constructor Summary | |
public | FastList() Creates a list of small initial capacity. | public | FastList(String id) Creates a persistent list associated to the specified unique identifier
(convenience method). | public | FastList(int capacity) Creates a list of specified initial capacity; unless the list size
reaches the specified capacity, operations on this list will not allocate
memory (no lazy object creation). | public | FastList(Collection values) Creates a list containing the specified values, in the order they
are returned by the collection's iterator. |
Method Summary | |
final public boolean | add(Object value) Appends the specified value to the end of this list
(equivalent to
FastList.addLast ).
Parameters: value - the value to be appended to this list. | final public void | add(int index, Object value) Inserts the specified value at the specified position in this list. | final public boolean | addAll(int index, Collection values) Inserts all of the values in the specified collection into this
list at the specified position. | final public void | addBefore(Node next, Object value) Inserts the specified value before the specified Node.
Parameters: next - the Node before which this value is inserted. Parameters: value - the value to be inserted. | final public void | addFirst(Object value) Inserts the specified value at the beginning of this list. | public void | addLast(Object value) Appends the specified value to the end of this list (fast). | final public void | clear() | final public boolean | contains(Object value) | final public void | delete(Record record) | final public Object | get(int index) Returns the value at the specified position in this list.
Parameters: index - the index of value to return. | final public Object | getFirst() Returns the first value of this list. | final public Object | getLast() Returns the last value of this list. | public FastComparator | getValueComparator() | public int | hashCode() Returns the hash code value for this list. | final public Record | head() | final public int | indexOf(Object value) Returns the index in this list of the first occurrence of the specified
value, or -1 if this list does not contain this value.
Parameters: value - the value to search for. | public Iterator | iterator() Returns a simple iterator over the elements in this list
(allocated on the stack when executed in a
javolution.context.StackContext StackContext ). | final public int | lastIndexOf(Object value) Returns the index in this list of the last occurrence of the specified
value, or -1 if this list does not contain this value.
Parameters: value - the value to search for. | public ListIterator | listIterator() Returns a list iterator over the elements in this list
(allocated on the stack when executed in a
javolution.context.StackContext StackContext ). | public ListIterator | listIterator(int index) Returns a list iterator from the specified position
(allocated on the stack when executed in a
javolution.context.StackContext StackContext ).
The specified index indicates the first value that would be returned by
an initial call to the next method. | public static FastList | newInstance() Returns a new, preallocated or
FastList.recycle recycled list instance
(on the stack when executing in a
javolution.context.StackContextStackContext ). | protected Node | newNode() Returns a new node for this list; this method can be overriden by
custom list implementation. | public static void | recycle(FastList instance) Recycles a list
FastList.newInstance() instance immediately
(on the stack when executing in a
javolution.context.StackContextStackContext ). | final public Object | remove(int index) Removes the value at the specified position in this list.
Shifts any subsequent values to the left (subtracts one
from their indices). | final public Object | removeFirst() Removes and returns the first value of this list. | final public Object | removeLast() Removes and returns the last value of this list (fast). | public void | reset() | final public Object | set(int index, Object value) Replaces the value at the specified position in this list with the
specified value.
Parameters: index - the index of value to replace. Parameters: value - the value to be stored at the specified position. | public FastList | setValueComparator(FastComparator comparator) Sets the comparator to use for value equality.
Parameters: comparator - the value comparator. | final public int | size() | final public List | subList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specified
indexes (allocated from the "stack" when executing in a
javolution.context.StackContext StackContext ).
If the specified indexes are equal, the returned list is empty. | final public Record | tail() | public Collection | unmodifiable() | final public Object | valueOf(Record record) |
ONE_VOLATILE | static volatile int ONE_VOLATILE(Code) | | |
FastList | public FastList()(Code) | | Creates a list of small initial capacity.
|
FastList | public FastList(String id)(Code) | | Creates a persistent list associated to the specified unique identifier
(convenience method).
Parameters: id - the unique identifier for this map. throws: IllegalArgumentException - if the identifier is not unique. See Also: javolution.context.PersistentContext.Reference |
FastList | public FastList(int capacity)(Code) | | Creates a list of specified initial capacity; unless the list size
reaches the specified capacity, operations on this list will not allocate
memory (no lazy object creation).
Parameters: capacity - the initial capacity. |
FastList | public FastList(Collection values)(Code) | | Creates a list containing the specified values, in the order they
are returned by the collection's iterator.
Parameters: values - the values to be placed into this list. |
add | final public boolean add(Object value)(Code) | | Appends the specified value to the end of this list
(equivalent to
FastList.addLast ).
Parameters: value - the value to be appended to this list. true (as per the general contract of theCollection.add method). |
add | final public void add(int index, Object value)(Code) | | Inserts the specified value at the specified position in this list.
Shifts the value currently at that position
(if any) and any subsequent values to the right (adds one to their
indices).
Parameters: index - the index at which the specified value is to be inserted. Parameters: value - the value to be inserted. throws: IndexOutOfBoundsException - if (index < 0) || (index > size()) |
addAll | final public boolean addAll(int index, Collection values)(Code) | | Inserts all of the values in the specified collection into this
list at the specified position. Shifts the value currently at that
position (if any) and any subsequent values to the right
(increases their indices).
Parameters: index - the index at which to insert first value from the specifiedcollection. Parameters: values - the values to be inserted into this list. true if this list changed as a result of the call;false otherwise. throws: IndexOutOfBoundsException - if (index < 0) || (index > size()) |
addBefore | final public void addBefore(Node next, Object value)(Code) | | Inserts the specified value before the specified Node.
Parameters: next - the Node before which this value is inserted. Parameters: value - the value to be inserted. |
addFirst | final public void addFirst(Object value)(Code) | | Inserts the specified value at the beginning of this list.
Parameters: value - the value to be inserted. |
addLast | public void addLast(Object value)(Code) | | Appends the specified value to the end of this list (fast).
Parameters: value - the value to be inserted. |
clear | final public void clear()(Code) | | |
delete | final public void delete(Record record)(Code) | | |
get | final public Object get(int index)(Code) | | Returns the value at the specified position in this list.
Parameters: index - the index of value to return. the value at the specified position in this list. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
hashCode | public int hashCode()(Code) | | Returns the hash code value for this list. The hash code of a list
is defined to be the result of the following calculation:[code]
h = 1;
Iterator i = list.iterator();
while (i.hasNext()) {
Object obj = i.next();
h = 31 * h + this.getValueComparator().hashCodeOf(obj);
}[/code]
the hash code value for this list. |
head | final public Record head()(Code) | | |
indexOf | final public int indexOf(Object value)(Code) | | Returns the index in this list of the first occurrence of the specified
value, or -1 if this list does not contain this value.
Parameters: value - the value to search for. the index in this list of the first occurrence of the specifiedvalue, or -1 if this list does not contain this value. |
lastIndexOf | final public int lastIndexOf(Object value)(Code) | | Returns the index in this list of the last occurrence of the specified
value, or -1 if this list does not contain this value.
Parameters: value - the value to search for. the index in this list of the last occurrence of the specifiedvalue, or -1 if this list does not contain this value. |
listIterator | public ListIterator listIterator(int index)(Code) | | Returns a list iterator from the specified position
(allocated on the stack when executed in a
javolution.context.StackContext StackContext ).
The specified index indicates the first value that would be returned by
an initial call to the next method. An initial call to
the previous method would return the value with the
specified index minus one.
Parameters: index - index of first value to be returned from thelist iterator (by a call to the next method). a list iterator over the values in this liststarting at the specified position in this list. throws: IndexOutOfBoundsException - if the index is out of range[code](index < 0 || index > size())[/code]. |
newNode | protected Node newNode()(Code) | | Returns a new node for this list; this method can be overriden by
custom list implementation.
a new node. |
remove | final public Object remove(int index)(Code) | | Removes the value at the specified position in this list.
Shifts any subsequent values to the left (subtracts one
from their indices). Returns the value that was removed from the
list.
Parameters: index - the index of the value to removed. the value previously at the specified position. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
removeFirst | final public Object removeFirst()(Code) | | Removes and returns the first value of this list.
this list's first value before this call. throws: NoSuchElementException - if this list is empty. |
removeLast | final public Object removeLast()(Code) | | Removes and returns the last value of this list (fast).
this list's last value before this call. throws: NoSuchElementException - if this list is empty. |
reset | public void reset()(Code) | | |
set | final public Object set(int index, Object value)(Code) | | Replaces the value at the specified position in this list with the
specified value.
Parameters: index - the index of value to replace. Parameters: value - the value to be stored at the specified position. the value previously at the specified position. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
setValueComparator | public FastList setValueComparator(FastComparator comparator)(Code) | | Sets the comparator to use for value equality.
Parameters: comparator - the value comparator. this |
size | final public int size()(Code) | | |
subList | final public List subList(int fromIndex, int toIndex)(Code) | | Returns a view of the portion of this list between the specified
indexes (allocated from the "stack" when executing in a
javolution.context.StackContext StackContext ).
If the specified indexes are equal, the returned list is empty.
The returned list is backed by this list, so non-structural changes in
the returned list are reflected in this list, and vice-versa.
This method eliminates the need for explicit range operations (of
the sort that commonly exist for arrays). Any operation that expects
a list can be used as a range operation by passing a subList view
instead of a whole list. For example, the following idiom
removes a range of values from a list:
list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and
lastIndexOf , and all of the algorithms in the
Collections class can be applied to a subList.
The semantics of the list returned by this method become undefined if
the backing list (i.e., this list) is structurally modified in
any way other than via the returned list (structural modifications are
those that change the size of this list, or otherwise perturb it in such
a fashion that iterations in progress may yield incorrect results).
Parameters: fromIndex - low endpoint (inclusive) of the subList. Parameters: toIndex - high endpoint (exclusive) of the subList. a view of the specified range within this list. throws: IndexOutOfBoundsException - if [code](fromIndex < 0 ||toIndex > size || fromIndex < toIndex)[/code] |
tail | final public Record tail()(Code) | | |
|
|
|