#355 override toString to log properties

This commit is contained in:
qza
2016-06-02 07:27:35 +02:00
parent 32b647323c
commit a372f05e41

View File

@ -8,31 +8,42 @@ import java.util.stream.Stream;
public abstract class AbstractDocument implements Document {
private final Map<String, Object> properties;
private final Map<String, Object> properties;
protected AbstractDocument(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties map is required");
this.properties = properties;
}
protected AbstractDocument(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties map is required");
this.properties = properties;
}
@Override
public Void put(String key, Object value) {
properties.put(key, value);
return null;
}
@Override
public Void put(String key, Object value) {
properties.put(key, value);
return null;
}
@Override
public Object get(String key) {
return properties.get(key);
}
@Override
public Object get(String key) {
return properties.get(key);
}
@Override
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
return Stream.of(get(key))
.filter(el -> el != null)
.map(el -> (List<Map<String, Object>>) el)
.findFirst().get().stream()
.map(constructor);
}
@Override
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
return Stream.of(get(key))
.filter(el -> el != null)
.map(el -> (List<Map<String, Object>>) el)
.findAny().get().stream()
.map(constructor);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getClass().getName()).append("[");
properties.entrySet().forEach(e ->
builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]")
);
builder.append("]");
return builder.toString();
}
}