forked from open-feature/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMutableStructure.java
91 lines (76 loc) · 2.26 KB
/
MutableStructure.java
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
package dev.openfeature.sdk;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* {@link MutableStructure} represents a potentially nested object type which is used to represent
* structured data.
* The MutableStructure is a Structure implementation which is not threadsafe, and whose attributes can
* be modified after instantiation.
*/
@ToString
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType"})
@EqualsAndHashCode(callSuper = true)
public class MutableStructure extends AbstractStructure {
public MutableStructure() {
super();
}
public MutableStructure(Map<String, Value> attributes) {
super(attributes);
}
@Override
public Set<String> keySet() {
return attributes.keySet();
}
// getters
@Override
public Value getValue(String key) {
return attributes.get(key);
}
// adders
public MutableStructure add(String key, Value value) {
attributes.put(key, value);
return this;
}
public MutableStructure add(String key, Boolean value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, String value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, Integer value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, Double value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, Instant value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, Structure value) {
attributes.put(key, new Value(value));
return this;
}
public MutableStructure add(String key, List<Value> value) {
attributes.put(key, new Value(value));
return this;
}
/**
* Get all values.
*
* @return all attributes on the structure
*/
@Override
public Map<String, Value> asMap() {
return new HashMap<>(attributes);
}
}