getSpaceNames()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
1
package com.hltech.judged.server.domain.environment;
2
3
import com.hltech.judged.server.domain.ServiceId;
4
import lombok.Getter;
5
import lombok.RequiredArgsConstructor;
6
7
import java.util.HashSet;
8
import java.util.Set;
9
import java.util.stream.Collectors;
10
11
12
@Getter
13
@RequiredArgsConstructor
14
public class Environment {
15
16
    public static final String DEFAULT_NAMESPACE = "default";
17
18
    private final String name;
19
    private final Set<Space> spaces;
20
21
    public Set<String> getSpaceNames() {
22
        return spaces.stream()
23
            .map(Space::getName)
24
            .collect(Collectors.toUnmodifiableSet());
25
    }
26
27
    public Set<ServiceId> getServices(String spaceName) {
28
       return spaces.stream()
29
           .filter(space -> space.getName().equals(spaceName))
30
           .findAny()
31
           .map(Space::getServiceIds)
32
           .orElse(new HashSet<>());
33
    }
34
35
    public Set<ServiceId> getAllServices() {
36
        return spaces.stream()
37
            .flatMap(space -> space.getServiceIds().stream())
38
            .collect(Collectors.toUnmodifiableSet());
39
    }
40
}
41