-
Notifications
You must be signed in to change notification settings - Fork 5
/
ResultEntitySource.java
370 lines (340 loc) · 16 KB
/
ResultEntitySource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.io.source;
import static java.util.Map.entry;
import edu.ie3.datamodel.io.factory.SimpleEntityFactory;
import edu.ie3.datamodel.io.factory.result.*;
import edu.ie3.datamodel.models.result.NodeResult;
import edu.ie3.datamodel.models.result.ResultEntity;
import edu.ie3.datamodel.models.result.connector.LineResult;
import edu.ie3.datamodel.models.result.connector.SwitchResult;
import edu.ie3.datamodel.models.result.connector.Transformer2WResult;
import edu.ie3.datamodel.models.result.connector.Transformer3WResult;
import edu.ie3.datamodel.models.result.system.*;
import edu.ie3.datamodel.models.result.thermal.CylindricalStorageResult;
import edu.ie3.datamodel.models.result.thermal.ThermalHouseResult;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Interface that provides the capability to build entities of type {@link ResultEntity} container
* from .csv files.
*
* @version 0.1
* @since 22 June 2021
*/
public class ResultEntitySource extends EntitySource {
private final SystemParticipantResultFactory systemParticipantResultFactory;
private final ThermalResultFactory thermalResultFactory;
private final SwitchResultFactory switchResultFactory;
private final NodeResultFactory nodeResultFactory;
private final ConnectorResultFactory connectorResultFactory;
private final FlexOptionsResultFactory flexOptionsResultFactory;
public ResultEntitySource(DataSource dataSource) {
this.dataSource = dataSource;
// init factories
this.systemParticipantResultFactory = new SystemParticipantResultFactory();
this.thermalResultFactory = new ThermalResultFactory();
this.switchResultFactory = new SwitchResultFactory();
this.nodeResultFactory = new NodeResultFactory();
this.connectorResultFactory = new ConnectorResultFactory();
this.flexOptionsResultFactory = new FlexOptionsResultFactory();
}
public ResultEntitySource(DataSource dataSource, String dtfPattern) {
this.dataSource = dataSource;
// init factories
this.systemParticipantResultFactory = new SystemParticipantResultFactory(dtfPattern);
this.thermalResultFactory = new ThermalResultFactory();
this.switchResultFactory = new SwitchResultFactory();
this.nodeResultFactory = new NodeResultFactory();
this.connectorResultFactory = new ConnectorResultFactory();
this.flexOptionsResultFactory = new FlexOptionsResultFactory();
}
@Override
public Map<Class<?>, SourceValidator<?>> getValidationMapping() {
return Map.ofEntries(
entry(LoadResult.class, systemParticipantResultFactory),
entry(FixedFeedInResult.class, systemParticipantResultFactory),
entry(BmResult.class, systemParticipantResultFactory),
entry(PvResult.class, systemParticipantResultFactory),
entry(ChpResult.class, systemParticipantResultFactory),
entry(WecResult.class, systemParticipantResultFactory),
entry(StorageResult.class, systemParticipantResultFactory),
entry(EvcsResult.class, systemParticipantResultFactory),
entry(EvResult.class, systemParticipantResultFactory),
entry(HpResult.class, systemParticipantResultFactory),
entry(EmResult.class, systemParticipantResultFactory),
entry(ThermalHouseResult.class, thermalResultFactory),
entry(CylindricalStorageResult.class, thermalResultFactory),
entry(SwitchResult.class, switchResultFactory),
entry(NodeResult.class, nodeResultFactory),
entry(SystemParticipantResult.class, connectorResultFactory),
entry(LineResult.class, connectorResultFactory),
entry(Transformer2WResult.class, connectorResultFactory),
entry(Transformer3WResult.class, connectorResultFactory),
entry(FlexOptionsResult.class, flexOptionsResultFactory));
}
/**
* Returns a unique set of {@link NodeResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link NodeResult} which has to be checked manually,
* as {@link NodeResult#equals(Object)} is NOT restricted by the uuid of {@link NodeResult}.
*
* @return a set of object and uuid unique {@link NodeResult} entities
*/
public Set<NodeResult> getNodeResults() {
return getResultEntities(NodeResult.class, nodeResultFactory);
}
/**
* Returns a unique set of {@link SwitchResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link SwitchResult} which has to be checked
* manually, as {@link SwitchResult#equals(Object)} is NOT restricted by the uuid of {@link
* SwitchResult}.
*
* @return a set of object and uuid unique {@link SwitchResult} entities
*/
public Set<SwitchResult> getSwitchResults() {
return getResultEntities(SwitchResult.class, switchResultFactory);
}
/**
* Returns a unique set of {@link LineResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link LineResult} which has to be checked manually,
* as {@link LineResult#equals(Object)} is NOT restricted by the uuid of {@link LineResult}.
*
* @return a set of object and uuid unique {@link LineResult} entities
*/
public Set<LineResult> getLineResults() {
return getResultEntities(LineResult.class, connectorResultFactory);
}
/**
* Returns a unique set of {@link Transformer2WResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link Transformer2WResult} which has to be checked
* manually, as {@link Transformer2WResult#equals(Object)} is NOT restricted by the uuid of {@link
* Transformer2WResult}.
*
* @return a set of object and uuid unique {@link Transformer2WResult} entities
*/
public Set<Transformer2WResult> getTransformer2WResultResults() {
return getResultEntities(Transformer2WResult.class, connectorResultFactory);
}
/**
* Returns a unique set of {@link Transformer3WResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link Transformer3WResult} which has to be checked
* manually, as {@link Transformer3WResult#equals(Object)} is NOT restricted by the uuid of {@link
* Transformer3WResult}.
*
* @return a set of object and uuid unique {@link Transformer3WResult} entities
*/
public Set<Transformer3WResult> getTransformer3WResultResults() {
return getResultEntities(Transformer3WResult.class, connectorResultFactory);
}
/**
* Returns a unique set of {@link FlexOptionsResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link FlexOptionsResult} which has to be checked
* manually, as {@link FlexOptionsResult#equals(Object)} is NOT restricted by the uuid of {@link
* FlexOptionsResult}.
*
* @return a set of object and uuid unique {@link FlexOptionsResult} entities
*/
public Set<FlexOptionsResult> getFlexOptionsResults() {
return getResultEntities(FlexOptionsResult.class, flexOptionsResultFactory);
}
/**
* Returns a unique set of {@link LoadResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link LoadResult} which has to be checked manually,
* as {@link LoadResult#equals(Object)} is NOT restricted by the uuid of {@link LoadResult}.
*
* @return a set of object and uuid unique {@link LoadResult} entities
*/
public Set<LoadResult> getLoadResults() {
return getResultEntities(LoadResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link PvResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link PvResult} which has to be checked manually,
* as {@link PvResult#equals(Object)} is NOT restricted by the uuid of {@link PvResult}.
*
* @return a set of object and uuid unique {@link PvResult} entities
*/
public Set<PvResult> getPvResults() {
return getResultEntities(PvResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link FixedFeedInResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link FixedFeedInResult} which has to be checked
* manually, as {@link FixedFeedInResult#equals(Object)} is NOT restricted by the uuid of {@link
* FixedFeedInResult}.
*
* @return a set of object and uuid unique {@link FixedFeedInResult} entities
*/
public Set<FixedFeedInResult> getFixedFeedInResults() {
return getResultEntities(FixedFeedInResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link BmResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link BmResult} which has to be checked manually,
* as {@link BmResult#equals(Object)} is NOT restricted by the uuid of {@link BmResult}.
*
* @return a set of object and uuid unique {@link BmResult} entities
*/
public Set<BmResult> getBmResults() {
return getResultEntities(BmResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link ChpResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link ChpResult} which has to be checked manually,
* as {@link ChpResult#equals(Object)} is NOT restricted by the uuid of {@link ChpResult}.
*
* @return a set of object and uuid unique {@link ChpResult} entities
*/
public Set<ChpResult> getChpResults() {
return getResultEntities(ChpResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link WecResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link WecResult} which has to be checked manually,
* as {@link WecResult#equals(Object)} is NOT restricted by the uuid of {@link WecResult}.
*
* @return a set of object and uuid unique {@link WecResult} entities
*/
public Set<WecResult> getWecResults() {
return getResultEntities(WecResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link StorageResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link StorageResult} which has to be checked
* manually, as {@link StorageResult#equals(Object)} is NOT restricted by the uuid of {@link
* StorageResult}.
*
* @return a set of object and uuid unique {@link StorageResult} entities
*/
public Set<StorageResult> getStorageResults() {
return getResultEntities(StorageResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link EvcsResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link EvcsResult} which has to be checked manually,
* as {@link EvcsResult#equals(Object)} is NOT restricted by the uuid of {@link EvcsResult}.
*
* @return a set of object and uuid unique {@link EvcsResult} entities
*/
public Set<EvcsResult> getEvcsResults() {
return getResultEntities(EvcsResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link EvResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link EvResult} which has to be checked manually,
* as {@link EvResult#equals(Object)} is NOT restricted by the uuid of {@link EvResult}.
*
* @return a set of object and uuid unique {@link EvResult} entities
*/
public Set<EvResult> getEvResults() {
return getResultEntities(EvResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link HpResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link HpResult} which has to be checked manually,
* as {@link HpResult#equals(Object)} is NOT restricted by the uuid of {@link HpResult}.
*
* @return a set of object and uuid unique {@link HpResult} entities
*/
public Set<HpResult> getHpResults() {
return getResultEntities(HpResult.class, systemParticipantResultFactory);
}
/**
* Returns a unique set of {@link CylindricalStorageResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link CylindricalStorageResult} which has to be
* checked manually, as {@link CylindricalStorageResult#equals(Object)} is NOT restricted by the
* uuid of {@link CylindricalStorageResult}.
*
* @return a set of object and uuid unique {@link CylindricalStorageResult} entities
*/
public Set<CylindricalStorageResult> getCylindricalStorageResult() {
return getResultEntities(CylindricalStorageResult.class, thermalResultFactory);
}
/**
* Returns a unique set of {@link ThermalHouseResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link ThermalHouseResult} which has to be checked
* manually, as {@link ThermalHouseResult#equals(Object)} is NOT restricted by the uuid of {@link
* ThermalHouseResult}.
*
* @return a set of object and uuid unique {@link ThermalHouseResult} entities
*/
public Set<ThermalHouseResult> getThermalHouseResults() {
return getResultEntities(ThermalHouseResult.class, thermalResultFactory);
}
/**
* Returns a unique set of {@link EmResult} instances.
*
* <p>This set has to be unique in the sense of object uniqueness but also in the sense of {@link
* java.util.UUID} uniqueness of the provided {@link EmResult} which has to be checked manually,
* as {@link EmResult#equals(Object)} is NOT restricted by the uuid of {@link EmResult}.
*
* @return a set of object and uuid unique {@link EmResult} entities
*/
public Set<EmResult> getEmResults() {
return getResultEntities(EmResult.class, systemParticipantResultFactory);
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
private <T extends ResultEntity> Set<T> getResultEntities(
Class<T> entityClass, SimpleEntityFactory<? extends ResultEntity> factory) {
return simpleEntityDataStream(entityClass)
.map(
entityData ->
factory
.get(entityData)
.getData()
.flatMap(loadResult -> cast(entityClass, loadResult)))
.flatMap(Optional::stream)
.collect(Collectors.toSet());
}
private <T extends ResultEntity> Optional<T> cast(
Class<T> entityClass, ResultEntity resultEntity) {
if (resultEntity.getClass().equals(entityClass)) {
// safe here as a) type is checked and b) csv data stream already filters non-fitting input
// data
return Optional.of(entityClass.cast(resultEntity));
} else {
return Optional.empty();
}
}
}