Skip to content

Commit

Permalink
gh-3059 stream improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDev404 committed Nov 6, 2023
1 parent 33a5721 commit 8e07f18
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -49,6 +50,7 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.stream.Stream;

public class ApplyViewToElementsFunction implements ContextSpecificMergeFunction<Object, Iterable<Object>, Iterable<Object>> {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplyViewToElementsFunction.class);
Expand Down Expand Up @@ -99,8 +101,12 @@ private static void updateViewWithValidationFromSchema(final Map<String, Object>
final View view = (View) context.get(VIEW);
final Schema schema = (Schema) context.get(SCHEMA);
final View.Builder updatedView = new View.Builder(view);
updatedView.addEdges(getUpdatedViewDefsFromSchemaDefs(view, schema.getEdges()));
updatedView.addEntities(getUpdatedViewDefsFromSchemaDefs(view, schema.getEntities()));

//getUpdatedDefs and add to new view.
getUpdatedViewDefsFromSchemaDefs(schema.getEdges(), view)
.forEach(e -> updatedView.edge(e.getKey(), e.getValue()));
getUpdatedViewDefsFromSchemaDefs(schema.getEntities(), view)
.forEach(e -> updatedView.entity(e.getKey(), e.getValue()));

context.put(VIEW, updatedView.build());
}
Expand Down Expand Up @@ -142,17 +148,9 @@ private static void validate(final Map<String, Object> context) {
}
}

private static HashMap<String, ViewElementDefinition> getUpdatedViewDefsFromSchemaDefs(final View view, final Map<String, ? extends SchemaElementDefinition> elements) {
final HashMap<String, ViewElementDefinition> rtn = new HashMap<>();

for (final Map.Entry<String, ? extends SchemaElementDefinition> schemaElement : elements.entrySet()) {

final String groupName = schemaElement.getKey();
final ViewElementDefinition updatedViewElementDef = getUpdatedViewDefFromSchemaDef(groupName, schemaElement.getValue(), view);

rtn.put(groupName, updatedViewElementDef);
}
return rtn;
private static Stream<Map.Entry<String, ViewElementDefinition>> getUpdatedViewDefsFromSchemaDefs(final Map<String, ? extends SchemaElementDefinition> groupDefs, final View view) {
return groupDefs.entrySet().stream()
.map(e -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), getUpdatedViewDefFromSchemaDef(e.getKey(), e.getValue(), view)));
}

private static ViewElementDefinition getUpdatedViewDefFromSchemaDef(final String groupName, final SchemaElementDefinition schemaElementDef, final View view) {
Expand Down

0 comments on commit 8e07f18

Please sign in to comment.