-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardPack.java
More file actions
40 lines (31 loc) · 963 Bytes
/
CardPack.java
File metadata and controls
40 lines (31 loc) · 963 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
36
37
38
39
40
package blackjack.domain.card;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CardPack {
private static final int FRONT = 0;
private static final List<Card> cardPack = create();
private List<Card> cards;
public CardPack() {
this.cards = new ArrayList<>(cardPack);
}
private static List<Card> create() {
final List<Card> cards = new ArrayList<>();
for (final CardSymbol symbol : CardSymbol.values()) {
Arrays.stream(CardType.values())
.forEach(type -> cards.add(new Card(symbol, type)));
}
return new ArrayList<>(cards);
}
public void shuffle() {
Collections.shuffle(cards);
this.cards = new ArrayList<>(cards);
}
public List<Card> getCards() {
return new ArrayList<>(cards);
}
public Card pick() {
return cards.remove(FRONT);
}
}