|
8 | 8 |
|
9 | 9 | public abstract class AbstractDocument implements Document {
|
10 | 10 |
|
11 |
| - private final Map<String, Object> properties; |
12 |
| - |
13 |
| - protected AbstractDocument(Map<String, Object> properties) { |
14 |
| - Objects.requireNonNull(properties, "properties map is required"); |
15 |
| - this.properties = properties; |
16 |
| - } |
17 |
| - |
18 |
| - @Override |
19 |
| - public Void put(String key, Object value) { |
20 |
| - properties.put(key, value); |
21 |
| - return null; |
22 |
| - } |
23 |
| - |
24 |
| - @Override |
25 |
| - public Object get(String key) { |
26 |
| - return properties.get(key); |
27 |
| - } |
28 |
| - |
29 |
| - @Override |
30 |
| - public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) { |
31 |
| - return Stream.of(get(key)) |
32 |
| - .filter(el -> el != null) |
33 |
| - .map(el -> (List<Map<String, Object>>) el) |
34 |
| - .findFirst().get().stream() |
35 |
| - .map(constructor); |
36 |
| - } |
| 11 | + private final Map<String, Object> properties; |
| 12 | + |
| 13 | + protected AbstractDocument(Map<String, Object> properties) { |
| 14 | + Objects.requireNonNull(properties, "properties map is required"); |
| 15 | + this.properties = properties; |
| 16 | + } |
| 17 | + |
| 18 | + @Override |
| 19 | + public Void put(String key, Object value) { |
| 20 | + properties.put(key, value); |
| 21 | + return null; |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public Object get(String key) { |
| 26 | + return properties.get(key); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) { |
| 31 | + return Stream.of(get(key)) |
| 32 | + .filter(el -> el != null) |
| 33 | + .map(el -> (List<Map<String, Object>>) el) |
| 34 | + .findAny().get().stream() |
| 35 | + .map(constructor); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public String toString() { |
| 40 | + final StringBuilder builder = new StringBuilder(); |
| 41 | + builder.append(getClass().getName()).append("["); |
| 42 | + properties.entrySet().forEach(e -> |
| 43 | + builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]") |
| 44 | + ); |
| 45 | + builder.append("]"); |
| 46 | + return builder.toString(); |
| 47 | + } |
37 | 48 |
|
38 | 49 | }
|
0 commit comments