Package snap.util

Class Key

java.lang.Object
snap.util.Key

public class Key extends Object
This class provides an optimized convenience for getting named values from arbitrary objects.
  • Constructor Details

    • Key

      public Key()
  • Method Details

    • getValue

      public static Object getValue(Object anObj, String aKey)
      Returns a value for given object and key.
    • getValueImpl

      public static Object getValueImpl(Object anObj, String aKey)
      Returns a value for given object and key.
    • setValue

      public static void setValue(Object anObj, String aKey, Object aValue) throws Exception
      Sets a value for given object and key and value.
      Throws:
      Exception
    • setValueReflect

      public static void setValueReflect(Object anObj, String aKey, Object aValue) throws Exception
      Sets a value for given object and key and value.
      Throws:
      Exception
    • setValueSafe

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

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

      public static boolean hasKey(Object anObj, String aKey)
      Returns whether given object has an accessor for given key.
    • getIntValue

      public static int getIntValue(Object anObj, String aKey)
      Returns an int value for a key.
    • getStringValue

      public static String getStringValue(Object anObj, String aKey)
      Returns a string value for a key.
    • getValue

      public static <T> T getValue(Object anObj, String aKey, Class<T> aClass)
      Returns a value as given class, if appropriate.
    • getAccessor

      public static snap.util.KeyAccessor getAccessor(Object anObj, String aKey)
      Returns the accessor object for a given object (class) and key.
    • getStandard

      public static String getStandard(String aKey)
      Returns the key in a standard format (strip is/get prefix and start with capital letter).
    • setAllowFields

      public static void setAllowFields(boolean aValue)
      Sets whether Key is allowed to try to resolve values using object fields.