-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardPack.java
More file actions
35 lines (27 loc) · 836 Bytes
/
CardPack.java
File metadata and controls
35 lines (27 loc) · 836 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 CardPack {
private static final int FRONT = 0;
private final List<Card> cardPack;
public CardPack() {
this.cardPack = create();
}
private 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)));
}
Collections.shuffle(cards);
return new ArrayList<>(cards);
}
public List<Card> getCardPack() {
return Collections.unmodifiableList(cardPack);
}
public Card pick() {
return cardPack.remove(FRONT);
}
}