From 6f7269c4ae05bbdc879156d3e3d1863992a7c246 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 21 Oct 2019 16:59:48 +0200 Subject: [PATCH] [New] Added ParameterBagContainer.getParameter() using StrolchModelConstants.BAG_PARAMETERS --- .../model/GroupedParameterizedElement.java | 81 +++++++++++++++++++ .../strolch/model/ParameterBagContainer.java | 80 ++++++++++++++++++ 2 files changed, 161 insertions(+) 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 1cb74e87a..75f4e11e9 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 @@ -16,6 +16,7 @@ package li.strolch.model; import static java.util.stream.Collectors.toList; +import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS; import static li.strolch.model.StrolchModelConstants.BAG_RELATIONS; import java.text.MessageFormat; @@ -144,18 +145,98 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement return parameter; } + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_PARAMETERS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override + public > T getParameter(String paramKey) { + return getParameter(BAG_PARAMETERS, paramKey, false); + } + + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_PARAMETERS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override + public > T getParameter(String paramKey, boolean assertExists) { + return getParameter(BAG_PARAMETERS, paramKey, assertExists); + } + + /** + * Returns the {@link StringParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override public StringParameter getRelationParam(String paramKey) { return getParameter(BAG_RELATIONS, paramKey, false); } + /** + * Returns the {@link StringParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override public StringParameter getRelationParam(String paramKey, boolean assertExists) { return getParameter(BAG_RELATIONS, paramKey, assertExists); } + /** + * Returns the {@link StringListParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override public StringListParameter getRelationsParam(String paramKey) { return getParameter(BAG_RELATIONS, paramKey, false); } + /** + * Returns the {@link StringListParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + @Override public StringListParameter getRelationsParam(String paramKey, boolean assertExists) { return getParameter(BAG_RELATIONS, paramKey, assertExists); } 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 f444ad31e..bf1795f48 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 @@ -7,6 +7,8 @@ import java.util.stream.Stream; import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchModelException; import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; /** * A {@link ParameterBagContainer} has a map of {@link ParameterBag ParameterBags} where the key is the id of the @@ -16,6 +18,84 @@ import li.strolch.model.parameter.Parameter; */ public interface ParameterBagContainer extends StrolchElement { + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the ID {@link * + * StrolchModelConstants#BAG_PARAMETERS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + > T getParameter(String paramKey); + + /** + * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_PARAMETERS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + > T getParameter(String paramKey, boolean assertExists); + + /** + * Returns the {@link StringParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + StringParameter getRelationParam(String paramKey); + + /** + * Returns the {@link StringParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + StringParameter getRelationParam(String paramKey, boolean assertExists); + + /** + * Returns the {@link StringListParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * + * @return the found {@link Parameter} or null if it was not found + */ + StringListParameter getRelationsParam(String paramKey); + + /** + * Returns the {@link StringListParameter} with the given key from the {@link ParameterBag} with the ID {@link + * StrolchModelConstants#BAG_RELATIONS}, or null if the {@link Parameter} or the {@link ParameterBag} does not + * exist + * + * @param paramKey + * the key of the {@link Parameter} which is to be returned + * @param assertExists + * if set to true, and the parameter does not exist, a {@link StrolchModelException} is thrown + * + * @return the found {@link Parameter} or null if it was not found + */ + StringListParameter getRelationsParam(String paramKey, boolean assertExists); + /** * Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if * the {@link Parameter} or the {@link ParameterBag} does not exist