Skip to content

Commit a372f05

Browse files
committed
iluwatar#355 override toString to log properties
1 parent 32b6473 commit a372f05

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,42 @@
88

99
public abstract class AbstractDocument implements Document {
1010

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+
}
3748

3849
}

0 commit comments

Comments
 (0)