From 3fa9acf5226c6f842c31aba0a39f9e305b370e08 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 26 Mar 2019 19:32:56 -0400 Subject: Add get() without clazz Added Registry.get() that does not need a class argument. Change-Id: I3e8b0e3cc14eda914e0b1b201e6ddf67a9e3462e Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn --- .../org/onap/policy/common/utils/services/Registry.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils/src/main/java/org/onap/policy/common/utils/services/Registry.java b/utils/src/main/java/org/onap/policy/common/utils/services/Registry.java index c209379f..13fb3389 100644 --- a/utils/src/main/java/org/onap/policy/common/utils/services/Registry.java +++ b/utils/src/main/java/org/onap/policy/common/utils/services/Registry.java @@ -110,6 +110,23 @@ public class Registry { return (instance.name2object.remove(name) != null); } + /** + * Gets the object by the given name. + * + * @param name name of the object to get + * @return the object + * @throws IllegalArgumentException if no object is registered by the given name + */ + @SuppressWarnings("unchecked") + public static T get(String name) { + Object obj = instance.name2object.get(name); + if (obj == null) { + throw new IllegalArgumentException("not registered: " + name); + } + + return (T) obj; + } + /** * Gets the object by the given name. * -- cgit 1.2.3-korg