org.fuin.utils4j
Class ChangeTrackingUniqueList

java.lang.Object
  extended by org.fuin.utils4j.ChangeTrackingUniqueList
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List, Taggable

public class ChangeTrackingUniqueList
extends java.lang.Object
implements java.util.List, Taggable

A wrapper for lists that keeps track of all changes made to the list since construction. Only adding, replacing or deleting elements is tracked (not changes inside the objects). Duplicates elements are not allowed for the list - This is like a Set but at the same time ordered like a List . It's also possible to revert all changes.


Constructor Summary
ChangeTrackingUniqueList(java.util.List list)
          Constructor with covered list.
 
Method Summary
 void add(int index, java.lang.Object o)
          
 boolean add(java.lang.Object o)
          
 boolean addAll(java.util.Collection c)
          
 boolean addAll(int index, java.util.Collection c)
          
 void clear()
          
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection c)
          
 java.lang.Object get(int index)
          
 java.util.List getAdded()
          Returns added elements.
 java.util.List getDeleted()
          Returns deleted elements.
 boolean hasChangedSinceTagging()
          Returns if the content of the object has changed since setting the tag.
 int indexOf(java.lang.Object o)
          
 boolean isChanged()
          Returns if the list has changed.
 boolean isEmpty()
          
 boolean isTagged()
          Returns if the object is currently tagged.
 java.util.Iterator iterator()
          
 int lastIndexOf(java.lang.Object o)
          
 java.util.ListIterator listIterator()
          
 java.util.ListIterator listIterator(int index)
          
 java.lang.Object remove(int index)
          
 boolean remove(java.lang.Object o)
          
 boolean removeAll(java.util.Collection c)
          
 boolean retainAll(java.util.Collection c)
          
 void revert()
          Roll back all changes made since construction.
 void revertToTag()
          Reverts all changes made since setting the tag and clears internal state.
 java.lang.Object set(int index, java.lang.Object o)
          
 int size()
          
 java.util.List subList(int fromIndex, int toIndex)
          
 void tag()
          Start memorizing changes.
 java.lang.Object[] toArray()
          
 java.lang.Object[] toArray(java.lang.Object[] a)
          
 java.lang.String toString()
          
 void untag()
          Stop memorizing changes and clear internal state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

ChangeTrackingUniqueList

public ChangeTrackingUniqueList(java.util.List list)
Constructor with covered list. The list is tagged at construction time - This means isTagged() will return true without calling tag() first. If this behavior is not wanted you can call untag() after constructing the list.

Parameters:
list - Wrapped list - Be aware that this list will be changed by this class. There is no internal copy of the list - The reference itself is used.
Method Detail

isChanged

public final boolean isChanged()
Returns if the list has changed. If the list is not in tag mode (this means isTagged() returns true) this method will always return false.

Returns:
If elements have been added or deleted true else false.

getDeleted

public final java.util.List getDeleted()
Returns deleted elements. If the list is not in tag mode (this means isTagged() returns true) this method will always return an empty list.

Returns:
Elements that have been deleted since construction of this instance - Unmodifiable list!

getAdded

public final java.util.List getAdded()
Returns added elements. If the list is not in tag mode (this means isTagged() returns true) this method will always return an empty list.

Returns:
Elements that have been added since construction of this instance - Unmodifiable list!

revert

public final void revert()
Roll back all changes made since construction. WARNING: The position of the elements is not guaranteed to be the same again! This is the same function ad revertToTag(). If the list is not in tag mode ( this means isTagged() returns true) this method will do nothing.


add

public final boolean add(java.lang.Object o)

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List

add

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

Specified by:
add in interface java.util.List

addAll

public final boolean addAll(java.util.Collection c)

Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List

addAll

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

Specified by:
addAll in interface java.util.List

clear

public final void clear()

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List

contains

public final boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List

containsAll

public final boolean containsAll(java.util.Collection c)

Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List

get

public final java.lang.Object get(int index)

Specified by:
get in interface java.util.List

indexOf

public final int indexOf(java.lang.Object o)

Specified by:
indexOf in interface java.util.List

isEmpty

public final boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List

iterator

public final java.util.Iterator iterator()

Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List

lastIndexOf

public final int lastIndexOf(java.lang.Object o)

Specified by:
lastIndexOf in interface java.util.List

listIterator

public final java.util.ListIterator listIterator()

Specified by:
listIterator in interface java.util.List

listIterator

public final java.util.ListIterator listIterator(int index)

Specified by:
listIterator in interface java.util.List

remove

public final boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List

remove

public final java.lang.Object remove(int index)

Specified by:
remove in interface java.util.List

removeAll

public final boolean removeAll(java.util.Collection c)

Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List

retainAll

public final boolean retainAll(java.util.Collection c)

Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List

set

public final java.lang.Object set(int index,
                                  java.lang.Object o)

Specified by:
set in interface java.util.List

size

public final int size()

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List

subList

public final java.util.List subList(int fromIndex,
                                    int toIndex)

Specified by:
subList in interface java.util.List

toArray

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

Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

toArray

public final java.lang.Object[] toArray(java.lang.Object[] a)

Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

toString

public final java.lang.String toString()

Overrides:
toString in class java.lang.Object

hasChangedSinceTagging

public final boolean hasChangedSinceTagging()
Returns if the content of the object has changed since setting the tag.

Specified by:
hasChangedSinceTagging in interface Taggable
Returns:
If something has changed true else false.

isTagged

public final boolean isTagged()
Returns if the object is currently tagged.

Specified by:
isTagged in interface Taggable
Returns:
If a tag is set true else false.

revertToTag

public final void revertToTag()
Reverts all changes made since setting the tag and clears internal state.

Specified by:
revertToTag in interface Taggable

tag

public final void tag()
Start memorizing changes.

Specified by:
tag in interface Taggable

untag

public final void untag()
Stop memorizing changes and clear internal state. It's not reverting any change! It's simply a "forget all changes".

Specified by:
untag in interface Taggable


Copyright © 2009 Future Invent Informationsmanagement GmbH. All Rights Reserved.