Package heronarts.lx
Class LXSerializable.Utils
java.lang.Object
heronarts.lx.LXSerializable.Utils
- Enclosing interface:
- LXSerializable
Static container for utility methods
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic JsonElement
getParameter
(JsonObject object, String parameter) static boolean
hasParameter
(JsonObject object, String parameter) static void
loadArray
(LX lx, LXSerializable[] serializables, JsonObject object, String key) Loads an array of sub-objects from the given key, if it is foundstatic 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 foundstatic void
loadBoolean
(BooleanParameter parameter, JsonObject object, String key) Loads a boolean value into a parameter, if it is found.static void
loadDouble
(LXParameter parameter, JsonObject object, String key) Loads an double value into a parameter, if it is found.static void
loadInt
(DiscreteParameter parameter, JsonObject object, String key) Loads an integer value into a parameter, if it is found.static void
loadObject
(LX lx, LXSerializable serializable, JsonObject object, String key) Loads a serializable object from a sub-key, if the key is found.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.static void
loadParameter
(LXParameter parameter, JsonObject obj, String path) static void
loadParameters
(JsonObject obj, LXParameter.Collection parameters) Utility function to load a set of parametersstatic void
loadString
(StringParameter parameter, JsonObject object, String key) Loads an double value into a parameter, if it is found.static void
resetObject
(LX lx, LXSerializable serializable) Reset an object by loading an empty dictionary with the reset keystatic void
saveParameter
(LXParameter parameter, JsonObject obj) static void
saveParameter
(LXParameter parameter, JsonObject obj, String path) static void
saveParameters
(JsonObject obj, LXParameter.Collection parameters) static JsonObject
saveParameters
(LXParameter.Collection parameters) static JsonObject
stripIds
(JsonObject object) Strips all ID values out of a JsonObject.static JsonObject
stripParameter
(JsonObject object, LXParameter parameter) static JsonObject
stripParameter
(JsonObject object, String parameter) static JsonArray
toArray
(LX lx, LXSerializable[] serializables) Serializes an array of subobjectsstatic JsonArray
toArray
(LX lx, LXSerializable[] serializables, boolean stripIds) Serializes an array of subobjectsstatic JsonArray
toArray
(LX lx, Collection<? extends LXSerializable> serializables) Serialized a generic collection of sub-objects, not necessarily orderedstatic JsonArray
toArray
(LX lx, Collection<? extends LXSerializable> serializables, boolean stripIds) Serialized a generic collection of sub-objects, not necessarily orderedstatic JsonObject
toObject
(LXComponent component) Serializes an LXComponent to a JsonObjectstatic JsonObject
toObject
(LXComponent component, boolean stripIds) Serializes an LXComponent to a JsonObjectstatic JsonObject
toObject
(LX lx, LXSerializable serializable) Serializes any LXSerializable to a JsonObjectstatic JsonObject
toObject
(LX lx, LXSerializable serializable, boolean stripIds) Serializes any LXSerializable to a JsonObjectstatic JsonObject
toObject
(LX lx, Map<String, ? extends LXSerializable> serializables) Serializes a map of subobjects into a JsonObject
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
hasParameter
-
getParameter
-
saveParameters
-
saveParameters
-
saveParameter
-
saveParameter
-
loadParameters
Utility function to load a set of parameters- Parameters:
obj
- JsonObject to serialize toparameters
- Map of parameters to unserialize
-
loadParameter
-
loadInt
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 loadobject
- Json objectkey
- Key to check, if exists loaded as int
-
loadBoolean
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 loadobject
- Json objectkey
- Key to check, if exists loaded as boolean
-
loadDouble
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 loadobject
- Json objectkey
- Key to check, if exists loaded as double
-
loadString
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 loadobject
- Json objectkey
- Key to check, if exists loaded as string
-
loadObject
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 instanceserializable
- Sub-object to loadobject
- JSON object to load fromkey
- 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 istrue
. The sub-object should handle that.- Parameters:
lx
- LX instanceserializable
- Sub-object to loadobject
- JSON object to load fromkey
- Key to check for existence ofdefaultEmptyObj
- Whether to load an empty JsonObject ifkey
is not found
-
resetObject
Reset an object by loading an empty dictionary with the reset key- Parameters:
lx
- LX instanceserializable
- 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 instanceserializables
- List of child objects to loadobject
- Object to load fromkey
- Key to check for
-
loadArray
Loads an array of sub-objects from the given key, if it is found- Parameters:
lx
- LX instanceserializables
- array of child objects to loadobject
- Object to load fromkey
- Key to check for
-
toObject
Serializes an LXComponent to a JsonObject- Parameters:
component
- Component to serialize- Returns:
- JsonObject representation of the component
-
toObject
Serializes an LXComponent to a JsonObject- Parameters:
component
- Component to serializestripIds
- Whether to strip ids from the result- Returns:
- JsonObject representation of the component
-
toObject
Serializes any LXSerializable to a JsonObject- Parameters:
lx
- LX instanceserializable
- Serializable object- Returns:
- JsonObject representation of the object
-
toObject
Serializes any LXSerializable to a JsonObject- Parameters:
lx
- LX instanceserializable
- Serializable objectstripIds
- Whether to strip ids from the result- Returns:
- JsonObject representation of the object
-
toObject
Serializes a map of subobjects into a JsonObject- Parameters:
lx
- LX instanceserializables
- Map of serializable subobjects- Returns:
- JsonObject representation of all child objects
-
toArray
Serializes an array of subobjects- Parameters:
lx
- LX instanceserializables
- Array of sub-objects- Returns:
- JsonArray representation of all subobjects
-
toArray
Serializes an array of subobjects- Parameters:
lx
- LX instanceserializables
- Array of sub-objectsstripIds
- Whether to strip ids in output- Returns:
- JsonArray representation of all subobjects
-
toArray
Serialized a generic collection of sub-objects, not necessarily ordered- Parameters:
lx
- LX instanceserializables
- 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 instanceserializables
- Collection of serializable objectsstripIds
- Whether to strip ids from output- Returns:
- JsonArray representation of collection of objects
-
stripIds
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
-
stripParameter
-