E
- any Class
C
- an implementation of Comparable
that is used to compare instance of ComparableElement
public class ComparableElement<E,C extends Comparable> extends Object implements Comparable<ComparableElement<E,C>>
Arrays.sort(...)
without
writing a comparator. Furthermore it helps to speed up the sorting since the
"weight" can be precomputed and does not have to be recomputed in
every comparison.Constructor and Description |
---|
ComparableElement(E o,
C w)
Creates a new
ComparableElement . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ComparableElement<E,C> o) |
E |
getElement()
This method returns the element.
|
C |
getWeight()
This method returns the weight of the element.
|
String |
toString() |
public ComparableElement(E o, C w)
ComparableElement
.o
- the elementw
- the weightpublic E getElement()
public C getWeight()
public int compareTo(ComparableElement<E,C> o) throws ClassCastException
compareTo
in interface Comparable<ComparableElement<E,C extends Comparable>>
ClassCastException