-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardDeck.java
More file actions
35 lines (28 loc) · 962 Bytes
/
CardDeck.java
File metadata and controls
35 lines (28 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
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
package blackjack.domain.card;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CardDeck {
private static final int FIRST_INDEX = 0;
private static List<Card> cards = new ArrayList<>();
static {
Arrays.stream(CardNumber.values()).forEach(
cardNumber -> Arrays.stream(CardPattern.values()).forEach(
cardPattern -> cards.add(new Card(cardNumber, cardPattern))
)
);
Collections.shuffle(cards);
}
public static Cards pop(final int count) {
List<Card> newCards = new ArrayList<>(cards.subList(FIRST_INDEX, count));
cards = cards.subList(count, cards.size() - count);
return new Cards(newCards);
}
public static Card pop() {
return cards.remove(FIRST_INDEX);
}
public static List<Card> getCards() {
return Collections.unmodifiableList(cards);
}
}