public class DefaultCardComparator extends java.lang.Object implements CardComparator
A default implementation implementation of CardComparator
based on the ranks of suits and values as defined by the respective
enumerations.
Different games have different game orders and the game definitions
may define their particular card comparator by extending this class,
redefining only the CardValue
comparator, for example.
null
(e.g. jokers).
This class is a singleton to prevent the proliferation of
redundant objects in the application. Extensions of this class
should also be singletons.Modifier and Type | Field and Description |
---|---|
(package private) static DefaultCardComparator |
instance |
Modifier | Constructor and Description |
---|---|
protected |
DefaultCardComparator()
Although a singleton, this class constructor is protected
rather than private to enable its extension.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(Card o1,
Card o2)
Card order used in this game.
|
int |
compare(CardSuit o1,
CardSuit o2)
Implementation of a method similar the
Comparator<CardSuit> interface
using the compareTo() method of Enum . |
int |
compare(CardValue o1,
CardValue o2)
Implementation of a method similar the
Comparator<CardValue> interface
using the the compareTo() method of Enum . |
static DefaultCardComparator |
getInstance()
Single instance if this class.
|
static DefaultCardComparator instance
protected DefaultCardComparator()
public static DefaultCardComparator getInstance()
public int compare(Card o1, Card o2)
compare(CardSuit o1, CardSuit o2)
and/or
compare(CardValue o1, CardValue o2)
.compare
in interface java.util.Comparator<Card>
public int compare(CardSuit o1, CardSuit o2)
Comparator<CardSuit>
interface
using the compareTo()
method of Enum
.compare
in interface CardComparator
o1
- 1st object to compare.o1
- 2nd object to compare.o2
- 2nd object to compare.public int compare(CardValue o1, CardValue o2)
Comparator<CardValue>
interface
using the the compareTo()
method of Enum
.compare
in interface CardComparator
o1
- 1st object to compare.o1
- 2nd object to compare.o2
- 2nd object to compare.