Package com.inductiveautomation.rm.base
Class RMKey
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMKey
-
public class RMKey extends java.lang.ObjectThis class provides an optimized convenience for getting named values from arbitrary objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRMKey.GetThis is interface is implemented by objects that can get key values themselves.static interfaceRMKey.GetSetThis is interface is implemented by objects that can get/set key value themselves.static classRMKey.KeyAccessorKeyAccessor - enclosed class for actually getting/setting values for a given object (class) and key.static interfaceRMKey.KeyMapstatic classRMKey.NoSetMethodExceptionNoSetMethodException.
-
Constructor Summary
Constructors Constructor Description RMKey()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RMKey.KeyAccessorgetAccessor(java.lang.Object anObj, java.lang.String aKey)Returns the accessor object for a given object (class) and key.static intgetIntValue(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.StringgetSanitizedKey(java.lang.String aKey)Returns the given string with all invalid key characters stripped out.static java.lang.StringgetStandard(java.lang.String aKey)Returns the key in a standard format (strip is/get prefix and start with capital letter).static java.lang.StringgetStringValue(java.lang.Object anObj, java.lang.String aKey)Returns a string value for a key.static java.lang.ObjectgetValue(java.lang.Object anObj, java.lang.String aKey)Returns a value for given object and key.static <T> TgetValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Class<T> aClass)Returns a value as given class, if appropriate.static java.lang.ObjectgetValueImpl(java.lang.Object anObj, java.lang.String aKey)Returns a value for given object and key.static booleanhasKey(java.lang.Object anObj, java.lang.String aKey)Returns whether given object has an accessor for given key.static booleanisKey(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 voidsetValue(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)Sets a value for given object and key and value.static voidsetValueSafe(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)Sets the value but only prints a warning if it fails.static voidsetValueSilent(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.ExceptionSets 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).
-
-