Class TreeSetGreedy<T extends IComparableProperty>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.TreeSet<T>
-
- info.monitorenter.util.collections.TreeSetGreedy<T>
-
- Type Parameters:
T- the type of instances to store.
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<T>,java.util.Collection<T>,java.util.NavigableSet<T>,java.util.Set<T>,java.util.SortedSet<T>
public class TreeSetGreedy<T extends IComparableProperty> extends java.util.TreeSet<T> implements java.util.Set<T>ASetthat will always successfully add new instances and guarantee that all the "Comparable properties" of the containedinstances will build a set (no duplicates).IComparablePropertyAlthough the interface of
Setis preserved and allows adding anyObjectonlyIComparablePropertyinstances may be added toTreeSetGreedybecause it uses a proprietaryComparator.The added
IComparablePropertyinstances with the lowestNumberproperty (seeIComparableProperty.getComparableProperty()) will be returned first from the retrievableIteratorWarning
If theIComparableProperty(thus meaning the member or accessed data) is changed from outside, the internal order of this set will get corrupted and iterations or add/remove calls may fail. Therefore it is necessary to remove the instance before outside modification and later on add it again.- Author:
- Achim Westermann
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TreeSetGreedy()Creates an instance with an internalComparatorto fulfill the contract of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T o)Attempts to add the the givenT.booleanremove(java.lang.Object o)-
Methods inherited from class java.util.TreeSet
addAll, ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, size, spliterator, subSet, subSet, tailSet, tailSet
-
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
-
-
-
-
Method Detail
-
add
public boolean add(T o)
Attempts to add the the givenT.- Specified by:
addin interfacejava.util.Collection<T extends IComparableProperty>- Specified by:
addin interfacejava.util.Set<T extends IComparableProperty>- Overrides:
addin classjava.util.TreeSet<T extends IComparableProperty>- Parameters:
o- the T to add.- Returns:
- see superclass.
- See Also:
TreeSet.add(java.lang.Object)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<T extends IComparableProperty>- Specified by:
removein interfacejava.util.Set<T extends IComparableProperty>- Overrides:
removein classjava.util.TreeSet<T extends IComparableProperty>- See Also:
TreeSet.remove(java.lang.Object)
-
-