summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-08-28 14:13:02 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-08-28 14:13:38 +0100
commit655d6f798878cd69b6c02c54d4bbed83d01fd937 (patch)
tree9410bfe42f9095efb4f2871fbf08c5e7723f5a2f /common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
parentf133be23c3fab4609e969a89ad64869bc8a7c38f (diff)
Improvements to Parameter Srvice
Add proper handling for optional parameters Add setName() to the parameter group interface to force definition of that method Add some convenience metnods to parameter service Issue-ID: POLICY-1035 Change-Id: Iaa9226f45215b00aff9b78ab5fc120c24a0af46d Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java')
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
index db6995c5..358e5535 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterService.java
@@ -61,6 +61,20 @@ public abstract class ParameterService {
}
/**
+ * Register a parameter group with the parameter service.
+ *
+ * @param parameterGroup the parameter group
+ * @param overwrite if true, overwrite the current value if set
+ */
+ public static void register(final ParameterGroup parameterGroup, final boolean overwrite) {
+ if (overwrite && parameterGroupMap.containsKey(parameterGroup.getName())) {
+ deregister(parameterGroup);
+ }
+
+ register(parameterGroup);
+ }
+
+ /**
* Remove a parameter group from the parameter service.
*
* @param parameterGroupName the name of the parameter group
@@ -74,13 +88,23 @@ public abstract class ParameterService {
}
/**
+ * Remove a parameter group from the parameter service.
+ *
+ * @param parameterGroup the parameter group
+ */
+ public static void deregister(final ParameterGroup parameterGroup) {
+ deregister(parameterGroup.getName());
+ }
+
+ /**
* Get a parameter group from the parameter service.
*
* @param parameterGroupName the name of the parameter group
* @return The parameter group
*/
- public static ParameterGroup get(final String parameterGroupName) {
- final ParameterGroup parameterGroup = parameterGroupMap.get(parameterGroupName);
+ public static <T extends ParameterGroup> T get(final String parameterGroupName) {
+ @SuppressWarnings("unchecked")
+ final T parameterGroup = (T) parameterGroupMap.get(parameterGroupName);
if (parameterGroup == null) {
throw new ParameterRuntimeException("\"" + parameterGroupName + "\" not found in parameter service");