-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardDeck.java
More file actions
39 lines (30 loc) · 903 Bytes
/
CardDeck.java
File metadata and controls
39 lines (30 loc) · 903 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
package blackjack.domain.card;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CardDeck {
public static final int FIRST_INDEX = 0;
private List<Card> cards;
public CardDeck() {
cards = createCardDeck();
}
private List<Card> createCardDeck() {
List<Card> cards = new ArrayList<>();
for (Shape shape : Shape.values()) {
Arrays.stream(Denomination.values())
.map(denomination -> new Card(shape, denomination))
.forEach(cards::add);
}
return cards;
}
public Card pickOneCard() {
Collections.shuffle(cards);
Card pickedCard = cards.get(FIRST_INDEX);
cards.remove(FIRST_INDEX);
return pickedCard;
}
public List<Card> getCards() {
return new ArrayList<>(cards);
}
}