diff --git a/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 7449bcf0f..af926317b 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -331,6 +331,31 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement return streamOfParametersByInterpretationAndUom(bagKey, interpretation, uom).collect(toList()); } + /** + * Adds a new {@link Parameter} to the {@link ParameterBag} with the key {@link + * StrolchModelConstants#BAG_PARAMETERS} + * + * @param parameter + * the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException + * if the {@link ParameterBag} does not exist + */ + @Override + public void addParameter(Parameter parameter) throws StrolchException { + assertNotReadonly(); + if (this.parameterBagMap == null) + this.parameterBagMap = new HashMap<>(1, 1.0F); + ParameterBag bag = this.parameterBagMap.get(BAG_PARAMETERS); + if (bag == null) { + String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, BAG_PARAMETERS); + throw new StrolchException(msg); + } + + bag.addParameter(parameter); + } + /** * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key * @@ -357,6 +382,28 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement bag.addParameter(parameter); } + /** + * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the key {@link + * StrolchModelConstants#BAG_PARAMETERS} + * + * @param paramKey + * the key of the {@link Parameter} which is to be removed + * + * @return the removed {@link Parameter} or null if it did not exist + */ + @Override + public > T removeParameter(String paramKey) { + assertNotReadonly(); + if (this.parameterBagMap == null) + return null; + ParameterBag bag = this.parameterBagMap.get(BAG_PARAMETERS); + if (bag == null) { + return null; + } + + return bag.removeParameter(paramKey); + } + /** * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey * 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 72678e218..329b73b79 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 @@ -186,6 +186,18 @@ public interface ParameterBagContainer extends StrolchElement { */ List> getParametersByInterpretationAndUom(String bagKey, String interpretation, String uom); + /** + * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key {@link + * StrolchModelConstants#BAG_PARAMETERS} + * + * @param parameter + * the {@link Parameter} to be added to the {@link ParameterBag} + * + * @throws StrolchException + * if the {@link ParameterBag} does not exist + */ + void addParameter(Parameter parameter) throws StrolchException; + /** * Adds a new {@link Parameter} to the {@link ParameterBag} with the given key * @@ -199,6 +211,17 @@ public interface ParameterBagContainer extends StrolchElement { */ void addParameter(String bagKey, Parameter parameter) throws StrolchException; + /** + * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the key {@link + * StrolchModelConstants#BAG_PARAMETERS} + * + * @param paramKey + * the key of the {@link Parameter} which is to be removed + * + * @return the removed {@link Parameter} or null if it did not exist + */ + > T removeParameter(String paramKey); + /** * Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey *