| |
|
| java.lang.Object javolution.util.FastCollection javolution.util.FastTable
All known Subclasses: j2me.util.ArrayList,
FastTable | public class FastTable extends FastCollection implements List,Reusable,RandomAccess(Code) | | This class represents a random access collection with real-time behavior
(smooth capacity increase).
This class has the following advantages over the widely used
java.util.ArrayList :
- No large array allocation (for large collections multi-dimensional
arrays are employed). The garbage collector is not stressed with
large chunk of memory to allocate (likely to trigger a
full garbage collection due to memory fragmentation).
- Support concurrent access/iteration without synchronization if the
collection values are not removed/inserted (Ref.
javolution.util discussion).
Iterations over the
FastTable values are faster when
performed using the
FastTable.get method rather than using collection
records or iterators:[code]
for (int i = 0, n = table.size(); i < n; i++) {
table.get(i);
}[/code]
FastTable supports
FastTable.sort sorting in place (quick sort)
using the
FastCollection.getValueComparator value comparator for the table (no object or array allocation when sorting).
The size of a
FastTable can be
FastTable.setSize set directly
and populated concurrently through the
FastTable.set(int,Object)
method (e.g. table shared by multiple threads each working on
different index ranges).
author: Jean-Marie Dautelle version: 5.2, August 20, 2007 |
Constructor Summary | |
public | FastTable() Creates a table of small initial capacity. | public | FastTable(String id) Creates a persistent table associated to the specified unique identifier
(convenience method). | public | FastTable(int capacity) Creates a table of specified initial capacity; unless the table size
reaches the specified capacity, operations on this table will not
allocate memory (no lazy object creation). | public | FastTable(Collection values) Creates a table 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 table.
Parameters: value - the value to be appended to this table. | final public void | add(int index, Object value) Inserts the specified value at the specified position in this table. | final public boolean | addAll(int index, Collection values) Inserts all of the values in the specified collection into this
table at the specified position. | final public void | addLast(Object value) Appends the specified value to the end of this table (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 element at the specified index.
Parameters: index - index of value to return. | final protected int | getCapacity() Returns the current capacity of this table. | final public Object | getFirst() Returns the first value of this table. | final public Object | getLast() Returns the last value of this table. | public FastComparator | getValueComparator() | final public Record | head() | final public int | indexOf(Object value) Returns the index in this table of the first occurrence of the specified
value, or -1 if this table does not contain this value.
Parameters: value - the value to search for. | public Iterator | iterator() Returns an 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 table of the last occurrence of the specified
value, or -1 if this table 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 list iterator being returned does not support insertion/deletion.
Parameters: index - the index of first value to be returned from thelist iterator (by a call to the next method). | public static FastTable | newInstance() Returns a new, preallocated or
FastTable.recycle recycled table instance
(on the stack when executing in a
javolution.context.StackContextStackContext ). | public static void | recycle(FastTable instance) Recycles a table
FastTable.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 from this table.
Shifts any subsequent values to the left (subtracts one
from their indices). | final public Object | removeLast() Removes and returns the last value of this table (fast). | final public void | removeRange(int fromIndex, int toIndex) Removes the values between [fromIndex..toIndex[ from
this table. | public void | reset() | final public Object | set(int index, Object value) Replaces the value at the specified position in this table with the
specified value.
Parameters: index - index of value to replace. Parameters: value - value to be stored at the specified position. | public void | setSize(int size) Sets the size of this table. | public FastTable | setValueComparator(FastComparator comparator) Sets the comparator to use for value equality or comparison if the
collection is ordered (see
FastTable.sort() ).
Parameters: comparator - the value comparator. | final public int | size() | final public FastTable | sort() Sorts this table in place (quick sort) using this table
FastCollection.getValueComparator value comparator (smallest first). | final public List | subList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specified
indexes (instance of
FastList 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() | final public void | trimToSize() Reduces the capacity of this table to the current size (minimize
storage space). | public Collection | unmodifiable() | final public Object | valueOf(Record record) |
ONE_VOLATILE | static volatile int ONE_VOLATILE(Code) | | |
FastTable | public FastTable()(Code) | | Creates a table of small initial capacity.
|
FastTable | public FastTable(String id)(Code) | | Creates a persistent table 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 |
FastTable | public FastTable(int capacity)(Code) | | Creates a table of specified initial capacity; unless the table size
reaches the specified capacity, operations on this table will not
allocate memory (no lazy object creation).
Parameters: capacity - the initial capacity. |
FastTable | public FastTable(Collection values)(Code) | | Creates a table containing the specified values, in the order they
are returned by the collection's iterator.
Parameters: values - the values to be placed into this table. |
add | final public boolean add(Object value)(Code) | | Appends the specified value to the end of this table.
Parameters: value - the value to be appended to this table. 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 table.
Shifts the value currently at that position
(if any) and any subsequent values to the right (adds one to their
indices).
Note: If this method is used concurrent access must be synchronized
(the table is no more thread-safe).
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
table at the specified position. Shifts the value currently at that
position (if any) and any subsequent values to the right
(increases their indices).
Note: If this method is used concurrent access must be synchronized
(the table is no more thread-safe).
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()) |
addLast | final public void addLast(Object value)(Code) | | Appends the specified value to the end of this table (fast).
Parameters: value - the value to be added. |
clear | final public void clear()(Code) | | |
delete | final public void delete(Record record)(Code) | | |
get | final public Object get(int index)(Code) | | Returns the element at the specified index.
Parameters: index - index of value to return. the value at the specified position in this list. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
getCapacity | final protected int getCapacity()(Code) | | Returns the current capacity of this table.
this table's capacity. |
head | final public Record head()(Code) | | |
indexOf | final public int indexOf(Object value)(Code) | | Returns the index in this table of the first occurrence of the specified
value, or -1 if this table does not contain this value.
Parameters: value - the value to search for. the index in this table of the first occurrence of the specifiedvalue, or -1 if this table does not contain this value. |
lastIndexOf | final public int lastIndexOf(Object value)(Code) | | Returns the index in this table of the last occurrence of the specified
value, or -1 if this table does not contain this value.
Parameters: value - the value to search for. the index in this table of the last occurrence of the specifiedvalue, or -1 if this table 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 list iterator being returned does not support insertion/deletion.
Parameters: index - the index of first value to be returned from thelist iterator (by a call to the next method). a list iterator of the values in this tablestarting at the specified position in this list. throws: IndexOutOfBoundsException - if the index is out of range [code](index < 0 || index > size())[/code] |
remove | final public Object remove(int index)(Code) | | Removes the value at the specified position from this table.
Shifts any subsequent values to the left (subtracts one
from their indices). Returns the value that was removed from the
table.
Note: If this method is used concurrent access must be synchronized
(the table is no more thread-safe).
Parameters: index - the index of the value to removed. the value previously at the specified position. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
removeLast | final public Object removeLast()(Code) | | Removes and returns the last value of this table (fast).
this table's last value before this call. throws: NoSuchElementException - if this table is empty. |
removeRange | final public void removeRange(int fromIndex, int toIndex)(Code) | | Removes the values between [fromIndex..toIndex[ from
this table.
Note: If this method is used concurrent access must be synchronized
(the table is no more thread-safe).
Parameters: fromIndex - the beginning index, inclusive. Parameters: toIndex - the ending index, exclusive. throws: IndexOutOfBoundsException - if (fromIndex < 0) || (toIndex < 0) || (fromIndex > toIndex) || (toIndex > this.size()) |
reset | public void reset()(Code) | | |
set | final public Object set(int index, Object value)(Code) | | Replaces the value at the specified position in this table with the
specified value.
Parameters: index - index of value to replace. Parameters: value - value to be stored at the specified position. previous value. throws: IndexOutOfBoundsException - if (index < 0) || (index >= size()) |
setSize | public void setSize(int size)(Code) | | Sets the size of this table. If the specified size is greater than
the current size then null elements are added; otherwise
the last elements are removed until the desired size is reached.
Parameters: size - the new size. |
setValueComparator | public FastTable setValueComparator(FastComparator comparator)(Code) | | Sets the comparator to use for value equality or comparison if the
collection is ordered (see
FastTable.sort() ).
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 (instance of
FastList 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: [code]
list.subList(from, to).clear();[/code]
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) | | |
trimToSize | final public void trimToSize()(Code) | | Reduces the capacity of this table to the current size (minimize
storage space).
|
|
|
|