|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.dautelle.realtime.RealtimeObject
com.dautelle.util.FastList
This class represents a linked-list with real-time behavior
(nodes allocated from the "stack" when executing in
a PoolContext).
Instances of this class can be used to implement dynamically sized
real-time objects (no expensive resizing operations) or
for throw-away collections allocated from
the stack. Iterators upon instances of this class are real-time
compliant as well.
The list is single-linked in forward direction (that is, forward iteration is much faster than backward iteration). Access to the last element is optimized, so that insertion to the end of the list is as fast as to the head.
subList(int, int) is implemented effectively, so that, for example,
splitting the big list into several smaller ones will speed up random
(indexed) access.
This implementation is not synchronized. Multiple threads accessing or modifying the collection must be synchronized externally.
This class is public domain (not copyrighted).
| Nested Class Summary |
| Nested classes inherited from class com.dautelle.realtime.RealtimeObject |
RealtimeObject.Factory |
| Constructor Summary | |
FastList()
Allocates a heap-only list. |
|
| Method Summary | |
void |
add(int index,
java.lang.Object element)
Inserts the given element at the specified position. |
boolean |
add(java.lang.Object obj)
Adds an object into the end of the list. |
boolean |
addAll(java.util.Collection col)
Adds all objects from the collection to the end of the list. |
boolean |
addAll(int index,
java.util.Collection col)
Inserts all elements from the given collection starting at the specified position. |
void |
addFirst(java.lang.Object obj)
Inserts the object into the head of the list. |
void |
addLast(java.lang.Object obj)
Appends the object into the tail of the list. |
void |
clear()
Removes all objects from the list. |
boolean |
contains(java.lang.Object obj)
Searches for the object starting from the beginning of the list. |
boolean |
containsAll(java.util.Collection col)
Returns true if this list contains all of the elements of the specified collection. |
java.lang.Object |
export()
Exports the list and all contained Realtime objects. |
java.lang.Object |
get(int index)
Returns the element residing at the specified position. |
java.lang.Object |
getFirst()
Returns the first element of the list (the head). |
java.lang.Object |
getLast()
Returns the last element of the list (the tail). |
int |
indexOf(java.lang.Object obj)
Searches for the equal object and return it's position in the list. |
boolean |
isEmpty()
Returns true if this list contains no elements. |
java.util.Iterator |
iterator()
An iterator over the list elements, starting from the first. |
int |
lastIndexOf(java.lang.Object obj)
Searches for the equal object and return it's last occurence in the list. |
java.util.ListIterator |
listIterator()
An iterator over the list elements, starting from the first. |
java.util.ListIterator |
listIterator(int index)
An iterator over the list elements, starting from the specified one. |
static FastList |
newInstance()
Allocates a PoolContext-enabled list. |
java.lang.Object |
remove(int index)
Removes the element at specified position. |
boolean |
remove(java.lang.Object obj)
Searches for the given object in the list and remove the object (once). |
boolean |
removeAll(java.util.Collection col)
Removes all the elements that are contained in the given collection. |
java.lang.Object |
removeFirst()
Removes and returns the first element of the list (the head). |
boolean |
retainAll(java.util.Collection col)
Leaves only elements which are also contained in the given collection. |
java.lang.Object |
set(int index,
java.lang.Object element)
Sets the value of an element existing at the specified position. |
int |
size()
Amount of elements in the list. |
java.util.List |
subList(int fromIndex,
int toIndex)
A transparent portion of the list (sub-list). |
java.lang.Object[] |
toArray()
Copies list contents into the array. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Copies list contents into the array. |
FastString |
toFastString(java.lang.CharSequence begin,
java.lang.CharSequence end,
java.lang.CharSequence separator,
int capacity)
Stringifies the list into FastString. |
FastString |
toFastString(int capacity)
Stringify the list into FastString. |
java.lang.Object |
toHeap()
Relocates the list and all contained Realtime objects to the GC heap. |
java.lang.Object[] |
toPoolArray()
Copies list contents into the array. |
java.lang.String |
toString()
The list stringified. |
| Methods inherited from class com.dautelle.realtime.RealtimeObject |
clone, isLocalObject, isPoolObject, recycle |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
equals, hashCode |
| Methods inherited from interface java.util.List |
equals, hashCode |
| Constructor Detail |
public FastList()
| Method Detail |
public static FastList newInstance()
FastList() constructor).
PoolContextpublic final int size()
size in interface java.util.Collectionpublic java.lang.Object export()
export in interface Realtimeexport in class RealtimeObjectpublic java.lang.Object toHeap()
toHeap in interface RealtimetoHeap in class RealtimeObjectpublic java.lang.String toString()
toFastString(int).
public FastString toFastString(int capacity)
toFastString(CharSequence, CharSequence, CharSequence, int).
public FastString toFastString(java.lang.CharSequence begin, java.lang.CharSequence end, java.lang.CharSequence separator, int capacity)
aList.toFastString( "[", "]", ", ", aList.size() * 10 ).
public final boolean add(java.lang.Object obj)
null pointers are not allowed.
add in interface java.util.Collectionpublic boolean addAll(java.util.Collection col)
addAll in interface java.util.Collectionpublic void clear()
clear in interface java.util.Collectionpublic boolean contains(java.lang.Object obj)
contains in interface java.util.Collectionpublic boolean containsAll(java.util.Collection col)
false is returned.
Method contains(Object) is used to search for an element.
Null pointers from the collection are ignored (as if they were present in the list).
containsAll in interface java.util.Collectionpublic boolean isEmpty()
isEmpty in interface java.util.Collectionpublic java.util.Iterator iterator()
iterator in interface java.util.Collectionpublic boolean remove(java.lang.Object obj)
Object.equals(java.lang.Object).
remove in interface java.util.Collectiontrue if equal object was found and removed.public boolean removeAll(java.util.Collection col)
removeAll in interface java.util.Collectiontrue if the list was modified as a result.remove( Object ),
contains( Object )public boolean retainAll(java.util.Collection col)
retainAll in interface java.util.Collectionpublic java.lang.Object[] toPoolArray()
public java.lang.Object[] toArray()
Collections.sort will throw exceptions.
toArray in interface java.util.Collectionpublic java.lang.Object[] toArray(java.lang.Object[] array)
array,
then a new array is allocated from the GC heap, with exactly the size of the list.
This is required to conform with the collections framework API,
otherwise methods such as Collections.sort will throw exceptions.
toArray in interface java.util.Collection
public void add(int index,
java.lang.Object element)
list.add(0,element) will make the new
element the first element of the list;
list.add(list.size(),element) will made the new element
the last element of the list.
add in interface java.util.Listjava.lang.IndexOutOfBoundsException - if the index is less
than 0 or greater than size().
public boolean addAll(int index,
java.util.Collection col)
addAll in interface java.util.Listjava.lang.IndexOutOfBoundsException - if the index is less than
0 or greater than size().public java.lang.Object get(int index)
get in interface java.util.Listindex-th element
java.lang.IndexOutOfBoundsException - if the index is less
than 0 or greater than size() - 1.public int indexOf(java.lang.Object obj)
indexOf in interface java.util.Listpublic int lastIndexOf(java.lang.Object obj)
lastIndexOf in interface java.util.Listpublic java.util.ListIterator listIterator()
listIterator in interface java.util.Listpublic java.util.ListIterator listIterator(int index)
index-th element of the list.
listIterator in interface java.util.Listindex - may be from 0 till the list size().public java.lang.Object remove(int index)
remove in interface java.util.Listindex-th position.
java.lang.IndexOutOfBoundsException - if the index is less than
0 or greater than size() - 1.
public java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.Listjava.lang.IndexOutOfBoundsException - if the index is less than
0 or greater than size() - 1.
public java.util.List subList(int fromIndex,
int toIndex)
list.subList(10,14).clear() will remove
10th, 11th, 12th and 13th elements from the list.
You can use several sub-lists at the same time (even from different threads)
as long as there is at least one position of space between them:runThread( list.subList( 0, 10 ) ); runThread( list.subList( 10, 20 ); // Wrong! runThread( list.subList( 0, 9 ) ); runThread( list.subList( 10, 19 ) ); // Ok.You should not use the main list while using one of it's sub-lists.
subList in interface java.util.Listjava.lang.IndexOutOfBoundsException - if the index is less than 0 or greater than size().public final java.lang.Object removeFirst()
java.util.NoSuchElementException - if the list is empty.public final java.lang.Object getFirst()
java.util.NoSuchElementException - if the list is empty.public final java.lang.Object getLast()
java.util.NoSuchElementException - if the list is empty.public final void addFirst(java.lang.Object obj)
public final void addLast(java.lang.Object obj)
|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||