Serializable
, Comparable<Player>
, Comparator<Player>
@Immutable public enum PlayerComparator extends Enum<PlayerComparator> implements Comparator<Player>
Collections.sort(List, Comparator)
, passing in
INSTANCE
as your comparator.
Note: this comparator imposes orderings that are inconsistent with equals,
because any two players that have the same symbol will be treated as equal.
However, all players passed to competitors are uniquely identified by their
symbols, so this is not an issue unless you create your own implementation of
the Player
interface.
Enum Constant | Description |
---|---|
INSTANCE |
The singleton instance of this class.
|
Modifier and Type | Method | Description |
---|---|---|
int |
compare(Player p1,
Player p2) |
|
static PlayerComparator |
valueOf(String name) |
Returns the enum constant of this type with the specified name.
|
static PlayerComparator[] |
values() |
Returns an array containing the constants of this enum type, in
the order they are declared.
|
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public static final PlayerComparator INSTANCE
public static PlayerComparator[] values()
for (PlayerComparator c : PlayerComparator.values()) System.out.println(c);
public static PlayerComparator valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic int compare(Player p1, Player p2)
compare
in interface Comparator<Player>