common
Class IndexedTreeSetDiff

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet
          extended by common.IndexedTreeSetDiff
All Implemented Interfaces:
IndexedSet, IndexedSetDiff, IndexedSortedSet, SetDiff, java.lang.Iterable, java.util.Collection, java.util.Set, java.util.SortedSet

public class IndexedTreeSetDiff
extends java.util.AbstractSet
implements IndexedSortedSet, IndexedSetDiff

Implementation of the IndexedSortedSet interface that is represented as a set of differences from an underlying IndexedSortedSet.

An IndexedSetDiff will behave correctly if objects are added to the underlying set after the IndexedSetDiff is created, as long as these objects have not also been added to the IndexedSetDiff (then they would be double-counted). Removing objects from the underlying set may cause an IndexedSetDiff to behave incorrectly, because it may change the indices of elements of the underlying set.


Nested Class Summary
 
Nested classes/interfaces inherited from interface common.IndexedSet
IndexedSet.EmptyIndexedSet
 
Field Summary
 
Fields inherited from interface common.IndexedSet
EMPTY_INDEXED_SET
 
Constructor Summary
IndexedTreeSetDiff(IndexedSortedSet underlying)
          Creates a new IndexedTreeSetDiff with the given underlying IndexedSortedSet.
 
Method Summary
 boolean add(java.lang.Object o)
           
 void changeUnderlying()
          Changes the underlying IndexedSet so it is equal to this one, and clears the changes in this IndexedSetDiff.
 void clearChanges()
          Clears the changes in this IndexedSetDiff so it is once again equal to the underlying IndexedSet.
 java.util.Comparator comparator()
           
 boolean contains(java.lang.Object o)
           
 java.lang.Object first()
           
 java.lang.Object get(int index)
          Returns the object with the specified index in this IndexedSet.
 java.util.Set getAdditions()
          Returns the set of objects that are in this set and not the underlying set.
 java.util.Set getRemovals()
          Returns the set of objects that are in the underlying set but not in this set.
 java.util.SortedSet headSet(java.lang.Object toElement)
           
 int indexOf(java.lang.Object o)
          Returns the index of the given object in this IndexedSet, or -1 if this IndexedSet does not contain the given object.
 java.util.Iterator iterator()
           
 java.lang.Object last()
           
static void main(java.lang.String[] args)
          Test program.
 boolean remove(java.lang.Object o)
           
 int size()
           
 java.util.SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
           
 java.util.SortedSet tailSet(java.lang.Object fromElement)
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, 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.Set
addAll, clear, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

IndexedTreeSetDiff

public IndexedTreeSetDiff(IndexedSortedSet underlying)
Creates a new IndexedTreeSetDiff with the given underlying IndexedSortedSet. This set uses the same comparator as the underlying set.

Method Detail

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection

iterator

public 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.Set
Specified by:
iterator in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection

get

public java.lang.Object get(int index)
Description copied from interface: IndexedSet
Returns the object with the specified index in this IndexedSet.

Specified by:
get in interface IndexedSet

indexOf

public int indexOf(java.lang.Object o)
Description copied from interface: IndexedSet
Returns the index of the given object in this IndexedSet, or -1 if this IndexedSet does not contain the given object.

Specified by:
indexOf in interface IndexedSet

comparator

public java.util.Comparator comparator()
Specified by:
comparator in interface java.util.SortedSet

first

public java.lang.Object first()
Specified by:
first in interface java.util.SortedSet

last

public java.lang.Object last()
Specified by:
last in interface java.util.SortedSet

headSet

public java.util.SortedSet headSet(java.lang.Object toElement)
Specified by:
headSet in interface java.util.SortedSet

tailSet

public java.util.SortedSet tailSet(java.lang.Object fromElement)
Specified by:
tailSet in interface java.util.SortedSet

subSet

public java.util.SortedSet subSet(java.lang.Object fromElement,
                                  java.lang.Object toElement)
Specified by:
subSet in interface java.util.SortedSet

getAdditions

public java.util.Set getAdditions()
Returns the set of objects that are in this set and not the underlying set.

Specified by:
getAdditions in interface SetDiff
Returns:
unmodifiable Set of objects

getRemovals

public java.util.Set getRemovals()
Returns the set of objects that are in the underlying set but not in this set.

Specified by:
getRemovals in interface SetDiff

changeUnderlying

public void changeUnderlying()
Changes the underlying IndexedSet so it is equal to this one, and clears the changes in this IndexedSetDiff. Note that his operation may change the indices of some elements.

Specified by:
changeUnderlying in interface SetDiff

clearChanges

public void clearChanges()
Clears the changes in this IndexedSetDiff so it is once again equal to the underlying IndexedSet.

Specified by:
clearChanges in interface SetDiff

main

public static void main(java.lang.String[] args)
Test program.