public final class SafeArrayList
extends java.util.AbstractList
implements java.util.RandomAccess, java.lang.Cloneable
SafeArrayList is an array List
implementation that provides basic thread-safety by implementing
a copy-on-write scheme. Because of this, fetching an
Iterator or ListIterator would
return a snapshot of the list data at the time the iterators
were fetched. Although this class is declared public, it is part of the implementation, and not part of the published API.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
SafeArrayList.SafeListIterator
A list iterator implementation based on a static array.
|
| Constructor and Description |
|---|
SafeArrayList()
Construct an empty list.
|
SafeArrayList(java.util.Collection c)
Construct a list containing the elements of the specified collection
in the order that they are returned by the collections iterator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
java.lang.Object element)
Inserts the given element at the given position in this list, shifting
any element down.
|
boolean |
add(java.lang.Object element)
Adds (append) the given element to the end of our list.
|
boolean |
addAll(java.util.Collection c)
Adds (appends) all of the elements in the given collection to the
end of this list.
|
boolean |
addAll(int index,
java.util.Collection c)
Inserts all of the elements of the given collection to this list
at the specified index.
|
void |
clear()
Empties this list.
|
java.lang.Object |
clone()
Returns a shallow copy of this list instance.
|
boolean |
contains(java.lang.Object element)
Fetch whether the given object is contained in this list.
|
java.lang.Object |
get(int index)
Fetch the element at the specified position in this list
|
int |
indexOf(java.lang.Object element)
Search for the first occurrence of the given argument, testing
for equality using the
equals() method. |
boolean |
isEmpty()
Tests if this list is empty.
|
java.util.Iterator |
iterator()
Returns 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 in the list.
|
java.util.ListIterator |
listIterator()
Returns a list iterator of the elements in this list in proper sequnce.
|
java.util.ListIterator |
listIterator(int index)
Returns a list iterator of the elements in this list in proper
sequence, starting at the given index.
|
java.lang.Object |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(java.lang.Object element)
Removes a single instance of the specified element from this
collection.
|
boolean |
removeAll(java.util.Collection c)
This operation is not supported by this list implementation.
|
protected void |
removeRange(int startIndex,
int endIndex)
Removes from this list all of the elements between the given indexes.
|
boolean |
retainAll(java.util.Collection c)
This operation is not supported by this list implementation.
|
java.lang.Object |
set(int index,
java.lang.Object element)
Replace the element at the specified position in this list with
the specified element
|
int |
size()
Fetch the number of elements in this list.
|
java.util.List |
subList(int startIndex,
int endIndex)
This operation is not supported by this list implementation.
|
java.lang.Object[] |
toArray()
Return an array containing all of the elements in the list in
the same order.
|
java.lang.Object[] |
toArray(java.lang.Object[] array)
Return an array containing all of the elements in this list in
the same order.
|
java.lang.String |
toString()
Fetch a visible representation of this object.
|
public SafeArrayList()
public SafeArrayList(java.util.Collection c)
public int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollectionpublic boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in interface java.util.ListisEmpty in class java.util.AbstractCollectionpublic boolean contains(java.lang.Object element)
contains in interface java.util.Collectioncontains in interface java.util.Listcontains in class java.util.AbstractCollectionelement - the element to checkpublic int indexOf(java.lang.Object element)
equals() method.indexOf in interface java.util.ListindexOf in class java.util.AbstractListelement - the element to checkpublic int lastIndexOf(java.lang.Object element)
lastIndexOf in interface java.util.ListlastIndexOf in class java.util.AbstractListelement - the element to checkpublic java.lang.Object clone()
clone in class java.lang.ObjectSafeArrayList instancepublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.AbstractCollectionpublic java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.AbstractCollectionarray - the array into which to store the elements of the
list (if it is big enough)public java.lang.Object get(int index)
get in interface java.util.Listget in class java.util.AbstractListindex - the index of the element to returnpublic java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.Listset in class java.util.AbstractListindex - the index of the element to replaceelement - the replacement elementpublic boolean add(java.lang.Object element)
add in interface java.util.Collectionadd in interface java.util.Listadd in class java.util.AbstractListelement - the element to addpublic void add(int index,
java.lang.Object element)
add in interface java.util.Listadd in class java.util.AbstractListindex - the index at which to insert the elementelement - the element to insertpublic boolean remove(java.lang.Object element)
remove in interface java.util.Collectionremove in interface java.util.Listremove in class java.util.AbstractCollectionelement - the element to be removedpublic java.lang.Object remove(int index)
remove in interface java.util.Listremove in class java.util.AbstractListindex - the index of the element to removepublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Listclear in class java.util.AbstractListpublic boolean addAll(java.util.Collection c)
addAll in interface java.util.CollectionaddAll in interface java.util.ListaddAll in class java.util.AbstractCollectionc - the elements to be appended to this listpublic boolean addAll(int index,
java.util.Collection c)
addAll in interface java.util.ListaddAll in class java.util.AbstractListindex - the location in which to insert the new elementsc - the collection to add to our listpublic boolean removeAll(java.util.Collection c)
removeAll in interface java.util.CollectionremoveAll in interface java.util.ListremoveAll in class java.util.AbstractCollectionpublic boolean retainAll(java.util.Collection c)
retainAll in interface java.util.CollectionretainAll in interface java.util.ListretainAll in class java.util.AbstractCollectionprotected void removeRange(int startIndex,
int endIndex)
removeRange in class java.util.AbstractListstartIndex - the index to start the removal from (inclusive)endIndex - the index to end the removal at (exclusive)public java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class java.util.AbstractListpublic java.util.ListIterator listIterator()
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListpublic java.util.ListIterator listIterator(int index)
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListindex - the index to start frompublic java.util.List subList(int startIndex,
int endIndex)
subList in interface java.util.ListsubList in class java.util.AbstractListpublic java.lang.String toString()
toString in class java.util.AbstractCollection