Package snap.util

Class KeyChain

java.lang.Object
snap.util.KeyChain

public class KeyChain extends Object
This class evaluates a string expression on a given object: KeyChain.getValue(object, expression).
  • Constructor Details

  • Method Details

    • getKeyChain

      public static KeyChain getKeyChain(Object aSource)
      Returns a keyChain for aSource (should be a String or existing KeyChain).
    • getAssignments

      public static Map getAssignments()
      Returns a thread-local assignments map.
    • getOp

      public KeyChain.Op getOp()
      Returns the top level operator of the keychain.
    • getValue

      public Object getValue()
      Returns the value of the keychain.
    • getValueString

      public String getValueString()
      Returns the value of the keychain as a string.
    • getChildCount

      public int getChildCount()
      Returns the number of children in the keychain.
    • getChild

      public Object getChild(int anIndex)
      Returns the child at the given index in the keychain.
    • addChild

      public void addChild(Object child)
      Adds a child to the end of the keychain's child list.
    • getChildString

      public String getChildString(int i)
      Returns the child at the given index in the keychain as a string.
    • getChildKeyChain

      public KeyChain getChildKeyChain(int i)
      Returns the child at the given index in the keychain as a keychain.
    • subchain

      public KeyChain subchain(int anIndex)
      Override to give list chance to implement this.
    • getValue

      public static Object getValue(Object anObj, Object aKeyChain)
      Returns the result of evaluating the given key chain on the given object.
    • getValue

      public static Object getValue(Object anObj, KeyChain aKeyChain)
      Returns the result of evaluating the given key chain on the given object.
    • getValue

      public static Object getValue(Object aRoot, Object anObj, KeyChain aKeyChain)
      Returns the result of evaluating the given key chain on the given object.
    • getValueImpl

      public static Object getValueImpl(Object aRoot, Object anObj, KeyChain aKeyChain)
      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

      public static void setFunctionHandler(KeyChain.FunctionHandler aFH)
      Sets the FunctionHandler.
    • getStringValue

      public static String getStringValue(Object anObj, Object aKeyChain)
      Convenience - returns a string for an object and key chain.
    • getNumberValue

      public static Number getNumberValue(Object anObj, Object aKeyChain)
      Convenience - returns a number for an object and key chain.
    • getIntValue

      public static int getIntValue(Object anObj, Object aKeyChain)
      Convenience - returns an int for an object and key chain.
    • getFloatValue

      public static float getFloatValue(Object anObj, Object aKeyChain)
      Convenience - returns a float for an object and key chain.
    • getDoubleValue

      public static double getDoubleValue(Object anObj, Object aKeyChain)
      Convenience - returns a double for an object and key chain.
    • getBoolValue

      public static boolean getBoolValue(Object anObj, Object aKeyChain)
      Convenience - returns a boolean for an object and key chain.
    • getError

      public static String getError()
      Returns the last error encountered by the key chain parser (or null).
    • getAndResetError

      public static String getAndResetError()
      Returns the last error encountered by the key chain parser and resets parser.
    • setValue

      public static void setValue(Object anObj, Object aKeyChain, Object aValue)
      Sets the given value for the given key chain + property. This is a real bogus loser implementation.
    • setValue

      public static void setValue(Object anObj, KeyChain aKeyChain, Object aValue)
      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

      public static void setValueSafe(Object anObj, String aKey, Object aValue)
      Sets the value but only prints a warning if it fails.
    • setValueSilent

      public static void setValueSilent(Object anObj, String aKey, Object aValue)
      Tries to set value in given object, ignoring failure exceptions.
    • toString

      public String toString()
      Returns a string representation of the key chain.
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args) throws IOException
      Simple main implementation, so RM's expressions can be used for simple math.
      Throws:
      IOException