diff --git a/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java b/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java index e16bc40cc..2a70fb419 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java +++ b/li.strolch.model/src/main/java/li/strolch/model/ParameterBagContainer.java @@ -19,6 +19,66 @@ import li.strolch.utils.time.PeriodDuration; */ public interface ParameterBagContainer extends StrolchElement { + /** + * Returns true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + * + * @param paramKey + * the parameter to check if it is empty + * + * @return true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + */ + default boolean isParamEmpty(String paramKey) { + return !this.hasParameter(paramKey) || getParameter(paramKey).isEmpty(); + } + + /** + * Returns true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + * + * @param bagKey + * the key from which {@link ParameterBag} to get the parameter + * @param paramKey + * the parameter to check if it is empty + * + * @return true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + */ + default boolean isParamEmpty(String bagKey, String paramKey) { + return !this.hasParameter(bagKey, paramKey) || getParameter(bagKey, paramKey).isEmpty(); + } + + /** + * Returns true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + * + * @param paramKey + * the parameter to check if it has a value + * + * @return true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + */ + default boolean isParamSet(String paramKey) { + return this.hasParameter(paramKey) && getParameter(paramKey).isSet(); + } + + /** + * Returns true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + * + * @param bagKey + * the key from which {@link ParameterBag} to get the parameter + * @param paramKey + * the parameter to check if it has a value + * + * @return true if the parameter with the given key on the {@link ParameterBag} with the id + * {@link StrolchModelConstants#BAG_PARAMETERS} exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + */ + default boolean isParamSet(String bagKey, String paramKey) { + return this.hasParameter(bagKey, paramKey) && getParameter(bagKey, paramKey).isSet(); + } + /** * Returns the value of the {@link StringParameter} with the given paramKey from the {@link ParameterBag} with the * ID {@link StrolchModelConstants#BAG_PARAMETERS} diff --git a/li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java b/li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java index 7529293b3..7c4f62333 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/ParameterizedElement.java @@ -92,6 +92,30 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { /// /// + /** + * Returns true if the parameter with the given key does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + * + * @param paramKey + * the parameter to check if it is empty + * + * @return true if the parameter with the given key does not exist or the value is empty, i.e. {@link Parameter#isEmpty()} returns true + */ + public boolean isParamEmpty(String paramKey) { + return !this.hasParameter(paramKey) || getParameter(paramKey).isEmpty(); + } + + /** + * Returns true if the parameter with the given key exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + * + * @param paramKey + * the parameter to check if it has a value + * + * @return true if the parameter with the given key exists and the value is not empty, i.e. {@link Parameter#isSet()} returns true + */ + public boolean isParamSet(String paramKey) { + return this.hasParameter(paramKey) && getParameter(paramKey).isSet(); + } + /** * Returns the value of the {@link StringParameter} with the given paramKey * @@ -925,7 +949,8 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { if (this.parameterMap == null) return Stream.empty(); - return this.parameterMap.values().stream() + return this.parameterMap.values() + .stream() .filter(p -> p.getInterpretation().equals(interpretation) && p.getUom().equals(uom)); } @@ -997,7 +1022,8 @@ public abstract class ParameterizedElement extends AbstractStrolchElement { * Parameters */ public Map toObjectMap() { - return this.parameterMap.values().stream() + return this.parameterMap.values() + .stream() .collect(toMap(StrolchElement::getId, (Function, Object>) Parameter::getValue)); }