com.hltech.judged.server.domain.environment.Environment   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
c 0
b 0
f 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllServices() 0 4 1
A getSpaceNames() 0 4 1
A getServices(String) 0 6 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