Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.iluwatar.abstractdocument;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -39,7 +38,7 @@ public abstract class AbstractDocument implements Document {
protected AbstractDocument(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties map is required");
this.documentProperties = properties;
}
} // indentation fixed

@Override
public Void put(String key, Object value) {
Expand All @@ -52,15 +51,19 @@ public Object get(String key) {
return documentProperties.get(key);
}

@SuppressWarnings("unchecked")
@Override
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> childConstructor) {
return Stream.ofNullable(get(key))
.filter(Objects::nonNull)
.map(el -> (List<Map<String, Object>>) el)
.findAny()
.stream()
.flatMap(Collection::stream)
.map(childConstructor);
Object value = get(key);
if (value instanceof List<?>) {
return ((List<?>) value)
.stream()
.filter(
e -> e instanceof Map) // Only keeping items that are actually maps before casting
.map(e -> (Map<String, Object>) e)
.map(childConstructor);
}
return Stream.empty();
}

@Override
Expand Down
37 changes: 37 additions & 0 deletions tyle apply spotless formatting
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java b/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java
index 41bfb2353..55584d94d 100644
--- a/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java
+++ b/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java
@@ -51,19 +51,20 @@ public abstract class AbstractDocument implements Document {
return documentProperties.get(key);
}

-@SuppressWarnings("unchecked")
-@Override
-public <T> Stream<T> children(String key, Function<Map<String, Object>, T> childConstructor) {
- Object value = get(key);
- if (value instanceof List<?>) {
- return ((List<?>) value).stream()
- .filter(e -> e instanceof Map) // Only keeping items that are actually maps before casting
- .map(e -> (Map<String, Object>) e)
- .map(childConstructor);
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> Stream<T> children(String key, Function<Map<String, Object>, T> childConstructor) {
+ Object value = get(key);
+ if (value instanceof List<?>) {
+ return ((List<?>) value)
+ .stream()
+ .filter(
+ e -> e instanceof Map) // Only keeping items that are actually maps before casting
+ .map(e -> (Map<String, Object>) e)
+ .map(childConstructor);
+ }
+ return Stream.empty();
}
- return Stream.empty();
-}
-

@Override
public String toString() {
Loading