|
||||||||||
| 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<E>
java.util.ArrayList<E>
org.tentackle.util.TrackedArrayList<E>
E - the element typepublic class TrackedArrayList<E>
An extended ArrayList with the ability to tell whether it has been structurally modified.
Furthermore, a TrackedArrayList distinguish between additions and removals. Replacements are treated as a removal followed by an addition. Furthermore, all removed objects are kept in a separate list.
The main usage is in OR-mapping to check whether a list should be written back to persistant storage or not and which elements have to be deleted and which to be inserted or updated. However, the TrackedArrayList is not restricted to DbObjects. However, if it is used in OR-mapping (see DbRelations.wrbl), all objects must be DbObjects and must be tracked as well (honour isModified()).
Notice that the list of added objects is just the sum of this list and the list of removed objects.
| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
TrackedArrayList()
Creates a tracked ArrayList. |
|
TrackedArrayList(boolean modified)
Creates a tracked ArrayList. |
|
TrackedArrayList(Collection<E> collection)
Creates a list from a collection. |
|
TrackedArrayList(int initialCapacity,
boolean modified)
Creates a tracked ArrayList. |
|
| Method Summary | |
|---|---|
boolean |
add(E o)
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> c)
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> c)
Inserts all of the elements in the specified collection into this list, starting at the specified position. |
protected void |
addRemovedObject(E object)
Adds an object to the list of removed objects. |
protected void |
addRemovedObjects(Collection<E> objects)
Adds a list of objects to the list of removed objects. |
void |
clear()
Removes all of the elements from this list. |
TrackedArrayList<E> |
clone()
Clones the list. |
List<E> |
getRemovedObjects()
Gets the removed objects in the order of their removal. |
boolean |
isModified()
Gets the modification state, i.e. |
boolean |
isObjectAdded()
Gets the added state. |
boolean |
isObjectRemoved()
Gets the removal state. |
E |
remove(int index)
Removes the element at the specified position in this list. |
boolean |
remove(Object obj)
Removes the first occurrence of the specified element from this list, if it is present. |
boolean |
removeAll(Collection<?> c)
Removes all objects that are contained in the given collection. |
protected void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. |
boolean |
retainAll(Collection<?> c)
Removes all objects that are not contained in the given collection. |
E |
set(int index,
E element)
Replaces the element at the specified position in this list with the specified element. |
void |
setModified(boolean modified)
Sets the modified state. |
| Methods inherited from class java.util.ArrayList |
|---|
contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, size, toArray, toArray, trimToSize |
| Methods inherited from class java.util.AbstractList |
|---|
equals, hashCode, iterator, listIterator, listIterator, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, subList |
| Constructor Detail |
|---|
public TrackedArrayList(int initialCapacity,
boolean modified)
initialCapacity - is the initial size of the listmodified - is true if list is marked modified initiallypublic TrackedArrayList(boolean modified)
modified - is true if list is marked modified initiallypublic TrackedArrayList()
public TrackedArrayList(Collection<E> collection)
collection - the collection| Method Detail |
|---|
public TrackedArrayList<E> clone()
clone in class ArrayList<E>Cloneablepublic void setModified(boolean modified)
modified - is true to set modified to true,
false to clear all 4 flags including the list of removed Objects.public boolean isModified()
public boolean isObjectRemoved()
public boolean isObjectAdded()
public List<E> getRemovedObjects()
protected void addRemovedObject(E object)
object - the object to be added.protected void addRemovedObjects(Collection<E> objects)
objects - the list of objectspublic boolean add(E o)
add in interface Collection<E>add in interface List<E>add in class ArrayList<E>o - element to be appended to this list
Collection.add(E))
public void add(int index,
E element)
add in interface List<E>add in class ArrayList<E>index - index at which the specified element is to be insertedelement - element to be inserted
IndexOutOfBoundsException - if the index is out of range
(index < 0 || index > size())public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface List<E>addAll in class ArrayList<E>c - collection containing elements to be added to this list
NullPointerException - if the specified collection is nullAbstractCollection.add(Object)
public boolean addAll(int index,
Collection<? extends E> c)
addAll in interface List<E>addAll in class ArrayList<E>index - index at which to insert the first element from the
specified collectionc - collection containing elements to be added to this list
IndexOutOfBoundsException - if the index is out of range
(index < 0 || index > size())
NullPointerException - if the specified collection is nullpublic void clear()
clear in interface Collection<E>clear in interface List<E>clear in class ArrayList<E>public E remove(int index)
remove in interface List<E>remove in class ArrayList<E>index - the index of the element to be removed
IndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size())public boolean remove(Object obj)
remove in interface Collection<E>remove in interface List<E>remove in class ArrayList<E>obj - element to be removed from this list, if present
public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>removeAll in interface List<E>removeAll in class AbstractCollection<E>c - the collection containing the objects to be removed from this list.
AbstractCollection.remove(Object),
AbstractCollection.contains(Object)public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>retainAll in interface List<E>retainAll in class AbstractCollection<E>c - the collection containing the objects not to be removed from this list.
AbstractCollection.remove(Object),
AbstractCollection.contains(Object)
protected void removeRange(int fromIndex,
int toIndex)
removeRange in class ArrayList<E>fromIndex - index of first element to be removedtoIndex - index after last element to be removed
IndexOutOfBoundsException - if fromIndex or toIndex out of
range (fromIndex < 0 || fromIndex >= size() || toIndex
> size() || toIndex < fromIndex)
public E set(int index,
E element)
set in interface List<E>set in class ArrayList<E>index - index of the element to replaceelement - element to be stored at the specified position
IndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size())
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||