blob: 1ad4c227d8149cc0910958753099ce90f38a22ea (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision.zone;
import com.yahoo.config.provision.CloudName;
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.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A ZoneList implementation which assumes all zones are controllerManaged.
*
* @author jonmv
*/
public class ZoneFilterMock implements ZoneList {
private final List<ZoneId> zones;
private final boolean negate;
private ZoneFilterMock(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 controllerUpgraded() {
return all();
}
@Override
public ZoneList directlyRouted() {
return all();
}
@Override
public ZoneList reachable() {
return all();
}
@Override
public ZoneList in(Environment... environments) {
return filter(zoneId -> new HashSet<>(Arrays.asList(environments)).contains(zoneId.environment()));
}
@Override
public ZoneList in(RegionName... regions) {
return filter(zoneId -> new HashSet<>(Arrays.asList(regions)).contains(zoneId.region()));
}
@Override
public ZoneList among(ZoneId... zones) {
return filter(zoneId -> new HashSet<>(Arrays.asList(zones)).contains(zoneId));
}
@Override
public List<ZoneId> ids() {
return Collections.unmodifiableList(zones);
}
@Override
public ZoneList ofCloud(CloudName cloud) {
return filter(zoneId -> zoneId.cloud().equals(cloud));
}
private ZoneFilterMock filter(Predicate<ZoneId> condition) {
return new ZoneFilterMock(zones.stream().filter(negate ? condition.negate() : condition).collect(Collectors.toList()), false);
}
}
|