Skip to content

Commit 0875c9a

Browse files
refactor with ThermalSystemParticipant to comply with sonar
1 parent 3667253 commit 0875c9a

File tree

8 files changed

+218
-107
lines changed

8 files changed

+218
-107
lines changed

src/main/java/edu/ie3/datamodel/io/factory/input/participant/AcInputEntityData.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
import edu.ie3.datamodel.models.input.system.type.AcTypeInput;
1313
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
1414
import java.util.Map;
15-
import java.util.Objects;
1615

17-
public class AcInputEntityData extends SystemParticipantTypedEntityData<AcTypeInput> {
18-
private final ThermalBusInput thermalBusInput;
16+
public class AcInputEntityData extends ThermalSystemParticipantEntityData<AcTypeInput> {
1917

2018
public AcInputEntityData(
2119
Map<String, String> fieldsToAttributes,
2220
NodeInput node,
2321
EmInput em,
2422
AcTypeInput typeInput,
2523
ThermalBusInput thermalBusInput) {
26-
super(fieldsToAttributes, AcInput.class, node, em, typeInput);
27-
this.thermalBusInput = thermalBusInput;
24+
super(fieldsToAttributes, AcInput.class, node, em, typeInput, thermalBusInput);
2825
}
2926

3027
public AcInputEntityData(
@@ -34,8 +31,7 @@ public AcInputEntityData(
3431
EmInput em,
3532
AcTypeInput typeInput,
3633
ThermalBusInput thermalBusInput) {
37-
super(fieldsToAttributes, AcInput.class, operator, node, em, typeInput);
38-
this.thermalBusInput = thermalBusInput;
34+
super(fieldsToAttributes, AcInput.class, operator, node, em, typeInput, thermalBusInput);
3935
}
4036

4137
/**
@@ -47,42 +43,11 @@ public AcInputEntityData(
4743
*/
4844
public AcInputEntityData(
4945
SystemParticipantTypedEntityData<AcTypeInput> entityData, ThermalBusInput thermalBusInput) {
50-
super(entityData, entityData.getTypeInput());
51-
this.thermalBusInput = thermalBusInput;
52-
}
53-
54-
public ThermalBusInput getThermalBusInput() {
55-
return thermalBusInput;
56-
}
57-
58-
@Override
59-
public boolean equals(Object o) {
60-
if (this == o) return true;
61-
if (!(o instanceof AcInputEntityData that)) return false;
62-
if (!super.equals(o)) return false;
63-
return thermalBusInput.equals(that.thermalBusInput);
64-
}
65-
66-
@Override
67-
public int hashCode() {
68-
return Objects.hash(super.hashCode(), thermalBusInput);
46+
super(entityData, thermalBusInput);
6947
}
7048

7149
@Override
7250
public String toString() {
73-
return "AcInputEntityData{"
74-
+ "thermalBusInput="
75-
+ thermalBusInput.getUuid()
76-
+ ", typeInput="
77-
+ getTypeInput().getUuid()
78-
+ ", node="
79-
+ getNode().getUuid()
80-
+ ", operatorInput="
81-
+ getOperatorInput().getUuid()
82-
+ ", fieldsToValues="
83-
+ getFieldsToValues()
84-
+ ", targetClass="
85-
+ getTargetClass()
86-
+ '}';
51+
return buildToStringContent("AcInputEntityData");
8752
}
8853
}

src/main/java/edu/ie3/datamodel/io/factory/input/participant/AcInputFactory.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,38 @@
1111
import edu.ie3.datamodel.models.input.OperatorInput;
1212
import edu.ie3.datamodel.models.input.system.AcInput;
1313
import edu.ie3.datamodel.models.input.system.characteristic.ReactivePowerCharacteristic;
14+
import edu.ie3.datamodel.models.input.system.type.AcTypeInput;
15+
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
1416
import java.util.UUID;
1517

1618
public class AcInputFactory
17-
extends SystemParticipantInputEntityFactory<AcInput, AcInputEntityData> {
19+
extends ThermalSystemParticipantInputFactory<AcInput, AcInputEntityData> {
1820

1921
public AcInputFactory() {
2022
super(AcInput.class);
2123
}
2224

2325
@Override
24-
protected String[] getAdditionalFields() {
25-
return new String[0];
26-
}
27-
28-
@Override
29-
protected AcInput buildModel(
30-
AcInputEntityData data,
26+
protected AcInput createThermalSystemModel(
3127
UUID uuid,
3228
String id,
29+
OperatorInput operator,
30+
OperationTime operationTime,
3331
NodeInput node,
32+
ThermalBusInput thermalBusInput,
3433
ReactivePowerCharacteristic qCharacteristics,
35-
OperatorInput operator,
36-
OperationTime operationTime) {
37-
final EmInput em = data.getControllingEm().orElse(null);
34+
EmInput em,
35+
Object typeInput) {
3836

3937
return new AcInput(
4038
uuid,
4139
id,
4240
operator,
4341
operationTime,
4442
node,
45-
data.getThermalBusInput(),
43+
thermalBusInput,
4644
qCharacteristics,
4745
em,
48-
data.getTypeInput());
46+
(AcTypeInput) typeInput);
4947
}
5048
}

src/main/java/edu/ie3/datamodel/io/factory/input/participant/HpInputEntityData.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
import edu.ie3.datamodel.models.input.system.type.HpTypeInput;
1313
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
1414
import java.util.Map;
15-
import java.util.Objects;
1615

17-
public class HpInputEntityData extends SystemParticipantTypedEntityData<HpTypeInput> {
18-
private final ThermalBusInput thermalBusInput;
16+
public class HpInputEntityData extends ThermalSystemParticipantEntityData<HpTypeInput> {
1917

2018
public HpInputEntityData(
2119
Map<String, String> fieldsToAttributes,
2220
NodeInput node,
2321
EmInput em,
2422
HpTypeInput typeInput,
2523
ThermalBusInput thermalBusInput) {
26-
super(fieldsToAttributes, HpInput.class, node, em, typeInput);
27-
this.thermalBusInput = thermalBusInput;
24+
super(fieldsToAttributes, HpInput.class, node, em, typeInput, thermalBusInput);
2825
}
2926

3027
public HpInputEntityData(
@@ -34,8 +31,7 @@ public HpInputEntityData(
3431
EmInput em,
3532
HpTypeInput typeInput,
3633
ThermalBusInput thermalBusInput) {
37-
super(fieldsToAttributes, HpInput.class, operator, node, em, typeInput);
38-
this.thermalBusInput = thermalBusInput;
34+
super(fieldsToAttributes, HpInput.class, operator, node, em, typeInput, thermalBusInput);
3935
}
4036

4137
/**
@@ -47,42 +43,11 @@ public HpInputEntityData(
4743
*/
4844
public HpInputEntityData(
4945
SystemParticipantTypedEntityData<HpTypeInput> entityData, ThermalBusInput thermalBusInput) {
50-
super(entityData, entityData.getTypeInput());
51-
this.thermalBusInput = thermalBusInput;
52-
}
53-
54-
public ThermalBusInput getThermalBusInput() {
55-
return thermalBusInput;
56-
}
57-
58-
@Override
59-
public boolean equals(Object o) {
60-
if (this == o) return true;
61-
if (!(o instanceof HpInputEntityData that)) return false;
62-
if (!super.equals(o)) return false;
63-
return thermalBusInput.equals(that.thermalBusInput);
64-
}
65-
66-
@Override
67-
public int hashCode() {
68-
return Objects.hash(super.hashCode(), thermalBusInput);
46+
super(entityData, thermalBusInput);
6947
}
7048

7149
@Override
7250
public String toString() {
73-
return "HpInputEntityData{"
74-
+ "thermalBusInput="
75-
+ thermalBusInput.getUuid()
76-
+ ", typeInput="
77-
+ getTypeInput().getUuid()
78-
+ ", node="
79-
+ getNode().getUuid()
80-
+ ", operatorInput="
81-
+ getOperatorInput().getUuid()
82-
+ ", fieldsToValues="
83-
+ getFieldsToValues()
84-
+ ", targetClass="
85-
+ getTargetClass()
86-
+ '}';
51+
return buildToStringContent("HpInputEntityData");
8752
}
8853
}

src/main/java/edu/ie3/datamodel/io/factory/input/participant/HpInputFactory.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,38 @@
1111
import edu.ie3.datamodel.models.input.OperatorInput;
1212
import edu.ie3.datamodel.models.input.system.HpInput;
1313
import edu.ie3.datamodel.models.input.system.characteristic.ReactivePowerCharacteristic;
14+
import edu.ie3.datamodel.models.input.system.type.HpTypeInput;
15+
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
1416
import java.util.UUID;
1517

1618
public class HpInputFactory
17-
extends SystemParticipantInputEntityFactory<HpInput, HpInputEntityData> {
19+
extends ThermalSystemParticipantInputFactory<HpInput, HpInputEntityData> {
1820

1921
public HpInputFactory() {
2022
super(HpInput.class);
2123
}
2224

2325
@Override
24-
protected String[] getAdditionalFields() {
25-
return new String[0];
26-
}
27-
28-
@Override
29-
protected HpInput buildModel(
30-
HpInputEntityData data,
26+
protected HpInput createThermalSystemModel(
3127
UUID uuid,
3228
String id,
29+
OperatorInput operator,
30+
OperationTime operationTime,
3331
NodeInput node,
32+
ThermalBusInput thermalBusInput,
3433
ReactivePowerCharacteristic qCharacteristics,
35-
OperatorInput operator,
36-
OperationTime operationTime) {
37-
final EmInput em = data.getControllingEm().orElse(null);
34+
EmInput em,
35+
Object typeInput) {
3836

3937
return new HpInput(
4038
uuid,
4139
id,
4240
operator,
4341
operationTime,
4442
node,
45-
data.getThermalBusInput(),
43+
thermalBusInput,
4644
qCharacteristics,
4745
em,
48-
data.getTypeInput());
46+
(HpTypeInput) typeInput);
4947
}
5048
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* © 2021. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.io.factory.input.participant;
7+
8+
import edu.ie3.datamodel.models.UniqueEntity;
9+
import edu.ie3.datamodel.models.input.EmInput;
10+
import edu.ie3.datamodel.models.input.NodeInput;
11+
import edu.ie3.datamodel.models.input.OperatorInput;
12+
import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput;
13+
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
14+
import java.util.Map;
15+
import java.util.Objects;
16+
17+
/**
18+
* Abstract base class for system participants that connect to thermal buses
19+
*
20+
* @param <T> The specific type input for the thermal system participant
21+
*/
22+
public abstract class ThermalSystemParticipantEntityData<T extends SystemParticipantTypeInput>
23+
extends SystemParticipantTypedEntityData<T> {
24+
25+
private final ThermalBusInput thermalBusInput;
26+
27+
protected ThermalSystemParticipantEntityData(
28+
Map<String, String> fieldsToAttributes,
29+
Class<? extends UniqueEntity> targetClass,
30+
NodeInput node,
31+
EmInput em,
32+
T typeInput,
33+
ThermalBusInput thermalBusInput) {
34+
super(fieldsToAttributes, targetClass, node, em, typeInput);
35+
this.thermalBusInput = thermalBusInput;
36+
}
37+
38+
protected ThermalSystemParticipantEntityData(
39+
Map<String, String> fieldsToAttributes,
40+
Class<? extends UniqueEntity> targetClass,
41+
OperatorInput operator,
42+
NodeInput node,
43+
EmInput em,
44+
T typeInput,
45+
ThermalBusInput thermalBusInput) {
46+
super(fieldsToAttributes, targetClass, operator, node, em, typeInput);
47+
this.thermalBusInput = thermalBusInput;
48+
}
49+
50+
/**
51+
* Creates a new ThermalSystemParticipantEntityData object based on a given {@link
52+
* SystemParticipantTypedEntityData} object and given thermal bus input
53+
*
54+
* @param entityData The SystemParticipantTypedEntityData object to enhance
55+
* @param thermalBusInput The thermal bus input
56+
*/
57+
protected ThermalSystemParticipantEntityData(
58+
SystemParticipantTypedEntityData<T> entityData, ThermalBusInput thermalBusInput) {
59+
super(entityData, entityData.getTypeInput());
60+
this.thermalBusInput = thermalBusInput;
61+
}
62+
63+
public ThermalBusInput getThermalBusInput() {
64+
return thermalBusInput;
65+
}
66+
67+
@Override
68+
public boolean equals(Object o) {
69+
if (this == o) return true;
70+
if (!(o instanceof ThermalSystemParticipantEntityData<?> that)) return false;
71+
if (!super.equals(o)) return false;
72+
return Objects.equals(thermalBusInput, that.thermalBusInput);
73+
}
74+
75+
@Override
76+
public int hashCode() {
77+
return Objects.hash(super.hashCode(), thermalBusInput);
78+
}
79+
80+
protected String buildToStringContent(String className) {
81+
return className
82+
+ "{"
83+
+ "thermalBusInput="
84+
+ thermalBusInput.getUuid()
85+
+ ", typeInput="
86+
+ getTypeInput().getUuid()
87+
+ ", node="
88+
+ getNode().getUuid()
89+
+ ", operatorInput="
90+
+ getOperatorInput().getUuid()
91+
+ ", fieldsToValues="
92+
+ getFieldsToValues()
93+
+ ", targetClass="
94+
+ getTargetClass()
95+
+ '}';
96+
}
97+
}

0 commit comments

Comments
 (0)