diff --git a/src/main/java/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInput.java b/src/main/java/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInput.java index 4daf604d7..dd845d57b 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInput.java @@ -13,7 +13,6 @@ import java.util.UUID; import javax.measure.quantity.Temperature; import javax.measure.quantity.Volume; -import org.apache.commons.lang3.NotImplementedException; import tech.units.indriya.ComparableQuantity; /** Thermal storage with cylindrical shape */ @@ -107,10 +106,8 @@ public ComparableQuantity getC() { return c; } - @Override - public UniqueEntityBuilder copy() { - throw new NotImplementedException( - "Copying of " + this.getClass().getSimpleName() + " entities is not supported yet!"); + public CylindricalStorageInputCopyBuilder copy() { + return new CylindricalStorageInputCopyBuilder(this); } @Override @@ -157,4 +154,76 @@ public String toString() { + c + '}'; } + + /** + * A builder pattern based approach to create copies of {@link CylindricalStorageInput} entities + * with altered field values. For detailed field descriptions refer to java docs of {@link + * CylindricalStorageInput} + */ + public static class CylindricalStorageInputCopyBuilder + extends ThermalUnitInput.ThermalUnitInputCopyBuilder { + + private ComparableQuantity storageVolumeLvl; + private ComparableQuantity storageVolumeLvlMin; + private ComparableQuantity inletTemp; + private ComparableQuantity returnTemp; + private ComparableQuantity c; + + private CylindricalStorageInputCopyBuilder(CylindricalStorageInput entity) { + super(entity); + this.storageVolumeLvl = entity.getStorageVolumeLvl(); + this.storageVolumeLvlMin = entity.getStorageVolumeLvlMin(); + this.inletTemp = entity.getInletTemp(); + this.returnTemp = entity.getReturnTemp(); + this.c = entity.getC(); + } + + @Override + public CylindricalStorageInput build() { + return new CylindricalStorageInput( + getUuid(), + getId(), + getOperator(), + getOperationTime(), + getThermalBus(), + storageVolumeLvl, + storageVolumeLvlMin, + inletTemp, + returnTemp, + c); + } + + public CylindricalStorageInputCopyBuilder storageVolumeLvl( + ComparableQuantity storageVolumeLvl) { + this.storageVolumeLvl = storageVolumeLvl; + return this; + } + + public CylindricalStorageInputCopyBuilder storageVolumeLvlMin( + ComparableQuantity storageVolumeLvlMin) { + this.storageVolumeLvlMin = storageVolumeLvlMin; + return this; + } + + public CylindricalStorageInputCopyBuilder inletTemp(ComparableQuantity inletTemp) { + this.inletTemp = inletTemp; + return this; + } + + public CylindricalStorageInputCopyBuilder returnTemp( + ComparableQuantity returnTemp) { + this.returnTemp = returnTemp; + return this; + } + + public CylindricalStorageInputCopyBuilder c(ComparableQuantity c) { + this.c = c; + return this; + } + + @Override + protected CylindricalStorageInputCopyBuilder childInstance() { + return this; + } + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalBusInput.java b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalBusInput.java index 5d497f86d..06b1bf6ee 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalBusInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalBusInput.java @@ -9,7 +9,6 @@ import edu.ie3.datamodel.models.input.AssetInput; import edu.ie3.datamodel.models.input.OperatorInput; import java.util.UUID; -import org.apache.commons.lang3.NotImplementedException; /** A thermal bus, to which different {@link ThermalUnitInput} units may be connected */ public class ThermalBusInput extends AssetInput { @@ -36,9 +35,30 @@ public ThermalBusInput(UUID uuid, String id) { super(uuid, id); } - @Override - public UniqueEntityBuilder copy() { - throw new NotImplementedException( - "Copying of " + this.getClass().getSimpleName() + " entities is not supported yet!"); + public ThermalBusInputCopyBuilder copy() { + return new ThermalBusInputCopyBuilder(this); + } + + /** + * A builder pattern based approach to create copies of {@link ThermalBusInput} entities with + * altered field values. For detailed field descriptions refer to java docs of {@link + * ThermalBusInput} + */ + public static class ThermalBusInputCopyBuilder + extends AssetInput.AssetInputCopyBuilder { + + private ThermalBusInputCopyBuilder(ThermalBusInput entity) { + super(entity); + } + + @Override + public ThermalBusInput build() { + return new ThermalBusInput(getUuid(), getId(), getOperator(), getOperationTime()); + } + + @Override + protected ThermalBusInputCopyBuilder childInstance() { + return this; + } } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalHouseInput.java b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalHouseInput.java index a60b6921c..5cf681e8b 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalHouseInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalHouseInput.java @@ -12,7 +12,6 @@ import edu.ie3.util.quantities.interfaces.ThermalConductance; import java.util.Objects; import java.util.UUID; -import org.apache.commons.lang3.NotImplementedException; import tech.units.indriya.ComparableQuantity; /** Quite simple thermal model of a house to serve as a heat sink */ @@ -70,10 +69,8 @@ public ComparableQuantity getEthCapa() { return ethCapa; } - @Override - public UniqueEntityBuilder copy() { - throw new NotImplementedException( - "Copying of " + this.getClass().getSimpleName() + " entities is not supported yet!"); + public ThermalHouseInputCopyBuilder copy() { + return new ThermalHouseInputCopyBuilder(this); } @Override @@ -109,4 +106,50 @@ public String toString() { + ethCapa + '}'; } + + /** + * A builder pattern based approach to create copies of {@link ThermalHouseInput} entities with + * altered field values. For detailed field descriptions refer to java docs of {@link + * ThermalHouseInput} + */ + public static class ThermalHouseInputCopyBuilder + extends ThermalUnitInput.ThermalUnitInputCopyBuilder { + + private ComparableQuantity ethLosses; + private ComparableQuantity ethCapa; + + private ThermalHouseInputCopyBuilder(ThermalHouseInput entity) { + super(entity); + this.ethLosses = entity.getEthLosses(); + this.ethCapa = entity.getEthCapa(); + } + + @Override + public ThermalHouseInput build() { + return new ThermalHouseInput( + getUuid(), + getId(), + getOperator(), + getOperationTime(), + getThermalBus(), + ethLosses, + ethCapa); + } + + public ThermalHouseInputCopyBuilder ethLosses( + ComparableQuantity ethLosses) { + this.ethLosses = ethLosses; + return this; + } + + public ThermalHouseInputCopyBuilder ethCapa(ComparableQuantity ethCapa) { + this.ethCapa = ethCapa; + return this; + } + + @Override + protected ThermalHouseInputCopyBuilder childInstance() { + return this; + } + } } diff --git a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalUnitInput.java b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalUnitInput.java index fd93265d3..9d4e44891 100644 --- a/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalUnitInput.java +++ b/src/main/java/edu/ie3/datamodel/models/input/thermal/ThermalUnitInput.java @@ -78,4 +78,35 @@ public String toString() { + thermalBus.getUuid() + '}'; } + + /** + * Abstract class for all builders that build child entities of abstract class {@link + * ThermalUnitInput} + */ + protected abstract static class ThermalUnitInputCopyBuilder< + T extends ThermalUnitInput.ThermalUnitInputCopyBuilder> + extends AssetInputCopyBuilder { + + private ThermalBusInput thermalBus; + + protected ThermalUnitInputCopyBuilder(ThermalUnitInput entity) { + super(entity); + this.thermalBus = entity.getThermalBus(); + } + + public T thermalBus(ThermalBusInput thermalBus) { + this.thermalBus = thermalBus; + return childInstance(); + } + + protected ThermalBusInput getThermalBus() { + return thermalBus; + } + + @Override + public abstract ThermalUnitInput build(); + + @Override + protected abstract T childInstance(); + } } diff --git a/src/test/groovy/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInputTest.groovy b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInputTest.groovy new file mode 100644 index 000000000..2cfad9e0e --- /dev/null +++ b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/CylindricalStorageInputTest.groovy @@ -0,0 +1,39 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ +package edu.ie3.datamodel.models.input.thermal + +import edu.ie3.test.common.ThermalUnitInputTestData +import spock.lang.Specification + + +class CylindricalStorageInputTest extends Specification { + + def "A CylindricalStorageInput copy method should work as expected"() { + given: + def cylindricalStorageInput = ThermalUnitInputTestData.cylindricStorageInput + + when: + def alteredUnit = cylindricalStorageInput.copy().storageVolumeLvl(ThermalUnitInputTestData.storageVolumeLvl) + .storageVolumeLvlMin(ThermalUnitInputTestData.storageVolumeLvlMin).inletTemp(ThermalUnitInputTestData.inletTemp) + .returnTemp(ThermalUnitInputTestData.returnTemp).c(ThermalUnitInputTestData.c) + .thermalBus(ThermalUnitInputTestData.thermalBus).build() + + + then: + alteredUnit.with { + assert uuid == cylindricalStorageInput.uuid + assert id == cylindricalStorageInput.id + assert operator == cylindricalStorageInput.operator + assert operationTime == cylindricalStorageInput.operationTime + assert thermalBus == cylindricalStorageInput.thermalBus + assert storageVolumeLvl == ThermalUnitInputTestData.storageVolumeLvl + assert storageVolumeLvlMin == ThermalUnitInputTestData.storageVolumeLvlMin + assert inletTemp == ThermalUnitInputTestData.inletTemp + assert returnTemp == ThermalUnitInputTestData.returnTemp + assert c == ThermalUnitInputTestData.c + } + } +} diff --git a/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalBusInputTest.groovy b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalBusInputTest.groovy new file mode 100644 index 000000000..36db74929 --- /dev/null +++ b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalBusInputTest.groovy @@ -0,0 +1,30 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ +package edu.ie3.datamodel.models.input.thermal + +import edu.ie3.test.common.ThermalUnitInputTestData +import spock.lang.Specification + + +class ThermalBusInputTest extends Specification { + + def "A ThermalBusInput copy method should work as expected"() { + given: + def thermalBusInput = ThermalUnitInputTestData.thermalBus + + when: + def alteredUnit = thermalBusInput.copy().build() + + + then: + alteredUnit.with { + assert uuid == thermalBusInput.uuid + assert id == thermalBusInput.id + assert operator == thermalBusInput.operator + assert operationTime == thermalBusInput.operationTime + } + } +} diff --git a/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalHouseInputTest.groovy b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalHouseInputTest.groovy new file mode 100644 index 000000000..2111ac8ee --- /dev/null +++ b/src/test/groovy/edu/ie3/datamodel/models/input/thermal/ThermalHouseInputTest.groovy @@ -0,0 +1,34 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ +package edu.ie3.datamodel.models.input.thermal + +import edu.ie3.test.common.ThermalUnitInputTestData +import spock.lang.Specification + + +class ThermalHouseInputTest extends Specification { + + def "A ThermalHouseInput copy method should work as expected"() { + given: + def thermalHouseInput = ThermalUnitInputTestData.thermalHouseInput + + when: + def alteredUnit = thermalHouseInput.copy().ethLosses(ThermalUnitInputTestData.thermalConductance) + .ethCapa(ThermalUnitInputTestData.ethCapa).thermalBus(ThermalUnitInputTestData.thermalBus).build() + + + then: + alteredUnit.with { + assert uuid == thermalHouseInput.uuid + assert id == thermalHouseInput.id + assert operator == thermalHouseInput.operator + assert operationTime == thermalHouseInput.operationTime + assert thermalBus == thermalHouseInput.thermalBus + assert ethLosses == ThermalUnitInputTestData.thermalConductance + assert ethCapa == ThermalUnitInputTestData.ethCapa + } + } +}