From 00a86834c4f2d9820f6a62a9987315c5242009b0 Mon Sep 17 00:00:00 2001 From: Paul Daulby Date: Wed, 2 Oct 2019 12:11:16 +0100 Subject: [PATCH] Update to some PR comments --- .../generation/databags/RowSpecDataBagGenerator.java | 11 +---------- .../grouped/FieldSpecGroupValueGenerator.java | 12 ++++++------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGenerator.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGenerator.java index 5f8ff3c4b..573560e3a 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGenerator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGenerator.java @@ -17,21 +17,12 @@ package com.scottlogic.deg.generator.generation.databags; import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.generator.config.detail.CombinationStrategyType; -import com.scottlogic.deg.generator.fieldspecs.FieldSpec; -import com.scottlogic.deg.generator.fieldspecs.FieldSpecGroup; import com.scottlogic.deg.generator.fieldspecs.RowSpec; -import com.scottlogic.deg.generator.fieldspecs.relations.FieldSpecRelations; +import com.scottlogic.deg.generator.generation.combinationstrategies.CombinationStrategy; import com.scottlogic.deg.generator.generation.grouped.FieldSpecGroupValueGenerator; -import com.scottlogic.deg.generator.generation.FieldSpecValueGenerator; import com.scottlogic.deg.generator.generation.grouped.RowSpecGrouper; -import com.scottlogic.deg.generator.generation.combinationstrategies.CombinationStrategy; -import java.util.Map; -import java.util.*; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.Stream; public class RowSpecDataBagGenerator { diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/grouped/FieldSpecGroupValueGenerator.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/grouped/FieldSpecGroupValueGenerator.java index 1724abb88..eeeb8a25c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/grouped/FieldSpecGroupValueGenerator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/grouped/FieldSpecGroupValueGenerator.java @@ -72,20 +72,20 @@ public Stream generate(FieldSpecGroup group) { private Field getFirst(FieldSpecGroup keySet) { Map otherCount = keySet.relations().stream().collect(Collectors.toMap( - r -> r.other(), - r -> 1, (l, r) -> l + r)); + FieldSpecRelations::other, + r -> 1, Integer::sum)); return otherCount.keySet().stream().reduce((l,r)->otherCount.get(l)>otherCount.get(r)?l:r) .orElse(keySet.fieldSpecs().keySet().iterator().next()); } private FieldSpec updateFirstSpecFromRelations(Field first, FieldSpecGroup group) { - Optional optionalFirstFieldSpec = Optional.of(group.fieldSpecs().get(first)); + FieldSpec firstFieldSpec = group.fieldSpecs().get(first); return group.relations().stream() .filter(relation -> isRelatedToField(first, relation)) .map(relation -> createMergedSpecFromRelation(first, relation, group)) .map(Optional::of) - .reduce(optionalFirstFieldSpec, this::mergeOptionalFieldspecs) + .reduce(Optional.of(firstFieldSpec), this::mergeOptionalFieldspecs) .orElseThrow(() -> new IllegalStateException("Failed to merge field specs in related fields")); } @@ -134,11 +134,11 @@ private FieldSpecGroup adjustBounds(Field generatedField, DataBagValue generated private FieldSpecGroup adjustBoundsOfDate(Field generatedField, FieldSpec generatedValue, FieldSpecGroup group) { Set nonUpdatedRelations = group.relations().stream() - .filter(relation -> !relation.main().equals(generatedField) && !relation.other().equals(generatedField)) + .filter(relation -> !isRelatedToField(generatedField, relation)) .collect(Collectors.toSet()); List updatableRelations = group.relations().stream() - .filter(relation -> relation.main().equals(generatedField) || relation.other().equals(generatedField)) + .filter(relation -> isRelatedToField(generatedField, relation)) .map(relations -> relations.other().equals(generatedField) ? relations : relations.inverse()) .collect(Collectors.toList());