org.decisiondeck.xmcda_oo.utils
Class ExternalOrderingSet<E>

java.lang.Object
  extended by org.decisiondeck.xmcda_oo.utils.ExternalOrderingSet<E>
Type Parameters:
E - the elements to include in this set.
All Implemented Interfaces:
Iterable<E>, Collection<E>, NavigableSet<E>, Set<E>, SortedSet<E>

public class ExternalOrderingSet<E>
extends Object
implements NavigableSet<E>

TODO consider using some special interface instead of NavigableSet, because e.g. floor is not really supported, and more generally asking for arbitrary object ordering information is not supported (only those objects already known). Maybe simply use ListOrderedSet? Own interface could also support additions through the NavigableSet.subSet(Object, Object) method.

TODO Document more.

Caution: contains(Object) work on every object; most methods work only on objects contained in this object.


Method Summary
 boolean add(E e)
           This method is implemented for compatibility with Set but should not be used with this object.
 void addAfter(E previous, E toAdd)
           
 boolean addAll(Collection<? extends E> c)
           This method is implemented for compatibility with Set but should not be used with this object.
 void addAsBest(E e)
           
 void addAsWorst(E e)
           
 void addInBetween(E previous, E e, E next)
           
 E ceiling(E e)
           
 void clear()
           
 Comparator<? super E> comparator()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
static
<E> ExternalOrderingSet<E>
create()
           
static
<E> ExternalOrderingSet<E>
create(Collection<E> order)
          Creates a new object initialized with the given collection, in order of iteration.
 Iterator<E> descendingIterator()
           
 NavigableSet<E> descendingSet()
          TODO not supported writing to it!
 boolean equals(Object o)
           
 E first()
           
 E floor(E e)
           
 int hashCode()
           
 SortedSet<E> headSet(E toElement)
           
 NavigableSet<E> headSet(E toElement, boolean inclusive)
           
 E higher(E e)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 E last()
           
 E lower(E e)
           
 E pollFirst()
           
 E pollLast()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 void replace(E oldElement, E newElement)
           
 void resetOrder(Collection<E> newOrder)
          Changes the ordering of this set.
 boolean retainAll(Collection<?> c)
           This method is implemented for compatibility with Set but should not be used with this object.
 int size()
           
 NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
           
 SortedSet<E> subSet(E fromElement, E toElement)
           
 SortedSet<E> tailSet(E fromElement)
           
 NavigableSet<E> tailSet(E fromElement, boolean inclusive)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public boolean add(E e)

This method is implemented for compatibility with Set but should not be used with this object.

Ordering information must be given with any new element added as this object does not know otherwise how to treat them compared to the other elements. Please use rather addAsBest(Object) or addInBetween(Object, Object, Object).

Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Parameters:
e -
Returns:
nothing.
Throws:
UnsupportedOperationException - always.

addAll

public boolean addAll(Collection<? extends E> c)

This method is implemented for compatibility with Set but should not be used with this object.

Ordering information must be given with any new element added as this object does not know otherwise how to treat them compared to the other elements. Please use rather addAsBest(Object) or addInBetween(Object, Object, Object).

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>
Parameters:
c -
Returns:
nothing.
Throws:
UnsupportedOperationException - always.

addAsBest

public void addAsBest(E e)

addInBetween

public void addInBetween(E previous,
                         E e,
                         E next)

addAfter

public void addAfter(E previous,
                     E toAdd)

ceiling

public E ceiling(E e)
Specified by:
ceiling in interface NavigableSet<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>

comparator

public Comparator<? super E> comparator()
Specified by:
comparator in interface SortedSet<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface Set<E>

descendingIterator

public Iterator<E> descendingIterator()
Specified by:
descendingIterator in interface NavigableSet<E>

descendingSet

public NavigableSet<E> descendingSet()
TODO not supported writing to it! (Others: same!)

Specified by:
descendingSet in interface NavigableSet<E>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Specified by:
equals in interface Set<E>
Overrides:
equals in class Object

first

public E first()
Specified by:
first in interface SortedSet<E>

floor

public E floor(E e)
Specified by:
floor in interface NavigableSet<E>

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface Set<E>
Overrides:
hashCode in class Object

headSet

public NavigableSet<E> headSet(E toElement,
                               boolean inclusive)
Specified by:
headSet in interface NavigableSet<E>

headSet

public SortedSet<E> headSet(E toElement)
Specified by:
headSet in interface NavigableSet<E>
Specified by:
headSet in interface SortedSet<E>

higher

public E higher(E e)
Specified by:
higher in interface NavigableSet<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface NavigableSet<E>
Specified by:
iterator in interface Set<E>

last

public E last()
Specified by:
last in interface SortedSet<E>

lower

public E lower(E e)
Specified by:
lower in interface NavigableSet<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface Set<E>

retainAll

public boolean retainAll(Collection<?> c)

This method is implemented for compatibility with Set but should not be used with this object.

Ordering information must be given with any new element added as this object does not know otherwise how to treat them compared to the other elements. Please use rather addAsBest(Object) or addInBetween(Object, Object, Object).

Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface Set<E>
Parameters:
c -
Returns:
nothing.
Throws:
UnsupportedOperationException - always.

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>

subSet

public NavigableSet<E> subSet(E fromElement,
                              boolean fromInclusive,
                              E toElement,
                              boolean toInclusive)
Specified by:
subSet in interface NavigableSet<E>

subSet

public SortedSet<E> subSet(E fromElement,
                           E toElement)
Specified by:
subSet in interface NavigableSet<E>
Specified by:
subSet in interface SortedSet<E>

tailSet

public NavigableSet<E> tailSet(E fromElement,
                               boolean inclusive)
Specified by:
tailSet in interface NavigableSet<E>

tailSet

public SortedSet<E> tailSet(E fromElement)
Specified by:
tailSet in interface NavigableSet<E>
Specified by:
tailSet in interface SortedSet<E>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface Set<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface Set<E>

pollFirst

public E pollFirst()
Specified by:
pollFirst in interface NavigableSet<E>

pollLast

public E pollLast()
Specified by:
pollLast in interface NavigableSet<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>

create

public static <E> ExternalOrderingSet<E> create()

create

public static <E> ExternalOrderingSet<E> create(Collection<E> order)
Creates a new object initialized with the given collection, in order of iteration. The content of the collection is used to define the universe of objects initially contained in the returned set, and the order of iteration on the given collection is used to define the order on that set of objects.

Type Parameters:
E - the type of the elements in the created set.
Parameters:
order - not null. May be empty (in which case this comparator will not be able to compare any objects until elements are added). One of the collection element may be null element (which counts as a normal element for this object). The collection may not contain duplicate elements. It is recommended to use a SortedSet when possible to ensure a correct iteration order and no duplicate.
Returns:
a new object.

replace

public void replace(E oldElement,
                    E newElement)

addAsWorst

public void addAsWorst(E e)

resetOrder

public void resetOrder(Collection<E> newOrder)
Changes the ordering of this set. The set of elements in this set is not changed by this method, only their order.

Parameters:
newOrder - not null, no duplicate allowed.


Copyright © 2011. All Rights Reserved.