public class FastArrayList extends ArrayList
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 Declartion.
modCount| 构造器和说明 |
|---|
FastArrayList()
Construct a an empty list.
|
FastArrayList(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.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(int index,
Object element)
Insert the specified element at the specified position in this list,
and shift all remaining elements up one position.
|
boolean |
add(Object element)
Appends the specified element to the end of this list.
|
boolean |
addAll(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,
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.
|
Object |
clone()
Return a shallow copy of this
FastArrayList instance. |
boolean |
contains(Object element)
Return
true if this list contains the specified element. |
boolean |
containsAll(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(Object o)
Compare the specified object with this list for equality.
|
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(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.
|
Iterator |
iterator()
Return an iterator over the elements in this list in proper sequence.
|
int |
lastIndexOf(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. |
ListIterator |
listIterator()
Return an iterator of the elements of this list, in proper sequence.
|
ListIterator |
listIterator(int index)
Return an iterator of the elements of this list, in proper sequence,
starting at the specified position.
|
Object |
remove(int index)
Remove the element at the specified position in the list, and shift
any subsequent elements down one position.
|
boolean |
remove(Object element)
Remove the first occurrence of the specified element from the list,
and shift any subsequent elements down one position.
|
boolean |
removeAll(Collection collection)
Remove from this collection all of its elements that are contained
in the specified collection.
|
boolean |
retainAll(Collection collection)
Remove from this collection all of its elements except those that are
contained in the specified collection.
|
Object |
set(int index,
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.
|
List |
subList(int fromIndex,
int toIndex)
Return a view of the portion of this list between fromIndex
(inclusive) and toIndex (exclusive).
|
Object[] |
toArray()
Return an array containing all of the elements in this list in the
correct order.
|
Object[] |
toArray(Object[] array)
Return an array containing all of the elements in this list in the
correct order.
|
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. |
forEach, removeIf, removeRange, replaceAll, sort, spliteratorparallelStream, streampublic FastArrayList()
public FastArrayList(int capacity)
capacity - The initial capacity of the empty listpublic FastArrayList(Collection collection)
collection - The collection whose elements initialize the contents
of this listpublic boolean getFast()
public void setFast(boolean fast)
fast - true if the list should operate in fast modepublic boolean add(Object element)
public void add(int index,
Object element)
add 在接口中 Listadd 在类中 ArrayListindex - Index at which to insert this elementelement - The element to be insertedIndexOutOfBoundsException - if the index is out of rangepublic boolean addAll(Collection collection)
public boolean addAll(int index,
Collection collection)
addAll 在接口中 ListaddAll 在类中 ArrayListindex - Index at which insertion takes placecollection - The collection to be addedIndexOutOfBoundsException - if the index is out of rangepublic void clear()
clear 在接口中 Collectionclear 在接口中 Listclear 在类中 ArrayListUnsupportedOperationException - if clear()
is not supported by this listpublic Object clone()
FastArrayList instance.
The elements themselves are not copied.public boolean contains(Object element)
true if this list contains the specified element.public boolean containsAll(Collection collection)
true if this list contains all of the elements
in the specified Collection.containsAll 在接口中 CollectioncontainsAll 在接口中 ListcontainsAll 在类中 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 在类中 ArrayListcapacity - The new minimum capacitypublic boolean equals(Object o)
List.equals method.equals 在接口中 Collectionequals 在接口中 Listequals 在类中 AbstractListo - Object to be compared to this listpublic Object get(int index)
get 在接口中 Listget 在类中 ArrayListindex - The index of the element to returnIndexOutOfBoundsException - if the index is out of rangepublic int hashCode()
List.hashCode method.hashCode 在接口中 CollectionhashCode 在接口中 ListhashCode 在类中 AbstractListpublic int indexOf(Object element)
equals() method, and return
the corresponding index, or -1 if the object is not found.public boolean isEmpty()
public Iterator iterator()
public int lastIndexOf(Object element)
equals() method, and return
the corresponding index, or -1 if the object is not found.lastIndexOf 在接口中 ListlastIndexOf 在类中 ArrayListelement - The element to search forpublic ListIterator listIterator()
iterator().listIterator 在接口中 ListlistIterator 在类中 ArrayListpublic ListIterator listIterator(int index)
iterator().listIterator 在接口中 ListlistIterator 在类中 ArrayListindex - The starting position of the iterator to returnIndexOutOfBoundsException - if the index is out of rangepublic Object remove(int index)
remove 在接口中 Listremove 在类中 ArrayListindex - Index of the element to be removedIndexOutOfBoundsException - if the index is out of rangepublic boolean remove(Object element)
public boolean removeAll(Collection collection)
removeAll 在接口中 CollectionremoveAll 在接口中 ListremoveAll 在类中 ArrayListcollection - Collection containing elements to be removedUnsupportedOperationException - if this optional operation
is not supported by this listpublic boolean retainAll(Collection collection)
retainAll 在接口中 CollectionretainAll 在接口中 ListretainAll 在类中 ArrayListcollection - Collection containing elements to be retainedUnsupportedOperationException - if this optional operation
is not supported by this listpublic Object set(int index, Object element)
set 在接口中 Listset 在类中 ArrayListindex - Index of the element to replaceelement - The new element to be storedIndexOutOfBoundsException - if the index is out of rangepublic int size()
public List subList(int fromIndex, int toIndex)
subList 在接口中 ListsubList 在类中 ArrayListfromIndex - The starting index of the sublist viewtoIndex - The index after the end of the sublist viewIndexOutOfBoundsException - if an index is out of rangepublic Object[] toArray()
public Object[] toArray(Object[] array)
toArray 在接口中 CollectiontoArray 在接口中 ListtoArray 在类中 ArrayListarray - Array defining the element type of the returned listArrayStoreException - if the runtime type of array
is not a supertype of the runtime type of every element in this listpublic String toString()
toString 在类中 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 在类中 ArrayListCopyright © 2024. All rights reserved.