Package heronarts.lx
Class LXSerializable.Utils
java.lang.Object
heronarts.lx.LXSerializable.Utils
- Enclosing interface:
LXSerializable
Static container for utility methods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetEnumNamePath(String path) static JsonElementgetParameter(JsonObject object, String parameter) static booleanhasParameter(JsonObject object, String parameter) static voidloadArray(LX lx, LXSerializable[] serializables, JsonObject object, String key) Loads an array of sub-objects from the given key, if it is foundstatic voidloadArray(LX lx, List<? extends LXSerializable> serializables, JsonObject object, String key) Loads an array of sub-objects from the given key, if it is foundstatic voidloadBoolean(BooleanParameter parameter, JsonObject object, String key) Loads a boolean value into a parameter, if it is found.static voidloadDouble(LXParameter parameter, JsonObject object, String key) Loads an double value into a parameter, if it is found.static voidloadInt(DiscreteParameter parameter, JsonObject object, String key) Loads an integer value into a parameter, if it is found.static voidloadObject(LX lx, LXSerializable serializable, JsonObject object, String key) Loads a serializable object from a sub-key, if the key is found.static voidloadObject(LX lx, LXSerializable serializable, JsonObject object, String key, boolean defaultEmptyObj) Loads a serializable object from a sub-key, if the key is found.static voidloadParameter(LXParameter parameter, JsonObject obj, String path) static voidloadParameters(JsonObject obj, LXParameter.Collection parameters) Utility function to load a set of parametersstatic voidloadString(StringParameter parameter, JsonObject object, String key) Loads an double value into a parameter, if it is found.static voidresetObject(LX lx, LXSerializable serializable) Reset an object by loading an empty dictionary with the reset keystatic voidsaveParameter(LXParameter parameter, JsonObject obj) static voidsaveParameter(LXParameter parameter, JsonObject obj, String path) static voidsaveParameters(JsonObject obj, LXParameter.Collection parameters) static JsonObjectsaveParameters(LXParameter.Collection parameters) static JsonObjectstripIds(JsonObject object) Strips all ID values out of a JsonObject.static JsonObjectstripParameter(JsonObject object, LXParameter parameter) static JsonObjectstripParameter(JsonObject object, String parameter) static JsonArraytoArray(LX lx, LXSerializable[] serializables) Serializes an array of subobjectsstatic JsonArraytoArray(LX lx, LXSerializable[] serializables, boolean stripIds) Serializes an array of subobjectsstatic JsonArraytoArray(LX lx, Collection<? extends LXSerializable> serializables) Serialized a generic collection of sub-objects, not necessarily orderedstatic JsonArraytoArray(LX lx, Collection<? extends LXSerializable> serializables, boolean stripIds) Serialized a generic collection of sub-objects, not necessarily orderedstatic JsonObjecttoObject(LXComponent component) Serializes an LXComponent to a JsonObjectstatic JsonObjecttoObject(LXComponent component, boolean stripIds) Serializes an LXComponent to a JsonObjectstatic JsonObjecttoObject(LX lx, LXSerializable serializable) Serializes any LXSerializable to a JsonObjectstatic JsonObjecttoObject(LX lx, LXSerializable serializable, boolean stripIds) Serializes any LXSerializable to a JsonObjectstatic JsonObjecttoObject(LX lx, Map<String, ? extends LXSerializable> serializables) Serializes a map of subobjects into a JsonObject
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
getEnumNamePath
-
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 ifkeyis 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
-