Package heronarts.lx

Class LXSerializable.Utils

java.lang.Object
heronarts.lx.LXSerializable.Utils
Enclosing interface:
LXSerializable

public static class LXSerializable.Utils extends Object
Static container for utility methods
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • hasParameter

      public static boolean hasParameter(JsonObject object, String parameter)
    • getParameter

      public static JsonElement getParameter(JsonObject object, String parameter)
    • saveParameters

      public static JsonObject saveParameters(LXParameter.Collection parameters)
    • saveParameters

      public static void saveParameters(JsonObject obj, LXParameter.Collection parameters)
    • saveParameter

      public static void saveParameter(LXParameter parameter, JsonObject obj)
    • saveParameter

      public static void saveParameter(LXParameter parameter, JsonObject obj, String path)
    • loadParameters

      public static void loadParameters(JsonObject obj, LXParameter.Collection parameters)
      Utility function to load a set of parameters
      Parameters:
      obj - JsonObject to serialize to
      parameters - Map of parameters to unserialize
    • loadParameter

      public static void loadParameter(LXParameter parameter, JsonObject obj, String path)
    • loadInt

      public static void loadInt(DiscreteParameter parameter, JsonObject object, String key)
      Loads an integer value into a parameter, if it is found. If the key doesn't exist, this method does nothing.
      Parameters:
      parameter - Parameter to load
      object - Json object
      key - Key to check, if exists loaded as int
    • loadBoolean

      public static void loadBoolean(BooleanParameter parameter, JsonObject object, String key)
      Loads a boolean value into a parameter, if it is found. If the key doesn't exist, this method does nothing.
      Parameters:
      parameter - Parameter to load
      object - Json object
      key - Key to check, if exists loaded as boolean
    • loadDouble

      public static void loadDouble(LXParameter parameter, JsonObject object, String key)
      Loads an double value into a parameter, if it is found. If the key doesn't exist, this method does nothing.
      Parameters:
      parameter - Parameter to load
      object - Json object
      key - Key to check, if exists loaded as double
    • loadString

      public static void loadString(StringParameter parameter, JsonObject object, String key)
      Loads an double value into a parameter, if it is found. If the key doesn't exist, this method does nothing.
      Parameters:
      parameter - Parameter to load
      object - Json object
      key - Key to check, if exists loaded as string
    • loadObject

      public static void loadObject(LX lx, LXSerializable serializable, JsonObject object, String key)
      Loads a serializable object from a sub-key, if the key is found. If it is not found, no loading will occur.
      Parameters:
      lx - LX instance
      serializable - Sub-object to load
      object - JSON object to load from
      key - Key to check for existence of
    • loadObject

      public static void loadObject(LX lx, LXSerializable serializable, JsonObject object, String key, boolean defaultEmptyObj)
      Loads a serializable object from a sub-key, if the key is found. If it is not found, loading will occur with a default empty object if the final argument is true. The sub-object should handle that.
      Parameters:
      lx - LX instance
      serializable - Sub-object to load
      object - JSON object to load from
      key - Key to check for existence of
      defaultEmptyObj - Whether to load an empty JsonObject if key is not found
    • resetObject

      public static void resetObject(LX lx, LXSerializable serializable)
      Reset an object by loading an empty dictionary with the reset key
      Parameters:
      lx - LX instance
      serializable - Object to reset
    • loadArray

      public static void loadArray(LX lx, List<? extends LXSerializable> serializables, JsonObject object, String key)
      Loads an array of sub-objects from the given key, if it is found
      Parameters:
      lx - LX instance
      serializables - List of child objects to load
      object - Object to load from
      key - Key to check for
    • loadArray

      public static void loadArray(LX lx, LXSerializable[] serializables, JsonObject object, String key)
      Loads an array of sub-objects from the given key, if it is found
      Parameters:
      lx - LX instance
      serializables - array of child objects to load
      object - Object to load from
      key - Key to check for
    • toObject

      public static JsonObject toObject(LXComponent component)
      Serializes an LXComponent to a JsonObject
      Parameters:
      component - Component to serialize
      Returns:
      JsonObject representation of the component
    • toObject

      public static JsonObject toObject(LXComponent component, boolean stripIds)
      Serializes an LXComponent to a JsonObject
      Parameters:
      component - Component to serialize
      stripIds - Whether to strip ids from the result
      Returns:
      JsonObject representation of the component
    • toObject

      public static JsonObject toObject(LX lx, LXSerializable serializable)
      Serializes any LXSerializable to a JsonObject
      Parameters:
      lx - LX instance
      serializable - Serializable object
      Returns:
      JsonObject representation of the object
    • toObject

      public static JsonObject toObject(LX lx, LXSerializable serializable, boolean stripIds)
      Serializes any LXSerializable to a JsonObject
      Parameters:
      lx - LX instance
      serializable - Serializable object
      stripIds - Whether to strip ids from the result
      Returns:
      JsonObject representation of the object
    • toObject

      public static JsonObject toObject(LX lx, Map<String,? extends LXSerializable> serializables)
      Serializes a map of subobjects into a JsonObject
      Parameters:
      lx - LX instance
      serializables - Map of serializable subobjects
      Returns:
      JsonObject representation of all child objects
    • toArray

      public static JsonArray toArray(LX lx, LXSerializable[] serializables)
      Serializes an array of subobjects
      Parameters:
      lx - LX instance
      serializables - Array of sub-objects
      Returns:
      JsonArray representation of all subobjects
    • toArray

      public static JsonArray toArray(LX lx, LXSerializable[] serializables, boolean stripIds)
      Serializes an array of subobjects
      Parameters:
      lx - LX instance
      serializables - Array of sub-objects
      stripIds - Whether to strip ids in output
      Returns:
      JsonArray representation of all subobjects
    • toArray

      public static JsonArray toArray(LX lx, Collection<? extends LXSerializable> serializables)
      Serialized a generic collection of sub-objects, not necessarily ordered
      Parameters:
      lx - LX instance
      serializables - Collection of serializable objects
      Returns:
      JsonArray representation of collection of objects
    • toArray

      public static JsonArray toArray(LX lx, Collection<? extends LXSerializable> serializables, boolean stripIds)
      Serialized a generic collection of sub-objects, not necessarily ordered
      Parameters:
      lx - LX instance
      serializables - Collection of serializable objects
      stripIds - Whether to strip ids from output
      Returns:
      JsonArray representation of collection of objects
    • stripIds

      public static JsonObject stripIds(JsonObject object)
      Strips all ID values out of a JsonObject. This is often helpful when copy/pasting or loading objects in a context where global IDs should not be overwritten.
      Parameters:
      object - Object to strip all nested ID keys from
      Returns:
      The same object, with no ID keys
    • stripParameter

      public static JsonObject stripParameter(JsonObject object, LXParameter parameter)
    • stripParameter

      public static JsonObject stripParameter(JsonObject object, String parameter)