E - Element type
Check if this class is correctly used (performance). Overload modification method to compute the hashCode only once.

public class ComparableSet<E extends Comparable> extends TreeSet<E> implements Comparable<ComparableSet>, Cloneable
This class gives a minimal representation of a comparable set where sets are compared using the lectic order.
This class extends class TreeSet, implements class Comparable and provides a compareTo(org.thegalactic.util.ComparableSet) method that implements the lectic order between two sets.
Therefore, a comparable set can be stored in a sorted collection, and in particular in a sorted set where set operations are provided.
The lectic order extends the inclusion, and is defined only for comparable elements, i.e. elements that can be sorted, as follows:
“a set A is smaller than a set B iff there exists an element in B\A such that any smaller element belonging to A also belongs to B.”
| Constructor and Description |
|---|
ComparableSet()
Constructs a new and empty ComparableSet.
|
ComparableSet(SortedSet<E> set)
Constructs a new ComparableSet with the set from the specified set.
|
| Modifier and Type | Method and Description |
|---|---|
ComparableSet |
clone()
Returns a clone of this component.
|
int |
compareTo(ComparableSet set)
Compares this component with those in parameter according to the lectic order.
|
add, addAll, ceiling, clear, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, spliterator, subSet, subSet, tailSet, tailSetequals, hashCode, removeAllcontainsAll, retainAll, toArray, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, equals, hashCode, removeAll, retainAll, toArray, toArrayparallelStream, removeIf, streampublic ComparableSet clone()
Returns a clone of this component.
clone in class TreeSet<E extends Comparable>public int compareTo(ComparableSet set)
Compares this component with those in parameter according to the lectic order.
The lectic order defines a sort on sets of elements extending the inclusion order as follows:
A set A is smaller than a set B iff there exists an element in B\A such that any smaller element belonging to A also belongs to B. The result is
This comparison method is needed to define a natural and total sort on a sets.
It allows to use sets of this class in a sorted collection
compareTo in interface Comparable<ComparableSet>set - the specified element to be compared with this componentIs this correct? (see test)
Copyright © 2010–2016 The Galactic Organization. All rights reserved.