Package snap.util
Class KeyChain
java.lang.Object
snap.util.KeyChain
This class evaluates a string expression on a given object: KeyChain.getValue(object, expression).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A function handler.static interface
This is interface is implemented by objects that can get key chain values themselves.static enum
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructor.protected
KeyChain
(KeyChain.Op anOp) Constructor.protected
KeyChain
(KeyChain.Op anOp, Object child) Constructor.protected
KeyChain
(KeyChain.Op anOp, Object left, Object right) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child to the end of the keychain's child list.static String
Returns the last error encountered by the key chain parser and resets parser.static Map
Returns a thread-local assignments map.static boolean
getBoolValue
(Object anObj, Object aKeyChain) Convenience - returns a boolean for an object and key chain.getChild
(int anIndex) Returns the child at the given index in the keychain.int
Returns the number of children in the keychain.getChildKeyChain
(int i) Returns the child at the given index in the keychain as a keychain.getChildString
(int i) Returns the child at the given index in the keychain as a string.static double
getDoubleValue
(Object anObj, Object aKeyChain) Convenience - returns a double for an object and key chain.static String
getError()
Returns the last error encountered by the key chain parser (or null).static float
getFloatValue
(Object anObj, Object aKeyChain) Convenience - returns a float for an object and key chain.static int
getIntValue
(Object anObj, Object aKeyChain) Convenience - returns an int for an object and key chain.static KeyChain
getKeyChain
(Object aSource) Returns a keyChain for aSource (should be a String or existing KeyChain).static Number
getNumberValue
(Object anObj, Object aKeyChain) Convenience - returns a number for an object and key chain.getOp()
Returns the top level operator of the keychain.static String
getStringValue
(Object anObj, Object aKeyChain) Convenience - returns a string for an object and key chain.getValue()
Returns the value of the keychain.static Object
Returns the result of evaluating the given key chain on the given object.static Object
Returns the result of evaluating the given key chain on the given object.static Object
Returns the result of evaluating the given key chain on the given object.static Object
getValueImpl
(Object aRoot, Object anObj, KeyChain aKeyChain) Returns the result of evaluating the given key chain on the given object.Returns the value of the keychain as a string.static void
Simple main implementation, so RM's expressions can be used for simple math.static void
Sets the FunctionHandler.static void
Sets the given value for the given key chain + property.static void
Sets the given value for the given key chain + property.static void
setValueSafe
(Object anObj, String aKey, Object aValue) Sets the value but only prints a warning if it fails.static void
setValueSilent
(Object anObj, String aKey, Object aValue) Tries to set value in given object, ignoring failure exceptions.subchain
(int anIndex) Override to give list chance to implement this.toString()
Returns a string representation of the key chain.
-
Constructor Details
-
KeyChain
Constructor. -
KeyChain
Constructor. -
KeyChain
Constructor. -
KeyChain
Constructor.
-
-
Method Details
-
getKeyChain
Returns a keyChain for aSource (should be a String or existing KeyChain). -
getAssignments
Returns a thread-local assignments map. -
getOp
Returns the top level operator of the keychain. -
getValue
Returns the value of the keychain. -
getValueString
Returns the value of the keychain as a string. -
getChildCount
public int getChildCount()Returns the number of children in the keychain. -
getChild
Returns the child at the given index in the keychain. -
addChild
Adds a child to the end of the keychain's child list. -
getChildString
Returns the child at the given index in the keychain as a string. -
getChildKeyChain
Returns the child at the given index in the keychain as a keychain. -
subchain
Override to give list chance to implement this. -
getValue
Returns the result of evaluating the given key chain on the given object. -
getValue
Returns the result of evaluating the given key chain on the given object. -
getValue
Returns the result of evaluating the given key chain on the given object. -
getValueImpl
Returns the result of evaluating the given key chain on the given object. Broken out so objects can implement custom getKeyChainValue but still have access to default implementation. -
setFunctionHandler
Sets the FunctionHandler. -
getStringValue
Convenience - returns a string for an object and key chain. -
getNumberValue
Convenience - returns a number for an object and key chain. -
getIntValue
Convenience - returns an int for an object and key chain. -
getFloatValue
Convenience - returns a float for an object and key chain. -
getDoubleValue
Convenience - returns a double for an object and key chain. -
getBoolValue
Convenience - returns a boolean for an object and key chain. -
getError
Returns the last error encountered by the key chain parser (or null). -
getAndResetError
Returns the last error encountered by the key chain parser and resets parser. -
setValue
Sets the given value for the given key chain + property. This is a real bogus loser implementation. -
setValue
Sets the given value for the given key chain + property. This is a real bogus loser implementation that only supports Op.Key and Op.Chain. -
setValueSafe
Sets the value but only prints a warning if it fails. -
setValueSilent
Tries to set value in given object, ignoring failure exceptions. -
toString
Returns a string representation of the key chain. -
main
Simple main implementation, so RM's expressions can be used for simple math.- Throws:
IOException
-