01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package enumeration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
// Typesafe enum (From Bloch)
//
public final class Card {
// Rank of Card
private final Rank rank;
// Suit of Card
private final Suit suit;
// Private constructor: All instances created in the class
private Card(Rank rank, Suit suit) {
this.rank = rank;
this.suit = suit;
}
public String toString() {
return rank + " of " + suit;
}
public int compareRank(Card c) {
return rank.compareTo(c.rank);
}
public int compareSuit(Card c) {
return suit.compareTo(c.suit);
}
public Rank getRank() {
return rank;
}
public int getRankValue() {
return rank.getValue();
}
public Suit getSuit() {
return suit;
}
public static final List<Card> VALUES;
static {
List<Card> values = new ArrayList<Card>(56);
for (Suit s : Suit.VALUES) {
for (Rank r : Rank.VALUES) {
values.add(new Card(r, s));
}
}
VALUES = Collections.unmodifiableList(values);
}
}
|