-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFallbackConfiguration.java
More file actions
103 lines (88 loc) · 3.07 KB
/
FallbackConfiguration.java
File metadata and controls
103 lines (88 loc) · 3.07 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
package io.split.android.client.fallback;
import androidx.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public final class FallbackConfiguration {
@Nullable
private final FallbackTreatment mGlobal;
private final Map<String, FallbackTreatment> mByFlag;
private FallbackConfiguration(@Nullable FallbackTreatment global,
@Nullable Map<String, FallbackTreatment> byFlag) {
mGlobal = global;
if (byFlag == null || byFlag.isEmpty()) {
mByFlag = Collections.emptyMap();
} else {
mByFlag = Collections.unmodifiableMap(new HashMap<>(byFlag));
}
}
@Nullable
public FallbackTreatment getGlobal() {
return mGlobal;
}
public Map<String, FallbackTreatment> getByFlag() {
return mByFlag;
}
/**
* Creates a new {@link Builder} for {@link FallbackConfiguration}.
* Use this to provide an optional global fallback and flag-specific fallbacks.
*/
public static Builder builder() {
return new Builder();
}
public static final class Builder {
@Nullable
private FallbackTreatment mGlobal;
@Nullable
private Map<String, FallbackTreatment> mByFlag;
private Builder() {
mGlobal = null;
mByFlag = null;
}
/**
* Sets an optional global fallback treatment to be used when no flag-specific
* fallback exists for a given flag. This value is returned only in place of
* the "control" treatment.
*
* @param global optional global {@link FallbackTreatment}
* @return this builder instance
*/
public Builder global(@Nullable FallbackTreatment global) {
mGlobal = global;
return this;
}
/**
* Sets optional flag-specific fallback treatments, where keys are flag names.
* These take precedence over the global fallback.
*
* @param byFlag map of flag name to {@link FallbackTreatment}; may be null or empty
* @return this builder instance
*/
public Builder byFlag(@Nullable Map<String, FallbackTreatment> byFlag) {
mByFlag = byFlag;
return this;
}
/**
* Builds an immutable {@link FallbackConfiguration} snapshot of the
* configured values.
*
* @return a new immutable {@link FallbackConfiguration}
*/
public FallbackConfiguration build() {
return new FallbackConfiguration(mGlobal, mByFlag);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FallbackConfiguration that = (FallbackConfiguration) o;
return Objects.equals(mGlobal, that.mGlobal) &&
Objects.equals(mByFlag, that.mByFlag);
}
@Override
public int hashCode() {
return Objects.hash(mGlobal, mByFlag);
}
}