diff options
author | Jim Hahn <jrh3@att.com> | 2019-03-26 19:32:56 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-03-26 19:32:56 -0400 |
commit | 3fa9acf5226c6f842c31aba0a39f9e305b370e08 (patch) | |
tree | 93f54dc9215b067450bae6b7cf950f596062936f /utils | |
parent | 4ac697769f46e3f6d52a086bcc8e15d89755dd0d (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/src/main/java/org/onap/policy/common/utils/services/Registry.java | 17 |
1 files changed, 17 insertions, 0 deletions
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 @@ -114,6 +114,23 @@ public class Registry { * 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> 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. + * + * @param name name of the object to get * @param clazz object's class * @return the object * @throws IllegalArgumentException if no object is registered by the given name |