-
Notifications
You must be signed in to change notification settings - Fork 39
/
AbstractStructure.java
35 lines (29 loc) · 1.05 KB
/
AbstractStructure.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
package dev.openfeature.sdk;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" })
abstract class AbstractStructure implements Structure {
protected final Map<String, Value> attributes;
AbstractStructure() {
this.attributes = new HashMap<>();
}
AbstractStructure(Map<String, Value> attributes) {
this.attributes = attributes;
}
/**
* Get all values as their underlying primitives types.
*
* @return all attributes on the structure into a Map
*/
@Override
public Map<String, Object> asObjectMap() {
return attributes
.entrySet()
.stream()
// custom collector, workaround for Collectors.toMap in JDK8
// https://bugs.openjdk.org/browse/JDK-8148463
.collect(HashMap::new,
(accumulated, entry) -> accumulated.put(entry.getKey(), convertValue(entry.getValue())),
HashMap::putAll);
}
}