The 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.

SafeArrayList

SafeArrayList

Construct a list containing the elements of the specified collection
in the order that they are returned by the collections iterator.

Method Detail

size

public int size()

Fetch the number of elements in this list.

Specified by:

size in interface java.util.Collection

Specified by:

size in interface java.util.List

Specified by:

size in class java.util.AbstractCollection

Returns:

the number of elements in this list

isEmpty

public boolean isEmpty()

Tests if this list is empty.

Specified by:

isEmpty in interface java.util.Collection

Specified by:

isEmpty in interface java.util.List

Overrides:

isEmpty in class java.util.AbstractCollection

Returns:

true if this list is empty, false otherwise

contains

public boolean contains(java.lang.Object element)

Fetch whether the given object is contained in this list.

Specified by:

contains in interface java.util.Collection

Specified by:

contains in interface java.util.List

Overrides:

contains in class java.util.AbstractCollection

Parameters:

element - the element to check

Returns:

true if the list contains the given element

indexOf

public int indexOf(java.lang.Object element)

Search for the first occurrence of the given argument, testing
for equality using the equals() method.

Specified by:

indexOf in interface java.util.List

Overrides:

indexOf in class java.util.AbstractList

Parameters:

element - the element to check

Returns:

the index of the first occurrence of the argument in this
list, or -1 if not found

lastIndexOf

public int lastIndexOf(java.lang.Object element)

Search for the last occurrence of the given argument in the list.

Specified by:

lastIndexOf in interface java.util.List

Overrides:

lastIndexOf in class java.util.AbstractList

Parameters:

element - the element to check

Returns:

the index of the last occurrence of the argument in this list,
or -1 if not found

clone

public java.lang.Object clone()

Returns a shallow copy of this list instance.

Overrides:

clone in class java.lang.Object

Returns:

a clone of this SafeArrayList instance

toArray

public java.lang.Object[] toArray()

Return an array containing all of the elements in the list in
the same order.

Specified by:

toArray in interface java.util.Collection

Specified by:

toArray in interface java.util.List

Overrides:

toArray in class java.util.AbstractCollection

Returns:

an array containing the elements of the list

toArray

public java.lang.Object[] toArray(java.lang.Object[] array)

Return an array containing all of the elements in this list in
the same order. Use the same type for the returned array as the
specified array.

Specified by:

toArray in interface java.util.Collection

Specified by:

toArray in interface java.util.List

Overrides:

toArray in class java.util.AbstractCollection

Parameters:

array - the array into which to store the elements of the
list (if it is big enough)

Returns:

an array containing the elements of this list

get

public java.lang.Object get(int index)

Fetch the element at the specified position in this list

Specified by:

get in interface java.util.List

Specified by:

get in class java.util.AbstractList

Parameters:

index - the index of the element to return

Returns:

the element at the given index

set

public java.lang.Object set(int index,
java.lang.Object element)

Replace the element at the specified position in this list with
the specified element

Specified by:

set in interface java.util.List

Overrides:

set in class java.util.AbstractList

Parameters:

index - the index of the element to replace

element - the replacement element

Returns:

the element previously stored at the given position

add

public boolean add(java.lang.Object element)

Adds (append) the given element to the end of our list.

Specified by:

add in interface java.util.Collection

Specified by:

add in interface java.util.List

Overrides:

add in class java.util.AbstractList

Parameters:

element - the element to add

Returns:

true always

add

public void add(int index,
java.lang.Object element)

Inserts the given element at the given position in this list, shifting
any element down.

Specified by:

add in interface java.util.List

Overrides:

add in class java.util.AbstractList

Parameters:

index - the index at which to insert the element

element - the element to insert

remove

public boolean remove(java.lang.Object element)

Removes a single instance of the specified element from this
collection.

Specified by:

remove in interface java.util.Collection

Specified by:

remove in interface java.util.List

Overrides:

remove in class java.util.AbstractCollection

Parameters:

element - the element to be removed

Returns:

true if the element contained the given element

remove

public java.lang.Object remove(int index)

Removes the element at the specified position in this list. Shifts
any element up.

Specified by:

remove in interface java.util.List

Overrides:

remove in class java.util.AbstractList

Parameters:

index - the index of the element to remove

Returns:

the element that was removed

clear

public void clear()

Empties this list.

Specified by:

clear in interface java.util.Collection

Specified by:

clear in interface java.util.List

Overrides:

clear in class java.util.AbstractList

addAll

public boolean addAll(java.util.Collection c)

Adds (appends) all of the elements in the given collection to the
end of this list.

Specified by:

addAll in interface java.util.Collection

Specified by:

addAll in interface java.util.List

Overrides:

addAll in class java.util.AbstractCollection

Parameters:

c - the elements to be appended to this list

Returns:

true if the contents of this list changed (collection to be
added was not empty)

addAll

public boolean addAll(int index,
java.util.Collection c)

Inserts all of the elements of the given collection to this list
at the specified index.

Specified by:

addAll in interface java.util.List

Overrides:

addAll in class java.util.AbstractList

Parameters:

index - the location in which to insert the new elements

c - the collection to add to our list

Returns:

true if the contents of this list changed (collection to be
added was not empty)

removeAll

public boolean removeAll(java.util.Collection c)

This operation is not supported by this list implementation.

Specified by:

removeAll in interface java.util.Collection

Specified by:

removeAll in interface java.util.List

Overrides:

removeAll in class java.util.AbstractCollection

retainAll

public boolean retainAll(java.util.Collection c)

This operation is not supported by this list implementation.

Specified by:

retainAll in interface java.util.Collection

Specified by:

retainAll in interface java.util.List

Overrides:

retainAll in class java.util.AbstractCollection

removeRange

protected void removeRange(int startIndex,
int endIndex)

Removes from this list all of the elements between the given indexes.

Overrides:

removeRange in class java.util.AbstractList

Parameters:

startIndex - the index to start the removal from (inclusive)

endIndex - the index to end the removal at (exclusive)

iterator

public java.util.Iterator iterator()

Returns an iterator over the elements in this list in proper sequence.
This iterator does not support removal of elements, and is represents
a snapshot of the contents of this list at the time the iterator is
fetched.

Specified by:

iterator in interface java.lang.Iterable

Specified by:

iterator in interface java.util.Collection

Specified by:

iterator in interface java.util.List

Overrides:

iterator in class java.util.AbstractList

Returns:

an iterator over the elements in this list

listIterator

public java.util.ListIterator listIterator()

Returns a list iterator of the elements in this list in proper sequnce.
This iterator does not support modifying the list, and represents a
snapshot of the contents of this list at the time the iterator is
fetched.

Specified by:

listIterator in interface java.util.List

Overrides:

listIterator in class java.util.AbstractList

listIterator

public java.util.ListIterator listIterator(int index)

Returns a list iterator of the elements in this list in proper
sequence, starting at the given index. This iterator does not
support modifying the list, and represents a snapshot of the contents
of this list at the time the iterator is fetched.