|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.sort.SortKey<E> edu.nrao.sss.sort.EnumSortKey<E>
public abstract class EnumSortKey<E extends Enum<E>>
A sort key for enumerations
.
Comparator
. The main job of the subclass
is to provide the integers to this parent class. Example:
/** * Sorts players according to the hand with which they bat. */ public class PlayerBattingHandKey extends EnumSortKey<Handedness> implements Comparator<Player> { public int compare(Player p1, Player p2) { return compareObjects(p1.getBattingHand() p2.getBattingHand()); } }
Clients of the example PlayerBattingHandKey class are able to
configure that comparator via the SortKey.setOrder(SortOrder)
method,
something they cannot do with the plain Comparator interface.
They may then place instances of this class in a
CompoundComparator
.
Version Info:
$Revision: 593 $ |
$Date: 2007-05-07 15:54:14 -0600 (Mon, 07 May 2007) $ |
$Author: dharland $ |
Constructor Summary | |
---|---|
protected |
EnumSortKey()
Helps create a new instance. |
Method Summary | |
---|---|
protected int |
compareAscending(E o1,
E o2)
Uses the natural ordering of E . |
protected int |
compareCustom(E o1,
E o2)
Uses a client-specified ordering |
protected int |
compareNatural(E o1,
E o2)
Uses the natural ordering of E . |
protected int |
compareObjects(E o1,
E o2,
SortOrder ordering)
Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in according to t he given sort order. |
void |
setCustomOrder(List<E> ordering)
Sets the ordering for this sort key. |
Methods inherited from class edu.nrao.sss.sort.SortKey |
---|
compareObjects, getOrder, nullOrdering, objectsAreEqual, setOrder |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected EnumSortKey()
Method Detail |
---|
public void setCustomOrder(List<E> ordering)
The list of elements should contain no more than one occurrence of a given element. Additional occurrences after the first are permitted but will be ignored. The list need not have an occurrence of every element of the enumeration. Any elements not present in the list will be deemed to be greater than an element that is in the list. A comparison between two unlisted elements will result in a tie.
The custom ordering provided here will be used only when the
sort order is set
to
SortOrder.CUSTOM
.
This method will not save a reference to ordering
, so any changes
made to the list after this method is called will not be reflected in
this object.
ordering
- a list containing elements of an enumeration in the order
in which this key should sort them.protected int compareObjects(E o1, E o2, SortOrder ordering)
compareObjects
in class SortKey<E extends Enum<E>>
protected int compareNatural(E o1, E o2)
E
.
compareNatural
in class SortKey<E extends Enum<E>>
protected int compareAscending(E o1, E o2)
E
.
compareAscending
in class SortKey<E extends Enum<E>>
protected int compareCustom(E o1, E o2)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |