| Method from org.apache.commons.collections.FastArrayList Detail: |
public boolean add(Object element) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.add(element);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.add(element));
}
}
}
Appends the specified element to the end of this list. |
public void add(int index,
Object element) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
temp.add(index, element);
list = temp;
}
} else {
synchronized (list) {
list.add(index, element);
}
}
}
Insert the specified element at the specified position in this list,
and shift all remaining elements up one position. |
public boolean addAll(Collection collection) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.addAll(collection);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.addAll(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. |
public boolean addAll(int index,
Collection collection) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.addAll(index, collection);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.addAll(index, 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. |
public void clear() {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
temp.clear();
list = temp;
}
} else {
synchronized (list) {
list.clear();
}
}
}
Remove all of the elements from this list. The list will be empty
after this call returns. |
public Object clone() {
FastArrayList results = null;
if (fast) {
results = new FastArrayList(list);
} else {
synchronized (list) {
results = new FastArrayList(list);
}
}
results.setFast(getFast());
return (results);
}
Return a shallow copy of this FastArrayList instance.
The elements themselves are not copied. |
public boolean contains(Object element) {
if (fast) {
return (list.contains(element));
} else {
synchronized (list) {
return (list.contains(element));
}
}
}
Return true if this list contains the specified element. |
public boolean containsAll(Collection collection) {
if (fast) {
return (list.containsAll(collection));
} else {
synchronized (list) {
return (list.containsAll(collection));
}
}
}
Return true if this list contains all of the elements
in the specified Collection. |
public void ensureCapacity(int capacity) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
temp.ensureCapacity(capacity);
list = temp;
}
} else {
synchronized (list) {
list.ensureCapacity(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. |
public boolean equals(Object o) {
// Simple tests that require no synchronization
if (o == this)
return (true);
else if (!(o instanceof List))
return (false);
List lo = (List) o;
// Compare the sets of elements for equality
if (fast) {
ListIterator li1 = list.listIterator();
ListIterator li2 = lo.listIterator();
while (li1.hasNext() && li2.hasNext()) {
Object o1 = li1.next();
Object o2 = li2.next();
if (!(o1 == null ? o2 == null : o1.equals(o2)))
return (false);
}
return (!(li1.hasNext() || li2.hasNext()));
} else {
synchronized (list) {
ListIterator li1 = list.listIterator();
ListIterator li2 = lo.listIterator();
while (li1.hasNext() && li2.hasNext()) {
Object o1 = li1.next();
Object o2 = li2.next();
if (!(o1 == null ? o2 == null : o1.equals(o2)))
return (false);
}
return (!(li1.hasNext() || li2.hasNext()));
}
}
}
Compare the specified object with this list for equality. This
implementation uses exactly the code that is used to define the
list equals function in the documentation for the
List.equals method. |
public Object get(int index) {
if (fast) {
return (list.get(index));
} else {
synchronized (list) {
return (list.get(index));
}
}
}
Return the element at the specified position in the list. |
public boolean getFast() {
return (this.fast);
}
Returns true if this list is operating in fast mode. |
public int hashCode() {
if (fast) {
int hashCode = 1;
java.util.Iterator i = list.iterator();
while (i.hasNext()) {
Object o = i.next();
hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode());
}
return (hashCode);
} else {
synchronized (list) {
int hashCode = 1;
java.util.Iterator i = list.iterator();
while (i.hasNext()) {
Object o = i.next();
hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode());
}
return (hashCode);
}
}
}
Return the hash code value for this list. This implementation uses
exactly the code that is used to define the list hash function in the
documentation for the List.hashCode method. |
public int indexOf(Object element) {
if (fast) {
return (list.indexOf(element));
} else {
synchronized (list) {
return (list.indexOf(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. |
public boolean isEmpty() {
if (fast) {
return (list.isEmpty());
} else {
synchronized (list) {
return (list.isEmpty());
}
}
}
Test if this list has no elements. |
public Iterator iterator() {
if (fast) {
return new ListIter(0);
} else {
return list.iterator();
}
}
Return an iterator over the elements in this list in proper sequence.
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). |
public int lastIndexOf(Object element) {
if (fast) {
return (list.lastIndexOf(element));
} else {
synchronized (list) {
return (list.lastIndexOf(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. |
public ListIterator listIterator() {
if (fast) {
return new ListIter(0);
} else {
return list.listIterator();
}
}
Return an iterator of the elements of this list, in proper sequence.
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). |
public ListIterator listIterator(int index) {
if (fast) {
return new ListIter(index);
} else {
return list.listIterator(index);
}
}
Return an iterator of the elements of this list, in proper sequence,
starting at the specified position.
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). |
public Object remove(int index) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
Object result = temp.remove(index);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.remove(index));
}
}
}
Remove the element at the specified position in the list, and shift
any subsequent elements down one position. |
public boolean remove(Object element) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.remove(element);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.remove(element));
}
}
}
Remove the first occurrence of the specified element from the list,
and shift any subsequent elements down one position. |
public boolean removeAll(Collection collection) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.removeAll(collection);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.removeAll(collection));
}
}
}
Remove from this collection all of its elements that are contained
in the specified collection. |
public boolean retainAll(Collection collection) {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
boolean result = temp.retainAll(collection);
list = temp;
return (result);
}
} else {
synchronized (list) {
return (list.retainAll(collection));
}
}
}
Remove from this collection all of its elements except those that are
contained in the specified collection. |
public Object set(int index,
Object element) {
if (fast) {
return (list.set(index, element));
} else {
synchronized (list) {
return (list.set(index, element));
}
}
}
Replace the element at the specified position in this list with
the specified element. Returns the previous object at that position.
IMPLEMENTATION NOTE - This operation is specifically
documented to not be a structural change, so it is safe to be performed
without cloning. |
public void setFast(boolean fast) {
this.fast = fast;
}
Sets whether this list will operate in fast mode. |
public int size() {
if (fast) {
return (list.size());
} else {
synchronized (list) {
return (list.size());
}
}
}
Return the number of elements in this list. |
public List subList(int fromIndex,
int toIndex) {
if (fast) {
return new SubList(fromIndex, toIndex);
} else {
return list.subList(fromIndex, toIndex);
}
}
Return a view of the portion of this list between fromIndex
(inclusive) and toIndex (exclusive). The returned list is backed
by this list, so non-structural changes in the returned list are
reflected in this list. The returned list supports
all of the optional list operations supported by this list. |
public Object[] toArray() {
if (fast) {
return (list.toArray());
} else {
synchronized (list) {
return (list.toArray());
}
}
}
Return an array containing all of the elements in this list in the
correct order. |
public Object[] toArray(Object[] array) {
if (fast) {
return (list.toArray(array));
} else {
synchronized (list) {
return (list.toArray(array));
}
}
}
Return an array containing all of the elements in this list in the
correct order. The runtime type of the returned array is that of
the specified array. If the list fits in the specified array, it is
returned therein. Otherwise, a new array is allocated with the
runtime type of the specified array, and the size of this list. |
public String toString() {
StringBuffer sb = new StringBuffer("FastArrayList[");
sb.append(list.toString());
sb.append("]");
return (sb.toString());
}
Return a String representation of this object. |
public void trimToSize() {
if (fast) {
synchronized (this) {
ArrayList temp = (ArrayList) list.clone();
temp.trimToSize();
list = temp;
}
} else {
synchronized (list) {
list.trimToSize();
}
}
}
Trim the capacity of this ArrayList instance to be the
list's current size. An application can use this operation to minimize
the storage of an ArrayList instance. |