|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractList
java.util.ArrayList
org.apache.commons.collections.FastArrayList
public class FastArrayList
A customized implementation of java.util.ArrayList designed
to operate in a multithreaded environment where the large majority of
method calls are read-only, instead of structural changes. When operating
in "fast" mode, read calls are non-synchronized and write calls perform the
following steps:
When first created, objects of this class default to "slow" mode, where
all accesses of any type are synchronized but no cloning takes place. This
is appropriate for initially populating the collection, followed by a switch
to "fast" mode (by calling setFast(true)) after initialization
is complete.
NOTE: If you are creating and accessing an
ArrayList only within a single thread, you should use
java.util.ArrayList directly (with no synchronization), for
maximum performance.
NOTE: This class is not cross-platform. Using it may cause unexpected failures on some architectures. It suffers from the same problems as the double-checked locking idiom. In particular, the instruction that clones the internal collection and the instruction that sets the internal reference to the clone can be executed or perceived out-of-order. This means that any read operation might fail unexpectedly, as it may be reading the state of the internal collection before the internal collection is fully formed. For more information on the double-checked locking idiom, see the Double-Checked Locking Idiom Is Broken Declaration.
| Field Summary | |
|---|---|
protected boolean |
fast
Are we operating in "fast" mode? |
protected java.util.ArrayList |
list
The underlying list we are managing. |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
FastArrayList()
Construct a an empty list. |
|
FastArrayList(java.util.Collection collection)
Construct a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
FastArrayList(int capacity)
Construct an empty list with the specified capacity. |
|
| Method Summary | |
|---|---|
void |
add(int index,
java.lang.Object element)
Insert the specified element at the specified position in this list, and shift all remaining elements up one position. |
boolean |
add(java.lang.Object element)
Appends the specified element to the end of this list. |
boolean |
addAll(java.util.Collection collection)
Append all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. |
boolean |
addAll(int index,
java.util.Collection collection)
Insert all of the elements in the specified Collection at the specified position in this list, and shift any previous elements upwards as needed. |
void |
clear()
Remove all of the elements from this list. |
java.lang.Object |
clone()
Return a shallow copy of this FastArrayList instance. |
boolean |
contains(java.lang.Object element)
Return true if this list contains the specified element. |
boolean |
containsAll(java.util.Collection collection)
Return true if this list contains all of the elements
in the specified Collection. |
void |
ensureCapacity(int capacity)
Increase the capacity of this ArrayList instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument. |
boolean |
equals(java.lang.Object o)
Compare the specified object with this list for equality. |
java.lang.Object |
get(int index)
Return the element at the specified position in the list. |
boolean |
getFast()
Returns true if this list is operating in fast mode. |
int |
hashCode()
Return the hash code value for this list. |
int |
indexOf(java.lang.Object element)
Search for the first occurrence of the given argument, testing for equality using the equals() method, and return
the corresponding index, or -1 if the object is not found. |
boolean |
isEmpty()
Test if this list has no elements. |
java.util.Iterator |
iterator()
Return an iterator over the elements in this list in proper sequence. |
int |
lastIndexOf(java.lang.Object element)
Search for the last occurrence of the given argument, testing for equality using the equals() method, and return
the corresponding index, or -1 if the object is not found. |
java.util.ListIterator |
listIterator()
Return an iterator of the elements of this list, in proper sequence. |
java.util.ListIterator |
listIterator(int index)
Return an iterator of the elements of this list, in proper sequence, starting at the specified position. |
java.lang.Object |
remove(int index)
Remove the element at the specified position in the list, and shift any subsequent elements down one position. |
boolean |
remove(java.lang.Object element)
Remove the first occurrence of the specified element from the list, and shift any subsequent elements down one position. |
boolean |
removeAll(java.util.Collection collection)
Remove from this collection all of its elements that are contained in the specified collection. |
boolean |
retainAll(java.util.Collection collection)
Remove from this collection all of its elements except those that are contained in the specified collection. |
java.lang.Object |
set(int index,
java.lang.Object element)
Replace the element at the specified position in this list with the specified element. |
void |
setFast(boolean fast)
Sets whether this list will operate in fast mode. |
int |
size()
Return the number of elements in this list. |
java.util.List |
subList(int fromIndex,
int toIndex)
Return a view of the portion of this list between fromIndex (inclusive) and toIndex (exclusive). |
java.lang.Object[] |
toArray()
Return an array containing all of the elements in this list in the correct order. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Return an array containing all of the elements in this list in the correct order. |
java.lang.String |
toString()
Return a String representation of this object. |
void |
trimToSize()
Trim the capacity of this ArrayList instance to be the
list's current size. |
| Methods inherited from class java.util.ArrayList |
|---|
removeRange |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.util.ArrayList list
protected boolean fast
| Constructor Detail |
|---|
public FastArrayList()
public FastArrayList(int capacity)
capacity - The initial capacity of the empty listpublic FastArrayList(java.util.Collection collection)
collection - The collection whose elements initialize the contents
of this list| Method Detail |
|---|
public boolean getFast()
public void setFast(boolean fast)
fast - true if the list should operate in fast modepublic boolean add(java.lang.Object element)
add in interface java.util.Collectionadd in interface java.util.Listadd in class java.util.ArrayListelement - The element to be appended
public void add(int index,
java.lang.Object element)
add in interface java.util.Listadd in class java.util.ArrayListindex - Index at which to insert this elementelement - The element to be inserted
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic boolean addAll(java.util.Collection collection)
addAll in interface java.util.CollectionaddAll in interface java.util.ListaddAll in class java.util.ArrayListcollection - The collection to be appended
public boolean addAll(int index,
java.util.Collection collection)
addAll in interface java.util.ListaddAll in class java.util.ArrayListindex - Index at which insertion takes placecollection - The collection to be added
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Listclear in class java.util.ArrayListjava.lang.UnsupportedOperationException - if clear()
is not supported by this listpublic java.lang.Object clone()
FastArrayList instance.
The elements themselves are not copied.
clone in class java.util.ArrayListpublic boolean contains(java.lang.Object element)
true if this list contains the specified element.
contains in interface java.util.Collectioncontains in interface java.util.Listcontains in class java.util.ArrayListelement - The element to test forpublic boolean containsAll(java.util.Collection collection)
true if this list contains all of the elements
in the specified Collection.
containsAll in interface java.util.CollectioncontainsAll in interface java.util.ListcontainsAll in class java.util.AbstractCollectioncollection - Collection whose elements are to be checkedpublic void ensureCapacity(int capacity)
ArrayList instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.
ensureCapacity in class java.util.ArrayListcapacity - The new minimum capacitypublic boolean equals(java.lang.Object o)
List.equals method.
equals in interface java.util.Collectionequals in interface java.util.Listequals in class java.util.AbstractListo - Object to be compared to this listpublic java.lang.Object get(int index)
get in interface java.util.Listget in class java.util.ArrayListindex - The index of the element to return
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic int hashCode()
List.hashCode method.
hashCode in interface java.util.CollectionhashCode in interface java.util.ListhashCode in class java.util.AbstractListpublic int indexOf(java.lang.Object element)
equals() method, and return
the corresponding index, or -1 if the object is not found.
indexOf in interface java.util.ListindexOf in class java.util.ArrayListelement - The element to search forpublic boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in interface java.util.ListisEmpty in class java.util.ArrayListpublic java.util.Iterator iterator()
Thread safety
The iterator returned is thread-safe ONLY in FAST mode.
In slow mode there is no way to synchronize, or make the iterator thread-safe.
In fast mode iteration and modification may occur in parallel on different threads, however there is a restriction. Modification must be EITHER via the Iterator interface methods OR the List interface. If a mixture of modification methods is used a ConcurrentModificationException is thrown from the iterator modification method. If the List modification methods are used the changes are NOT visible in the iterator (it shows the list contents at the time the iterator was created).
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class java.util.AbstractListpublic int lastIndexOf(java.lang.Object element)
equals() method, and return
the corresponding index, or -1 if the object is not found.
lastIndexOf in interface java.util.ListlastIndexOf in class java.util.ArrayListelement - The element to search forpublic java.util.ListIterator listIterator()
Thread safety
The iterator returned is thread-safe ONLY in FAST mode.
In slow mode there is no way to synchronize, or make the iterator thread-safe.
In fast mode iteration and modification may occur in parallel on different threads, however there is a restriction. Modification must be EITHER via the Iterator interface methods OR the List interface. If a mixture of modification methods is used a ConcurrentModificationException is thrown from the iterator modification method. If the List modification methods are used the changes are NOT visible in the iterator (it shows the list contents at the time the iterator was created).
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListpublic java.util.ListIterator listIterator(int index)
Thread safety
The iterator returned is thread-safe ONLY in FAST mode.
In slow mode there is no way to synchronize, or make the iterator thread-safe.
In fast mode iteration and modification may occur in parallel on different threads, however there is a restriction. Modification must be EITHER via the Iterator interface methods OR the List interface. If a mixture of modification methods is used a ConcurrentModificationException is thrown from the iterator modification method. If the List modification methods are used the changes are NOT visible in the iterator (it shows the list contents at the time the iterator was created).
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListindex - The starting position of the iterator to return
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic java.lang.Object remove(int index)
remove in interface java.util.Listremove in class java.util.ArrayListindex - Index of the element to be removed
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic boolean remove(java.lang.Object element)
remove in interface java.util.Collectionremove in interface java.util.Listremove in class java.util.ArrayListelement - Element to be removedpublic boolean removeAll(java.util.Collection collection)
removeAll in interface java.util.CollectionremoveAll in interface java.util.ListremoveAll in class java.util.AbstractCollectioncollection - Collection containing elements to be removed
java.lang.UnsupportedOperationException - if this optional operation
is not supported by this listpublic boolean retainAll(java.util.Collection collection)
retainAll in interface java.util.CollectionretainAll in interface java.util.ListretainAll in class java.util.AbstractCollectioncollection - Collection containing elements to be retained
java.lang.UnsupportedOperationException - if this optional operation
is not supported by this list
public java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.Listset in class java.util.ArrayListindex - Index of the element to replaceelement - The new element to be stored
java.lang.IndexOutOfBoundsException - if the index is out of rangepublic int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.ArrayList
public java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListsubList in class java.util.AbstractListfromIndex - The starting index of the sublist viewtoIndex - The index after the end of the sublist view
java.lang.IndexOutOfBoundsException - if an index is out of rangepublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.ArrayListpublic java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.ArrayListarray - Array defining the element type of the returned list
java.lang.ArrayStoreException - if the runtime type of array
is not a supertype of the runtime type of every element in this listpublic java.lang.String toString()
toString in class java.util.AbstractCollectionpublic void trimToSize()
ArrayList instance to be the
list's current size. An application can use this operation to minimize
the storage of an ArrayList instance.
trimToSize in class java.util.ArrayList
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||