From 092d0f893bf2db00301347a50ce401a0c8db5dc3 Mon Sep 17 00:00:00 2001 From: MioRtia Date: Mon, 5 Jul 2021 10:12:20 +0200 Subject: [PATCH] Add methods to get measurements by type (#1782) Signed-off-by: RALAMBOTIANA MIORA --- .../iidm/network/extensions/DiscreteMeasurements.java | 2 ++ .../com/powsybl/iidm/network/extensions/Measurements.java | 2 ++ .../network/impl/extensions/DiscreteMeasurementsImpl.java | 6 ++++++ .../iidm/network/impl/extensions/MeasurementsImpl.java | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/DiscreteMeasurements.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/DiscreteMeasurements.java index 2ee682b7f4b..607d90f74e9 100644 --- a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/DiscreteMeasurements.java +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/DiscreteMeasurements.java @@ -26,6 +26,8 @@ default String getName() { Collection getDiscreteMeasurements(); + Collection getDiscreteMeasurements(DiscreteMeasurement.Type type); + DiscreteMeasurement getDiscreteMeasurement(String id); DiscreteMeasurementAdder newDiscreteMeasurement(); diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/Measurements.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/Measurements.java index f14a7c74c27..6a23174ff61 100644 --- a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/Measurements.java +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/Measurements.java @@ -26,6 +26,8 @@ default String getName() { Collection getMeasurements(); + Collection getMeasurements(Measurement.Type type); + Measurement getMeasurement(String id); MeasurementAdder newMeasurement(); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/DiscreteMeasurementsImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/DiscreteMeasurementsImpl.java index ea71f0cc912..2d601dbf758 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/DiscreteMeasurementsImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/DiscreteMeasurementsImpl.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * @author Miora Ralambotiana @@ -38,6 +39,11 @@ public Collection getDiscreteMeasurements() { return Collections.unmodifiableList(discreteMeasurements); } + @Override + public Collection getDiscreteMeasurements(DiscreteMeasurement.Type type) { + return discreteMeasurements.stream().filter(dm -> dm.getType() == type).collect(Collectors.toList()); + } + @Override public DiscreteMeasurement getDiscreteMeasurement(String id) { return discreteMeasurements.stream() diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/MeasurementsImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/MeasurementsImpl.java index 1efdbcbfc99..e96e377e862 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/MeasurementsImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/MeasurementsImpl.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * @author Miora Ralambotiana @@ -38,6 +39,11 @@ public Collection getMeasurements() { return Collections.unmodifiableList(measurements); } + @Override + public Collection getMeasurements(Measurement.Type type) { + return measurements.stream().filter(m -> m.getType() == type).collect(Collectors.toList()); + } + @Override public Measurement getMeasurement(String id) { return measurements.stream()