From 1ccd929cbec70d01f5405c142879bfa5dac718c3 Mon Sep 17 00:00:00 2001 From: Paul Daulby Date: Mon, 2 Sep 2019 16:36:42 +0100 Subject: [PATCH] refactor(#1235): remove wrappedDataBag --- .../FieldSpecGroupValueGenerator.java | 17 +++++---- .../generation/databags/WrappedDataBag.java | 36 ------------------- 2 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 generator/src/main/java/com/scottlogic/deg/generator/generation/databags/WrappedDataBag.java diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldSpecGroupValueGenerator.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldSpecGroupValueGenerator.java index deca8fef2..8cca63a4f 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldSpecGroupValueGenerator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldSpecGroupValueGenerator.java @@ -216,12 +216,15 @@ private static DataBagGroupWrapper acceptNextRandomValue(DataBagGroupWrapper wra } private static Stream acceptNextNonRandomValue(DataBagGroupWrapper wrapper, Field field) { - FieldSpecGroup group = wrapper.group(); - return wrapper.generator().generate(field, group.fieldSpecs().get(field)) - .map(value -> new WrappedDataBag(toDataBag(field, value), value)) - .map(wrapped -> new WrappedDataBag(DataBag.merge(wrapped.dataBag(), wrapper.dataBag()), wrapped.value())) - .map(combined -> new DataBagGroupWrapper( - combined.dataBag(), adjustBounds(field, combined.value(), wrapper.group()), wrapper.generator()) - ); + return wrapper.generator() + .generate(field, wrapper.group().fieldSpecs().get(field)) + .map(value -> getWrappedDataBag(wrapper, field, value)); + } + + private static DataBagGroupWrapper getWrappedDataBag(DataBagGroupWrapper wrapper, Field field, DataBagValue value) { + DataBag dataBag = toDataBag(field, value); + DataBag merged = DataBag.merge(dataBag, wrapper.dataBag()); + + return new DataBagGroupWrapper(merged, adjustBounds(field, value, wrapper.group()), wrapper.generator()); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/WrappedDataBag.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/WrappedDataBag.java deleted file mode 100644 index e43f9e1bc..000000000 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/WrappedDataBag.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.generator.generation.databags; - -public final class WrappedDataBag { - private final DataBag dataBag; - private final DataBagValue value; - - public WrappedDataBag(DataBag dataBag, DataBagValue value) { - this.dataBag = dataBag; - this.value = value; - } - - public DataBag dataBag() { - return dataBag; - } - - public DataBagValue value() { - return value; - } -} -