blob: e68bf0ccc243e3cdc9e31849b1423a0d41cc5e79 (
plain) (
blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package com.yahoo.vespa.hosted.controller.api.integration.zone;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A Zones.List implementation which assumes all zones are controllerManaged.
*
* @author jvenstad
*/
public class ZoneFilterMock implements ZoneList {
private final java.util.List<ZoneId> zones;
private final boolean negate;
private ZoneFilterMock(java.util.List<ZoneId> zones, boolean negate) {
this.negate = negate;
this.zones = zones;
}
public static ZoneFilter from(Collection<ZoneId> zones) {
return new ZoneFilterMock(new ArrayList<>(zones), false);
}
@Override
public ZoneList not() {
return new ZoneFilterMock(zones, ! negate);
}
@Override
public ZoneList all() {
return filter(zoneId -> true);
}
@Override
public ZoneList controllerManaged() {
return all();
}
@Override
public ZoneList in(Environment environment) {
return filter(zoneId -> zoneId.environment() == environment);
}
@Override
public ZoneList in(RegionName region) {
return filter(zoneId -> zoneId.region().equals(region));
}
@Override
public ZoneList zones(ZoneId... zones) {
return filter(zoneId -> new HashSet<>(Arrays.asList(zones)).contains(zoneId));
}
@Override
public java.util.List<ZoneId> ids() {
return Collections.unmodifiableList(zones);
}
private ZoneFilterMock filter(Predicate<ZoneId> condition) {
return new ZoneFilterMock(zones.stream().filter(negate ? condition.negate() : condition).collect(Collectors.toList()), false);
}
}
|