Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Update to some PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pdaulbyscottlogic committed Oct 2, 2019
1 parent 50c4a63 commit 00a8683
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ public Stream<DataBag> generate(FieldSpecGroup group) {

private Field getFirst(FieldSpecGroup keySet) {
Map<Field, Integer> 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<FieldSpec> 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"));
}

Expand Down Expand Up @@ -134,11 +134,11 @@ private FieldSpecGroup adjustBounds(Field generatedField, DataBagValue generated

private FieldSpecGroup adjustBoundsOfDate(Field generatedField, FieldSpec generatedValue, FieldSpecGroup group) {
Set<FieldSpecRelations> nonUpdatedRelations = group.relations().stream()
.filter(relation -> !relation.main().equals(generatedField) && !relation.other().equals(generatedField))
.filter(relation -> !isRelatedToField(generatedField, relation))
.collect(Collectors.toSet());

List<FieldSpecRelations> 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());

Expand Down

0 comments on commit 00a8683

Please sign in to comment.