-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathComputerStore.java
More file actions
31 lines (27 loc) · 926 Bytes
/
ComputerStore.java
File metadata and controls
31 lines (27 loc) · 926 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
package nextstep.optional;
import java.util.Optional;
import nextstep.optional.Computer.Soundcard;
import nextstep.optional.Computer.USB;
public class ComputerStore {
public static final String UNKNOWN_VERSION = "UNKNOWN";
public static String getVersion(Computer computer) {
String version = UNKNOWN_VERSION;
if (computer != null) {
Soundcard soundcard = computer.getSoundcard();
if (soundcard != null) {
USB usb = soundcard.getUsb();
if (usb != null) {
version = usb.getVersion();
}
}
}
return version;
}
public static String getVersionOptional(Computer computer) {
return Optional.ofNullable(computer)
.map(Computer::getSoundcard)
.map(Soundcard::getUsb)
.map(USB::getVersion)
.orElse(UNKNOWN_VERSION);
}
}