|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<T>
com.scottlogic.util.PatchWorkArray<T>
T - The type of element that this list should store.public class PatchWorkArray<T>
List implementation which is backed by an ArrayList and performs lazy insertions and removals
This implementation is not synchronised so if you need
multi-threaded access then consider wrapping
it using the Collections.synchronizedList(java.util.List method.
The iterators this list provides are fail-fast, so any structural
modification, other than through the iterator itself, cause it to throw a
ConcurrentModificationException.
List,
Collection,
ArrayList,
Serialized Form| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
PatchWorkArray()
Creates a new PatchWorkArray backed by an ArrayList with an initial
capacity of ten. |
|
PatchWorkArray(int initialCapacity)
Creates a new PatchWorkArray backed by an ArrayList with the given
initial capacity. |
|
| Method Summary | |
|---|---|
void |
add(int index,
T obj)
Inserts the specified element at the specified position in this list. |
boolean |
add(T obj)
Adds the given object to the end of this PatchWorkArray. |
void |
clear()
Removes all elements and alterations from this PatchWorkArray. |
void |
fix()
Pushes all the alterations in this PatchWorkArray to the backing list,
leaving the number of alterations as zero. |
T |
get(int index)
Obtains the element at the given index in this PatchWorkArray. |
int |
getPerformanceHit()
The performance hit caused by the Alterations to the backingList of this
PatchWorkArray. |
java.util.Iterator<T> |
iterator()
Returns an iterator which allows the list to be iterated over in O(a + n), where a is the number of alterations and n is the number of elements in this PatchWorkArray. |
T |
remove(int index)
Removes and returns the element at the given index in this PatchWorkArray. |
int |
size()
Returns the number of elements in this PatchWorkArray. |
| Methods inherited from class java.util.AbstractList |
|---|
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, set, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public PatchWorkArray()
PatchWorkArray backed by an ArrayList with an initial
capacity of ten.
public PatchWorkArray(int initialCapacity)
PatchWorkArray backed by an ArrayList with the given
initial capacity.
| Method Detail |
|---|
public T get(int index)
PatchWorkArray. Note that
indices are numbered from zero through to #size()-1.
This implementation works in time O(log(d)), where d is the number of alterations in the list.
get in interface java.util.List<T>get in class java.util.AbstractList<T>PatchWorkArray.public int size()
PatchWorkArray.
size in interface java.util.Collection<T>size in interface java.util.List<T>size in class java.util.AbstractCollection<T>PatchWorkArray.public boolean add(T obj)
PatchWorkArray. This implementation
forbids null values from being added, an IllegalArgumentException
is thrown in the case that this is attempted.
add in interface java.util.Collection<T>add in interface java.util.List<T>add in class java.util.AbstractList<T>obj - the object to add to the list.
true if the operation to insert the element was successful.
java.lang.IllegalArgumentException - in the case that the given element is null.public int getPerformanceHit()
Alterations to the backingList of this
PatchWorkArray. The time it takes to perform the operations: get, remove, add is the log
of this value.
PatchWorkArray.public java.util.Iterator<T> iterator()
PatchWorkArray.
iterator in interface java.lang.Iterable<T>iterator in interface java.util.Collection<T>iterator in interface java.util.List<T>iterator in class java.util.AbstractList<T>Iterator for iterating elements of this list.
public void add(int index,
T obj)
If the given index is the current size of the list, the #add(Object) method is invoked, otherwise
the element is lazily added and the number of alterations is incremented.
add in interface java.util.List<T>add in class java.util.AbstractList<T>index - at which the element should be added.obj - the object to by inserted.
java.lang.IllegalArgumentException - in the case that the given element is null.
java.lang.IndexOutOfBoundsException - in the case that (0 <= index <= size()) does not hold.public void fix()
PatchWorkArray to the backing list,
leaving the number of alterations as zero.
This method performs structural changes to the list and hence increments the
modCount of the list.
public void clear()
PatchWorkArray.
clear in interface java.util.Collection<T>clear in interface java.util.List<T>clear in class java.util.AbstractList<T>public T remove(int index)
PatchWorkArray.
This method can increase or decrease the number of alterations, depending on the element on which it is called.
remove in interface java.util.List<T>remove in class java.util.AbstractList<T>index - the index of the element to remove.
java.lang.IllegalArgumentException - in the case that the index is not a valid index.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||