-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathCoin.java
More file actions
35 lines (28 loc) · 795 Bytes
/
Copy pathCoin.java
File metadata and controls
35 lines (28 loc) · 795 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 vendingmachine.domain;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum Coin {
COIN_500(500),
COIN_100(100),
COIN_50(50),
COIN_10(10);
private final int amount;
Coin(final int amount) {
this.amount = amount;
}
public static List<Integer> getCoinAmounts() {
return Arrays.stream(Coin.values())
.map(coin -> coin.amount)
.collect(Collectors.toList());
}
public static Coin from(int amount) {
return Arrays.stream(Coin.values())
.filter(coin -> coin.amount == amount)
.findFirst()
.orElseThrow(IllegalArgumentException::new);
}
public int getAmount() {
return amount;
}
}