-
Notifications
You must be signed in to change notification settings - Fork 5
/
EnergyManagementSource.java
73 lines (64 loc) · 2.92 KB
/
EnergyManagementSource.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
/*
* © 2023. 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 edu.ie3.datamodel.exceptions.SourceException;
import edu.ie3.datamodel.io.factory.input.participant.EmInputFactory;
import edu.ie3.datamodel.models.input.OperatorInput;
import edu.ie3.datamodel.models.input.container.EnergyManagementUnits;
import edu.ie3.datamodel.models.input.system.EmInput;
import edu.ie3.datamodel.utils.Try;
import java.util.Set;
public class EnergyManagementSource extends EntitySource {
private final TypeSource typeSource;
private final EmInputFactory emInputFactory;
public EnergyManagementSource(TypeSource typeSource, DataSource dataSource) {
this.typeSource = typeSource;
this.dataSource = dataSource;
this.emInputFactory = new EmInputFactory();
}
@Override
public void validate() {
validate(EmInput.class, emInputFactory);
}
/**
* Returns a unique set of {@link EmInput} 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 EmInput} which has to be checked manually, as
* {@link EmInput#equals(Object)} is NOT restricted on the uuid of {@link EmInput}.
*
* @return a set of object and uuid unique {@link EmInput} entities
*/
public EnergyManagementUnits getEmUnits() throws SourceException {
Set<OperatorInput> operators = typeSource.getOperators();
return getEmUnits(operators);
}
/**
* 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 EmInput} which has to be checked manually, as
* {@link EmInput#equals(Object)} is NOT restricted on the uuid of {@link EmInput}.
*
* <p>In contrast to {@link #getEmUnits()} this method provides the ability to pass in an already
* existing set of {@link OperatorInput} entities, the {@link EmInput} instances depend on. Doing
* so, already loaded nodes can be recycled to improve performance and prevent unnecessary loading
* operations.
*
* <p>If something fails during the creation process a {@link SourceException} is thrown, else a
* set with all entities that has been able to be build is returned.
*
* @param operators a set of object and uuid unique {@link OperatorInput} that should be used for
* the returning instances
* @return a set of object and uuid unique {@link EmInput} entities
*/
public EnergyManagementUnits getEmUnits(Set<OperatorInput> operators) throws SourceException {
Set<EmInput> emUnits =
Try.scanCollection(
buildAssetInputEntities(EmInput.class, emInputFactory, operators), EmInput.class)
.transformF(SourceException::new)
.getOrThrow();
return new EnergyManagementUnits(emUnits);
}
}