001package enumeration2;
002
003import java.util.ArrayList;
004import java.util.List;
005
006public class Card {
007        public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,
008                SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }
009
010        public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
011
012        private final Rank rank;
013        private final Suit suit;
014        private Card(Rank rank, Suit suit) {
015                this.rank = rank;
016                this.suit = suit;
017        }
018
019        public Rank rank() { return rank; }
020        public Suit suit() { return suit; }
021        public String toString() { return rank + " of " + suit; }
022
023        private static final List<Card> protoDeck = new ArrayList<Card>();
024
025        // Initialize prototype deck
026        static {
027                for (Suit suit : Suit.values())
028                        for (Rank rank : Rank.values())
029                                protoDeck.add(new Card(rank, suit));
030        }
031
032        public static List<Card> newDeck() {
033                return new ArrayList<Card>(protoDeck); // Return copy of prototype deck
034        }
035}