|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractCollection<E>
AbstractList<E>
ArrayList<E>
CheckedArrayList<E>
E - The type of elements in the list.@ThreadSafe public class CheckedArrayList<E>
A checked and synchronized List. Type checks are performed at run-time in addition of
compile-time checks. The synchronization lock can be modified at runtime by overriding the
getLock() method.
This class is similar to using the wrappers provided in Collections, minus the cost
of indirection levels and with the addition of overrideable methods.
Collections.checkedList(java.util.List, java.lang.Class) ,
Collections.synchronizedList(java.util.List) ,
Serialized Form
| utility/geotk-utility (download) | View source code for this class |
| Field Summary |
|---|
| Fields inherited from class AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
CheckedArrayList(Class<E> type)
Constructs a list of the specified type. |
|
CheckedArrayList(Class<E> type,
int capacity)
Constructs a list of the specified type and initial capacity. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E element)
Appends the specified element to the end of this list. |
|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this list. |
|
boolean |
addAll(Collection<? extends E> collection)
Appends 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<? extends E> collection)
Inserts all of the elements in the specified collection into this list, starting at the specified position. |
|
protected void |
checkWritePermission()
Checks if changes in this collection are allowed. |
|
void |
clear()
Removes all of the elements from this list. |
|
CheckedArrayList<E> |
clone()
Returns a shallow copy of this list. |
|
boolean |
contains(Object o)
Returns true if this list contains the specified element. |
|
void |
ensureCapacity(int minCapacity)
Increases the capacity, if necessary, to ensure that it can hold the given number of elements. |
|
protected void |
ensureValidType(E element)
Checks the type of the specified object. |
|
boolean |
equals(Object o)
Compares the specified object with this list for equality. |
|
E |
get(int index)
Returns the element at the specified position in this list. |
|
Class<E> |
getElementType()
Returns the element type given at construction time. |
|
protected Object |
getLock()
Returns the synchronization lock. |
|
int |
hashCode()
Returns the hash code value for this list. |
|
int |
indexOf(Object o)
Returns the index of the first occurrence of the specified element in this list, or -1 if none. |
|
boolean |
isEmpty()
Returns true if this list contains no elements. |
|
Iterator<E> |
iterator()
Returns an iterator over the elements in this list. |
|
int |
lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element in this list, or -1 if none. |
|
E |
remove(int index)
Removes the element at the specified position in this list. |
|
boolean |
remove(Object o)
Removes the first occurrence of the specified element from this list. |
|
boolean |
removeAll(Collection<?> c)
Removes all of this list's elements that are also contained in the specified collection. |
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this list that are contained in the specified collection. |
|
E |
set(int index,
E element)
Replaces the element at the specified position in this list with the specified element. |
|
int |
size()
Returns the number of elements in this list. |
|
Object[] |
toArray()
Returns an array containing all of the elements in this list. |
|
|
toArray(T[] a)
Returns an array containing all of the elements in this list in proper sequence. |
|
String |
toString()
Returns a string representation of this list. |
|
void |
trimToSize()
Trims the capacity to the list's current size. |
|
| Methods inherited from class ArrayList |
|---|
removeRange |
| Methods inherited from class AbstractList |
|---|
listIterator, listIterator, subList |
| Methods inherited from class AbstractCollection |
|---|
containsAll |
| Methods inherited from class Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface Collection |
|---|
containsAll |
| Methods inherited from interface List |
|---|
containsAll, listIterator, listIterator, subList |
| Constructor Detail |
|---|
public CheckedArrayList(Class<E> type)
type - The element type (should not be null).
public CheckedArrayList(Class<E> type,
int capacity)
type - The element type (should not be null).capacity - The initial capacity.| Method Detail |
|---|
public Class<E> getElementType()
getElementType in interface CheckedCollection<E>getElementType in interface CheckedContainer<E>
protected void ensureValidType(E element)
throws IllegalArgumentException
element - the object to check, or null.
IllegalArgumentException - if the specified element is not of the expected type.
protected void checkWritePermission()
throws UnsupportedOperationException
UnsupportedOperationException - if this collection is unmodifiable.protected Object getLock()
this.
Subclasses that override this method should be careful to update the lock reference
when this list is cloned.
public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface List<E>iterator in class AbstractList<E>public int size()
size in interface Collection<E>size in interface List<E>size in class ArrayList<E>public boolean isEmpty()
true if this list contains no elements.
isEmpty in interface Collection<E>isEmpty in interface List<E>isEmpty in class ArrayList<E>public boolean contains(Object o)
true if this list contains the specified element.
contains in interface Collection<E>contains in interface List<E>contains in class ArrayList<E>public int indexOf(Object o)
indexOf in interface List<E>indexOf in class ArrayList<E>public int lastIndexOf(Object o)
lastIndexOf in interface List<E>lastIndexOf in class ArrayList<E>public E get(int index)
get in interface List<E>get in class ArrayList<E>
public E set(int index,
E element)
throws IllegalArgumentException,
UnsupportedOperationException
set in interface List<E>set in class ArrayList<E>index - index of element to replace.element - element to be stored at the specified position.
IndexOutOfBoundsException - if index out of range.
IllegalArgumentException - if the specified element is not of the expected type.
UnsupportedOperationException - if this collection is unmodifiable.
public boolean add(E element)
throws IllegalArgumentException,
UnsupportedOperationException
add in interface Collection<E>add in interface List<E>add in class ArrayList<E>element - element to be appended to this list.
true.
IllegalArgumentException - if the specified element is not of the expected type.
UnsupportedOperationException - if this collection is unmodifiable.
public void add(int index,
E element)
throws IllegalArgumentException,
UnsupportedOperationException
add in interface List<E>add in class ArrayList<E>index - index at which the specified element is to be inserted.element - element to be inserted.
IndexOutOfBoundsException - if index out of range.
IllegalArgumentException - if the specified element is not of the expected type.
UnsupportedOperationException - if this collection is unmodifiable.
public boolean addAll(Collection<? extends E> collection)
throws IllegalArgumentException,
UnsupportedOperationException
addAll in interface Collection<E>addAll in interface List<E>addAll in class ArrayList<E>collection - the elements to be inserted into this list.
true if this list changed as a result of the call.
IllegalArgumentException - if at least one element is not of the expected type.
UnsupportedOperationException - if this collection is unmodifiable.
public boolean addAll(int index,
Collection<? extends E> collection)
throws IllegalArgumentException,
UnsupportedOperationException
addAll in interface List<E>addAll in class ArrayList<E>index - index at which to insert first element fromm the specified collection.collection - elements to be inserted into this list.
true if this list changed as a result of the call.
IllegalArgumentException - if at least one element is not of the expected type.
UnsupportedOperationException - if this collection is unmodifiable.
public E remove(int index)
throws UnsupportedOperationException
remove in interface List<E>remove in class ArrayList<E>UnsupportedOperationException - if this collection is unmodifiable.
public boolean remove(Object o)
throws UnsupportedOperationException
remove in interface Collection<E>remove in interface List<E>remove in class ArrayList<E>UnsupportedOperationException - if this collection is unmodifiable.
public boolean removeAll(Collection<?> c)
throws UnsupportedOperationException
removeAll in interface Collection<E>removeAll in interface List<E>removeAll in class AbstractCollection<E>UnsupportedOperationException - if this collection is unmodifiable.
public boolean retainAll(Collection<?> c)
throws UnsupportedOperationException
retainAll in interface Collection<E>retainAll in interface List<E>retainAll in class AbstractCollection<E>UnsupportedOperationException - if this collection is unmodifiable.public void trimToSize()
trimToSize in class ArrayList<E>public void ensureCapacity(int minCapacity)
ensureCapacity in class ArrayList<E>
public void clear()
throws UnsupportedOperationException
clear in interface Collection<E>clear in interface List<E>clear in class ArrayList<E>UnsupportedOperationException - if this collection is unmodifiable.public Object[] toArray()
toArray in interface Collection<E>toArray in interface List<E>toArray in class ArrayList<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in interface List<E>toArray in class ArrayList<E>T - The type of array elements.public String toString()
toString in class AbstractCollection<E>public boolean equals(Object o)
equals in interface Collection<E>equals in interface List<E>equals in class AbstractList<E>public int hashCode()
hashCode in interface Collection<E>hashCode in interface List<E>hashCode in class AbstractList<E>public CheckedArrayList<E> clone()
clone in class ArrayList<E>Object.clone()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||