Package com.inductiveautomation.rm.base
Class RMKey
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMKey
-
public class RMKey extends java.lang.Object
This class provides an optimized convenience for getting named values from arbitrary objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RMKey.Get
This is interface is implemented by objects that can get key values themselves.static interface
RMKey.GetSet
This is interface is implemented by objects that can get/set key value themselves.static class
RMKey.KeyAccessor
KeyAccessor - enclosed class for actually getting/setting values for a given object (class) and key.static interface
RMKey.KeyMap
static class
RMKey.NoSetMethodException
NoSetMethodException.
-
Constructor Summary
Constructors Constructor Description RMKey()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RMKey.KeyAccessor
getAccessor(java.lang.Object anObj, java.lang.String aKey)
Returns the accessor object for a given object (class) and key.static int
getIntValue(java.lang.Object anObj, java.lang.String aKey)
Returns an int value for a key.static java.util.Collection<java.lang.String>
getKeys(java.lang.Object obj)
static java.lang.String
getSanitizedKey(java.lang.String aKey)
Returns the given string with all invalid key characters stripped out.static java.lang.String
getStandard(java.lang.String aKey)
Returns the key in a standard format (strip is/get prefix and start with capital letter).static java.lang.String
getStringValue(java.lang.Object anObj, java.lang.String aKey)
Returns a string value for a key.static java.lang.Object
getValue(java.lang.Object anObj, java.lang.String aKey)
Returns a value for given object and key.static <T> T
getValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Class<T> aClass)
Returns a value as given class, if appropriate.static java.lang.Object
getValueImpl(java.lang.Object anObj, java.lang.String aKey)
Returns a value for given object and key.static boolean
hasKey(java.lang.Object anObj, java.lang.String aKey)
Returns whether given object has an accessor for given key.static boolean
isKey(java.lang.String aString)
Returns whether given string is a valid key (starts with letter and only contains letters, digits, white space and under bars).static void
setValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Sets a value for given object and key and value.static void
setValueSafe(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Sets the value but only prints a warning if it fails.static void
setValueSilent(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Tries to set value in given object, ignoring failure exceptions.
-
-
-
Method Detail
-
isKey
public static boolean isKey(@Nullable java.lang.String aString)
Returns whether given string is a valid key (starts with letter and only contains letters, digits, white space and under bars).
-
getSanitizedKey
@Nonnull public static java.lang.String getSanitizedKey(@Nullable java.lang.String aKey)
Returns the given string with all invalid key characters stripped out. If aKey is blank, null, or contains only invalid characters, resulting string will empty and therefore invalid. Resulting string may also end up being a duplicate of another key -- there's only so much we can do for the user.
-
getKeys
public static java.util.Collection<java.lang.String> getKeys(java.lang.Object obj)
-
getValue
public static java.lang.Object getValue(java.lang.Object anObj, java.lang.String aKey)
Returns a value for given object and key.
-
getValueImpl
public static java.lang.Object getValueImpl(java.lang.Object anObj, java.lang.String aKey)
Returns a value for given object and key.
-
setValue
public static void setValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue) throws java.lang.Exception
Sets a value for given object and key and value.- Throws:
java.lang.Exception
-
setValueSafe
public static void setValueSafe(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Sets the value but only prints a warning if it fails.
-
setValueSilent
public static void setValueSilent(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Tries to set value in given object, ignoring failure exceptions.
-
hasKey
public static boolean hasKey(java.lang.Object anObj, java.lang.String aKey)
Returns whether given object has an accessor for given key.
-
getIntValue
public static int getIntValue(java.lang.Object anObj, java.lang.String aKey)
Returns an int value for a key.
-
getStringValue
public static java.lang.String getStringValue(java.lang.Object anObj, java.lang.String aKey)
Returns a string value for a key.
-
getValue
public static <T> T getValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Class<T> aClass)
Returns a value as given class, if appropriate.
-
getAccessor
public static RMKey.KeyAccessor getAccessor(java.lang.Object anObj, java.lang.String aKey)
Returns the accessor object for a given object (class) and key.
-
getStandard
public static java.lang.String getStandard(@Nonnull java.lang.String aKey)
Returns the key in a standard format (strip is/get prefix and start with capital letter).
-
-