[New] Added ParameterizedElement and ParameterBagContainer .isParamEmpty() and .isParamSet()
This commit is contained in:
parent
60438cd743
commit
9400b97ca7
|
@ -19,6 +19,66 @@ import li.strolch.utils.time.PeriodDuration;
|
||||||
*/
|
*/
|
||||||
public interface ParameterBagContainer extends StrolchElement {
|
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
|
* Returns the value of the {@link StringParameter} with the given paramKey from the {@link ParameterBag} with the
|
||||||
* ID {@link StrolchModelConstants#BAG_PARAMETERS}
|
* ID {@link StrolchModelConstants#BAG_PARAMETERS}
|
||||||
|
|
|
@ -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
|
* 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)
|
if (this.parameterMap == null)
|
||||||
return Stream.empty();
|
return Stream.empty();
|
||||||
|
|
||||||
return this.parameterMap.values().stream()
|
return this.parameterMap.values()
|
||||||
|
.stream()
|
||||||
.filter(p -> p.getInterpretation().equals(interpretation) && p.getUom().equals(uom));
|
.filter(p -> p.getInterpretation().equals(interpretation) && p.getUom().equals(uom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +1022,8 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
||||||
* Parameters
|
* Parameters
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> toObjectMap() {
|
public Map<String, Object> toObjectMap() {
|
||||||
return this.parameterMap.values().stream()
|
return this.parameterMap.values()
|
||||||
|
.stream()
|
||||||
.collect(toMap(StrolchElement::getId, (Function<Parameter<?>, Object>) Parameter::getValue));
|
.collect(toMap(StrolchElement::getId, (Function<Parameter<?>, Object>) Parameter::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue