org.gcube.vremanagement.resourcebroker.impl.support.types
Class SortableElement<V extends java.lang.Comparable<V>,T>
java.lang.Object
org.gcube.vremanagement.resourcebroker.impl.support.types.SortableElement<V,T>
- All Implemented Interfaces:
- java.lang.Comparable<SortableElement<V,T>>
- Direct Known Subclasses:
- GHNDescriptor, GHNReservation
public class SortableElement<V extends java.lang.Comparable<V>,T>
- extends java.lang.Object
- implements java.lang.Comparable<SortableElement<V,T>>
Generic container for sortable elements.
Wraps generic elements inside it and is built up an index that
is used to apply sorting algorithms.
Example:
// This example applies sorting on Tuple
elements
TreeSet
<SortableElement<?>> sortingTable = new TreeSet<SortableElement<?>>();
sortingTable.add(new SortableElement<Tuple<String>>(3, new Tuple<String>("Hello", "My element")));
sortingTable.add(new SortableElement<Tuple<String>>(1, new Tuple<String>("I am an element", "My element")));
sortingTable.add(new SortableElement<Tuple<String>>(2, new Tuple<String>("I am an element too", "My third element")));
sortingTable.add(new SortableElement<Tuple<String>>(0, new Tuple<String>("I should be the first", "My first element")));
sortingTable.add(new SortableElement<Tuple<String>>(7, new Tuple<String>("I should be the last", "Name", "surname")));
Other usages (on demand sorting):
List
<SortableElement> sortableList = new Vector<SortableElement>();
Collections.sort(java.util.List)
(sortableList);
- Author:
- Daniele Strollo (ISTI-CNR)
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
SortableElement
public SortableElement(V sortIdx,
T elem)
getSortIndex
public V getSortIndex()
getElement
public final T getElement()
toString
public final java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
compareTo
public final int compareTo(SortableElement<V,T> o)
- Specified by:
compareTo
in interface java.lang.Comparable<SortableElement<V extends java.lang.Comparable<V>,T>>