From f47c83e10e0dee59ec79eb3601ff2eabd84d4d15 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 16:10:26 +0200 Subject: [PATCH 1/6] add specific parse methods --- .../datamodel/models/profile/LoadProfile.java | 29 +++++++++++-------- .../models/profile/StandardLoadProfile.java | 8 ++++- .../TemperatureDependantLoadProfile.java | 10 ++++++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java index b47b65eeb..1fd419234 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java @@ -9,26 +9,17 @@ import java.io.Serializable; import java.util.Arrays; import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.apache.commons.lang3.ArrayUtils; public interface LoadProfile extends Serializable { /** @return The identifying String */ String getKey(); - /** - * Parses the given key to {@link StandardLoadProfile}. - * - * @param key Key to parse - * @return Matching {@link StandardLoadProfile} - * @throws ParsingException If key cannot be parsed - */ - static LoadProfile parse(String key) throws ParsingException { + static LoadProfile parse(LoadProfile[] profiles, String key) throws ParsingException { if (key == null || key.isEmpty()) return LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE; String filterKey = getUniformKey(key); - return Stream.concat( - Arrays.stream(BdewStandardLoadProfile.values()), - Arrays.stream(NbwTemperatureDependantLoadProfile.values())) + return Arrays.stream(profiles) .filter(profile -> profile.getKey().equals(filterKey)) .findFirst() .orElseThrow( @@ -36,6 +27,20 @@ static LoadProfile parse(String key) throws ParsingException { new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); } + /** + * Parses the given key to {@link StandardLoadProfile}. + * + * @param key Key to parse + * @return Matching {@link StandardLoadProfile} + * @throws ParsingException If key cannot be parsed + */ + static LoadProfile parse(String key) throws ParsingException { + return parse( + ArrayUtils.addAll( + BdewStandardLoadProfile.values(), NbwTemperatureDependantLoadProfile.values()), + key); + } + static LoadProfile getProfile(LoadProfile[] profiles, String key) { return Arrays.stream(profiles) .filter(loadProfile -> loadProfile.getKey().equalsIgnoreCase(getUniformKey(key))) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index 22fd9c23b..e2eb3bcce 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries; import edu.ie3.datamodel.models.timeseries.repetitive.RepetitiveTimeSeries; @@ -16,4 +17,9 @@ *

If you intend to provide distinct values, create either an {@link IndividualTimeSeries} or * {@link RepetitiveTimeSeries} and assign it to the model via mapping to the model. */ -public interface StandardLoadProfile extends LoadProfile {} +public interface StandardLoadProfile extends LoadProfile { + + static StandardLoadProfile parse(String key) throws ParsingException { + return (StandardLoadProfile) LoadProfile.parse(BdewStandardLoadProfile.values(), key); + } +} diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index 34f17745f..606b0b1dd 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -5,9 +5,17 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; + /** * Temperature dependant load profiles for night storage heating and heat pumps . The profiles rely * on the VDN description for interruptable loads. For more details see here. */ -public interface TemperatureDependantLoadProfile extends LoadProfile {} +public interface TemperatureDependantLoadProfile extends LoadProfile { + + static NbwTemperatureDependantLoadProfile parse(String key) throws ParsingException { + return (NbwTemperatureDependantLoadProfile) + LoadProfile.parse(NbwTemperatureDependantLoadProfile.values(), key); + } +} From 4222d3903e00d36775ac806269b01de1a4937046 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 16:21:08 +0200 Subject: [PATCH 2/6] Revert "add specific parse methods" This reverts commit f47c83e10e0dee59ec79eb3601ff2eabd84d4d15. --- .../datamodel/models/profile/LoadProfile.java | 29 ++++++++----------- .../models/profile/StandardLoadProfile.java | 8 +---- .../TemperatureDependantLoadProfile.java | 10 +------ 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java index 1fd419234..b47b65eeb 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java @@ -9,24 +9,12 @@ import java.io.Serializable; import java.util.Arrays; import java.util.stream.Collectors; -import org.apache.commons.lang3.ArrayUtils; +import java.util.stream.Stream; public interface LoadProfile extends Serializable { /** @return The identifying String */ String getKey(); - static LoadProfile parse(LoadProfile[] profiles, String key) throws ParsingException { - if (key == null || key.isEmpty()) return LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE; - - String filterKey = getUniformKey(key); - return Arrays.stream(profiles) - .filter(profile -> profile.getKey().equals(filterKey)) - .findFirst() - .orElseThrow( - () -> - new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); - } - /** * Parses the given key to {@link StandardLoadProfile}. * @@ -35,10 +23,17 @@ static LoadProfile parse(LoadProfile[] profiles, String key) throws ParsingExcep * @throws ParsingException If key cannot be parsed */ static LoadProfile parse(String key) throws ParsingException { - return parse( - ArrayUtils.addAll( - BdewStandardLoadProfile.values(), NbwTemperatureDependantLoadProfile.values()), - key); + if (key == null || key.isEmpty()) return LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE; + + String filterKey = getUniformKey(key); + return Stream.concat( + Arrays.stream(BdewStandardLoadProfile.values()), + Arrays.stream(NbwTemperatureDependantLoadProfile.values())) + .filter(profile -> profile.getKey().equals(filterKey)) + .findFirst() + .orElseThrow( + () -> + new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); } static LoadProfile getProfile(LoadProfile[] profiles, String key) { diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index e2eb3bcce..22fd9c23b 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -5,7 +5,6 @@ */ package edu.ie3.datamodel.models.profile; -import edu.ie3.datamodel.exceptions.ParsingException; import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries; import edu.ie3.datamodel.models.timeseries.repetitive.RepetitiveTimeSeries; @@ -17,9 +16,4 @@ *

If you intend to provide distinct values, create either an {@link IndividualTimeSeries} or * {@link RepetitiveTimeSeries} and assign it to the model via mapping to the model. */ -public interface StandardLoadProfile extends LoadProfile { - - static StandardLoadProfile parse(String key) throws ParsingException { - return (StandardLoadProfile) LoadProfile.parse(BdewStandardLoadProfile.values(), key); - } -} +public interface StandardLoadProfile extends LoadProfile {} diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index 606b0b1dd..34f17745f 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -5,17 +5,9 @@ */ package edu.ie3.datamodel.models.profile; -import edu.ie3.datamodel.exceptions.ParsingException; - /** * Temperature dependant load profiles for night storage heating and heat pumps . The profiles rely * on the VDN description for interruptable loads. For more details see here. */ -public interface TemperatureDependantLoadProfile extends LoadProfile { - - static NbwTemperatureDependantLoadProfile parse(String key) throws ParsingException { - return (NbwTemperatureDependantLoadProfile) - LoadProfile.parse(NbwTemperatureDependantLoadProfile.values(), key); - } -} +public interface TemperatureDependantLoadProfile extends LoadProfile {} From c3f55cfff9ea181f1e5cdb06cb5d81344d52ecee Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 16:28:27 +0200 Subject: [PATCH 3/6] parse method --- .../models/profile/StandardLoadProfile.java | 7 ++- .../TemperatureDependantLoadProfile.java | 8 ++- .../datamodel/models/LoadProfileTest.groovy | 53 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index 22fd9c23b..b35de00eb 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -16,4 +16,9 @@ *

If you intend to provide distinct values, create either an {@link IndividualTimeSeries} or * {@link RepetitiveTimeSeries} and assign it to the model via mapping to the model. */ -public interface StandardLoadProfile extends LoadProfile {} +public interface StandardLoadProfile extends LoadProfile { + + static StandardLoadProfile parse(String key) { + return (StandardLoadProfile) LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); + } +} diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index 34f17745f..7fe4f14a5 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -10,4 +10,10 @@ * on the VDN description for interruptable loads. For more details see here. */ -public interface TemperatureDependantLoadProfile extends LoadProfile {} +public interface TemperatureDependantLoadProfile extends LoadProfile { + + static TemperatureDependantLoadProfile parse(String key) { + return (NbwTemperatureDependantLoadProfile) + LoadProfile.getProfile(NbwTemperatureDependantLoadProfile.values(), key); + } +} diff --git a/src/test/groovy/edu/ie3/datamodel/models/LoadProfileTest.groovy b/src/test/groovy/edu/ie3/datamodel/models/LoadProfileTest.groovy index eb4cc959f..60ab5fbbc 100644 --- a/src/test/groovy/edu/ie3/datamodel/models/LoadProfileTest.groovy +++ b/src/test/groovy/edu/ie3/datamodel/models/LoadProfileTest.groovy @@ -9,6 +9,8 @@ import edu.ie3.datamodel.exceptions.ParsingException import edu.ie3.datamodel.models.profile.BdewStandardLoadProfile import edu.ie3.datamodel.models.profile.LoadProfile import edu.ie3.datamodel.models.profile.NbwTemperatureDependantLoadProfile +import edu.ie3.datamodel.models.profile.StandardLoadProfile +import edu.ie3.datamodel.models.profile.TemperatureDependantLoadProfile import spock.lang.Specification class LoadProfileTest extends Specification { @@ -93,6 +95,40 @@ class LoadProfileTest extends Specification { null || LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE } + def "Standard load profiles can be parsed correctly"() { + when: + StandardLoadProfile actual = StandardLoadProfile.parse(key) + + then: + actual == expected + + where: + key || expected + "h0" || BdewStandardLoadProfile.H0 + "h-0" || BdewStandardLoadProfile.H0 + "h_0" || BdewStandardLoadProfile.H0 + "H0" || BdewStandardLoadProfile.H0 + "H-0" || BdewStandardLoadProfile.H0 + "H_0" || BdewStandardLoadProfile.H0 + } + + def "Tempearture dependent load profiles can be parsed correctly"() { + when: + TemperatureDependantLoadProfile actual = TemperatureDependantLoadProfile.parse(key) + + then: + actual == expected + + where: + key || expected + "ep1" || NbwTemperatureDependantLoadProfile.EP1 + "ep_1" || NbwTemperatureDependantLoadProfile.EP1 + "ep_1" || NbwTemperatureDependantLoadProfile.EP1 + "ez2" || NbwTemperatureDependantLoadProfile.EZ2 + "ez-2" || NbwTemperatureDependantLoadProfile.EZ2 + "ez_2" || NbwTemperatureDependantLoadProfile.EZ2 + } + def "BDEW load profiles can be gotten by their key"() { when: BdewStandardLoadProfile actual = BdewStandardLoadProfile.get(key) @@ -113,6 +149,23 @@ class LoadProfileTest extends Specification { "g_1" || BdewStandardLoadProfile.G1 } + def "Nbw temperature dependant load profiles can be parsed correctly"() { + when: + NbwTemperatureDependantLoadProfile actual = NbwTemperatureDependantLoadProfile.get(key) + + then: + actual == expected + + where: + key || expected + "ep1" || NbwTemperatureDependantLoadProfile.EP1 + "ep_1" || NbwTemperatureDependantLoadProfile.EP1 + "ep_1" || NbwTemperatureDependantLoadProfile.EP1 + "ez2" || NbwTemperatureDependantLoadProfile.EZ2 + "ez-2" || NbwTemperatureDependantLoadProfile.EZ2 + "ez_2" || NbwTemperatureDependantLoadProfile.EZ2 + } + def "Nbw temperature dependant load profiles can be gotten by their key"() { when: NbwTemperatureDependantLoadProfile actual = NbwTemperatureDependantLoadProfile.get(key) From 5dd79d4f93d37f07eaf76d0a33b7eead907fccd8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 16:32:55 +0200 Subject: [PATCH 4/6] add documentation --- .../java/edu/ie3/datamodel/models/profile/LoadProfile.java | 6 ++++++ .../ie3/datamodel/models/profile/StandardLoadProfile.java | 5 +++++ .../models/profile/TemperatureDependantLoadProfile.java | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java index b47b65eeb..50c708123 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java @@ -36,6 +36,12 @@ static LoadProfile parse(String key) throws ParsingException { new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); } + /** Looks for load profile with given key and returns it. + * + * @param profiles we search within + * @param key to look for + * @return the matching load profile + */ static LoadProfile getProfile(LoadProfile[] profiles, String key) { return Arrays.stream(profiles) .filter(loadProfile -> loadProfile.getKey().equalsIgnoreCase(getUniformKey(key))) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index b35de00eb..6948189b3 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -18,6 +18,11 @@ */ public interface StandardLoadProfile extends LoadProfile { + /** Returns standard load profile corresponding to the given key. + * + * @param key to look for + * @return the matching standard load profile + */ static StandardLoadProfile parse(String key) { return (StandardLoadProfile) LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); } diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index 7fe4f14a5..1535fd2e3 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -12,6 +12,11 @@ */ public interface TemperatureDependantLoadProfile extends LoadProfile { + /** Returns temperature dependant load profile corresponding to the given key. + * + * @param key to look for + * @return the matching temperature dependant load profile + */ static TemperatureDependantLoadProfile parse(String key) { return (NbwTemperatureDependantLoadProfile) LoadProfile.getProfile(NbwTemperatureDependantLoadProfile.values(), key); From 0dab0d86da8ff5ca14c276a2171f4e3767edcb1e Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jun 2022 16:33:11 +0200 Subject: [PATCH 5/6] fmt --- .../java/edu/ie3/datamodel/models/profile/LoadProfile.java | 3 ++- .../edu/ie3/datamodel/models/profile/StandardLoadProfile.java | 3 ++- .../models/profile/TemperatureDependantLoadProfile.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java index 50c708123..554acbe6d 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java @@ -36,7 +36,8 @@ static LoadProfile parse(String key) throws ParsingException { new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); } - /** Looks for load profile with given key and returns it. + /** + * Looks for load profile with given key and returns it. * * @param profiles we search within * @param key to look for diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index 6948189b3..bad528843 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -18,7 +18,8 @@ */ public interface StandardLoadProfile extends LoadProfile { - /** Returns standard load profile corresponding to the given key. + /** + * Returns standard load profile corresponding to the given key. * * @param key to look for * @return the matching standard load profile diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index 1535fd2e3..e8ab7d925 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -12,7 +12,8 @@ */ public interface TemperatureDependantLoadProfile extends LoadProfile { - /** Returns temperature dependant load profile corresponding to the given key. + /** + * Returns temperature dependant load profile corresponding to the given key. * * @param key to look for * @return the matching temperature dependant load profile From 382d917f03bcfd09ef4e52a336c2a76b2cbe7b75 Mon Sep 17 00:00:00 2001 From: Sebastian Peter Date: Fri, 3 Jun 2022 21:39:29 +0200 Subject: [PATCH 6/6] Load profile parsing without casting --- .../profile/BdewStandardLoadProfile.java | 6 +++-- .../datamodel/models/profile/LoadProfile.java | 26 +++++++++---------- .../NbwTemperatureDependantLoadProfile.java | 7 ++--- .../models/profile/StandardLoadProfile.java | 5 ++-- .../TemperatureDependantLoadProfile.java | 7 ++--- .../{ => profile}/LoadProfileTest.groovy | 9 ++----- 6 files changed, 30 insertions(+), 30 deletions(-) rename src/test/groovy/edu/ie3/datamodel/models/{ => profile}/LoadProfileTest.groovy (93%) diff --git a/src/main/java/edu/ie3/datamodel/models/profile/BdewStandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/BdewStandardLoadProfile.java index e99dc0159..22402733d 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/BdewStandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/BdewStandardLoadProfile.java @@ -5,6 +5,8 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; + /** * German standard electricity load profiles, defined by the bdew (Bundesverband der Energie- und * Wasserwirtschaft; engl.Federal Association of the Energy and Water Industry). For more details @@ -36,8 +38,8 @@ public enum BdewStandardLoadProfile implements StandardLoadProfile { * @return The corresponding bdew load profile or throw {@link IllegalArgumentException}, if no * matching load profile can be found */ - public static BdewStandardLoadProfile get(String key) { - return (BdewStandardLoadProfile) LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); + public static BdewStandardLoadProfile get(String key) throws ParsingException { + return LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); } @Override diff --git a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java index 554acbe6d..5159c9940 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java @@ -9,7 +9,6 @@ import java.io.Serializable; import java.util.Arrays; import java.util.stream.Collectors; -import java.util.stream.Stream; public interface LoadProfile extends Serializable { /** @return The identifying String */ @@ -25,15 +24,16 @@ public interface LoadProfile extends Serializable { static LoadProfile parse(String key) throws ParsingException { if (key == null || key.isEmpty()) return LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE; - String filterKey = getUniformKey(key); - return Stream.concat( - Arrays.stream(BdewStandardLoadProfile.values()), - Arrays.stream(NbwTemperatureDependantLoadProfile.values())) - .filter(profile -> profile.getKey().equals(filterKey)) - .findFirst() - .orElseThrow( - () -> - new ParsingException("Cannot parse \"" + key + "\" to a valid known load profile")); + return LoadProfile.getProfile(getAllProfiles(), key); + } + + static LoadProfile[] getAllProfiles() { + final LoadProfile[][] all = + new LoadProfile[][] { + BdewStandardLoadProfile.values(), NbwTemperatureDependantLoadProfile.values() + }; + + return Arrays.stream(all).flatMap(Arrays::stream).toArray(LoadProfile[]::new); } /** @@ -43,16 +43,16 @@ static LoadProfile parse(String key) throws ParsingException { * @param key to look for * @return the matching load profile */ - static LoadProfile getProfile(LoadProfile[] profiles, String key) { + static T getProfile(T[] profiles, String key) throws ParsingException { return Arrays.stream(profiles) .filter(loadProfile -> loadProfile.getKey().equalsIgnoreCase(getUniformKey(key))) .findFirst() .orElseThrow( () -> - new IllegalArgumentException( + new ParsingException( "No predefined load profile with key '" + key - + "' found. Please provide one of the following keys:" + + "' found. Please provide one of the following keys: " + Arrays.stream(profiles) .map(LoadProfile::getKey) .collect(Collectors.joining(", ")))); diff --git a/src/main/java/edu/ie3/datamodel/models/profile/NbwTemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/NbwTemperatureDependantLoadProfile.java index e32a250ca..783e164bc 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/NbwTemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/NbwTemperatureDependantLoadProfile.java @@ -5,6 +5,8 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; + /** Temperature dependant determined by NBW (accessed 05/2022) */ public enum NbwTemperatureDependantLoadProfile implements TemperatureDependantLoadProfile { // heat pumps @@ -26,9 +28,8 @@ public enum NbwTemperatureDependantLoadProfile implements TemperatureDependantLo * @return The corresponding nbw load profile or throw {@link IllegalArgumentException}, if no * matching load profile can be found */ - public static NbwTemperatureDependantLoadProfile get(String key) { - return (NbwTemperatureDependantLoadProfile) - LoadProfile.getProfile(NbwTemperatureDependantLoadProfile.values(), key); + public static NbwTemperatureDependantLoadProfile get(String key) throws ParsingException { + return LoadProfile.getProfile(NbwTemperatureDependantLoadProfile.values(), key); } @Override diff --git a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java index bad528843..b2878df09 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/StandardLoadProfile.java @@ -5,6 +5,7 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries; import edu.ie3.datamodel.models.timeseries.repetitive.RepetitiveTimeSeries; @@ -24,7 +25,7 @@ public interface StandardLoadProfile extends LoadProfile { * @param key to look for * @return the matching standard load profile */ - static StandardLoadProfile parse(String key) { - return (StandardLoadProfile) LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); + static StandardLoadProfile parse(String key) throws ParsingException { + return LoadProfile.getProfile(BdewStandardLoadProfile.values(), key); } } diff --git a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java index e8ab7d925..4b5a94f20 100644 --- a/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java +++ b/src/main/java/edu/ie3/datamodel/models/profile/TemperatureDependantLoadProfile.java @@ -5,6 +5,8 @@ */ package edu.ie3.datamodel.models.profile; +import edu.ie3.datamodel.exceptions.ParsingException; + /** * Temperature dependant load profiles for night storage heating and heat pumps . The profiles rely * on the VDN description for interruptable loads. For more details see