[New] Added ParameterizedElement and ParameterBagContainer .isParamEmpty() and .isParamSet()

This commit is contained in:
Robert von Burg 2022-06-14 11:21:49 +02:00
parent 60438cd743
commit 9400b97ca7
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 88 additions and 2 deletions

View File

@ -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}

View File

@ -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<String, Object> toObjectMap() {
return this.parameterMap.values().stream()
return this.parameterMap.values()
.stream()
.collect(toMap(StrolchElement::getId, (Function<Parameter<?>, Object>) Parameter::getValue));
}