Class StringOps
java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<String>
com.github.darksoulq.abyssallib.common.serialization.ops.StringOps
An implementation of
DynamicOps that serializes data into a custom string-based format.
This format utilizes Java-style literal suffixes for numeric types and specialized brackets for collections:
- Strings: Quoted with backslash escaping (
"text") - Longs: Suffix
L(100L) - Floats: Suffix
f(1.5f) - Doubles: Suffix
d(2.0d) - Lists: Wrapped in
[]and comma-separated - Maps: Wrapped in
{}withkey:valuepairs
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncreateBoolean(boolean value) Converts a boolean to its string representation.createDouble(double value) Converts a double to a string with a 'd' suffix.createFloat(float value) Converts a float to a string with an 'f' suffix.createInt(int value) Converts an integer to its string representation.createList(List<String> elements) Joins a list of strings into a bracketed, comma-separated string.createLong(long value) Converts a long to a string with an 'L' suffix.Formats a map into a curly-bracketed string of key-value pairs.createString(String value) Creates a quoted string with escaped backslashes and quotes.empty()getBooleanValue(String input) Parses a boolean value.getDoubleValue(String input) Parses a double by checking for the 'd' suffix.getFloatValue(String input) Parses a float by checking for the 'f' suffix.getIntValue(String input) Parses an integer if no type suffixes are present.Parses a list by stripping brackets and splitting content at the top level.getLongValue(String input) Parses a long by checking for the 'L' suffix.Parses a map by stripping brackets and splitting entries at the top level.getStringValue(String input) Attempts to unquote and unescape a string.
-
Field Details
-
INSTANCE
The singleton instance of StringOps.
-
-
Method Details
-
createString
Creates a quoted string with escaped backslashes and quotes.- Specified by:
createStringin classDynamicOps<String>- Parameters:
value- The raw string.- Returns:
- The escaped and quoted string.
-
createInt
Converts an integer to its string representation.- Specified by:
createIntin classDynamicOps<String>- Parameters:
value- The integer value.- Returns:
- The string form of the integer.
-
createLong
Converts a long to a string with an 'L' suffix.- Specified by:
createLongin classDynamicOps<String>- Parameters:
value- The long value.- Returns:
- The suffixed string.
-
createFloat
Converts a float to a string with an 'f' suffix.- Specified by:
createFloatin classDynamicOps<String>- Parameters:
value- The float value.- Returns:
- The suffixed string.
-
createDouble
Converts a double to a string with a 'd' suffix.- Specified by:
createDoublein classDynamicOps<String>- Parameters:
value- The double value.- Returns:
- The suffixed string.
-
createBoolean
Converts a boolean to its string representation.- Specified by:
createBooleanin classDynamicOps<String>- Parameters:
value- The boolean value.- Returns:
- "true" or "false".
-
createList
Joins a list of strings into a bracketed, comma-separated string.- Specified by:
createListin classDynamicOps<String>- Parameters:
elements- The list of serialized elements.- Returns:
- A string formatted as
[elem1,elem2].
-
createMap
-
getStringValue
Attempts to unquote and unescape a string.- Specified by:
getStringValuein classDynamicOps<String>- Parameters:
input- The serialized string.- Returns:
- Optional containing the raw string if correctly quoted.
-
getIntValue
Parses an integer if no type suffixes are present.- Specified by:
getIntValuein classDynamicOps<String>- Parameters:
input- The serialized input.- Returns:
- Optional containing the integer if parsing succeeds.
-
getLongValue
Parses a long by checking for the 'L' suffix.- Specified by:
getLongValuein classDynamicOps<String>- Parameters:
input- The serialized input.- Returns:
- Optional containing the long.
-
getFloatValue
Parses a float by checking for the 'f' suffix.- Specified by:
getFloatValuein classDynamicOps<String>- Parameters:
input- The serialized input.- Returns:
- Optional containing the float.
-
getDoubleValue
Parses a double by checking for the 'd' suffix.- Specified by:
getDoubleValuein classDynamicOps<String>- Parameters:
input- The serialized input.- Returns:
- Optional containing the double.
-
getBooleanValue
Parses a boolean value.- Specified by:
getBooleanValuein classDynamicOps<String>- Parameters:
input- The string to check.- Returns:
- Optional containing true/false if valid.
-
getList
-
getMap
-
empty
- Specified by:
emptyin classDynamicOps<String>- Returns:
- An empty string representation.
-