Class StringOps

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<String>
com.github.darksoulq.abyssallib.common.serialization.ops.StringOps

public final class StringOps extends DynamicOps<String>
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 {} with key:value pairs
  • Field Details

    • INSTANCE

      public static final StringOps INSTANCE
      The singleton instance of StringOps.
  • Method Details

    • createString

      public String createString(String value)
      Creates a quoted string with escaped backslashes and quotes.
      Specified by:
      createString in class DynamicOps<String>
      Parameters:
      value - The raw string.
      Returns:
      The escaped and quoted string.
    • createInt

      public String createInt(int value)
      Converts an integer to its string representation.
      Specified by:
      createInt in class DynamicOps<String>
      Parameters:
      value - The integer value.
      Returns:
      The string form of the integer.
    • createLong

      public String createLong(long value)
      Converts a long to a string with an 'L' suffix.
      Specified by:
      createLong in class DynamicOps<String>
      Parameters:
      value - The long value.
      Returns:
      The suffixed string.
    • createFloat

      public String createFloat(float value)
      Converts a float to a string with an 'f' suffix.
      Specified by:
      createFloat in class DynamicOps<String>
      Parameters:
      value - The float value.
      Returns:
      The suffixed string.
    • createDouble

      public String createDouble(double value)
      Converts a double to a string with a 'd' suffix.
      Specified by:
      createDouble in class DynamicOps<String>
      Parameters:
      value - The double value.
      Returns:
      The suffixed string.
    • createBoolean

      public String createBoolean(boolean value)
      Converts a boolean to its string representation.
      Specified by:
      createBoolean in class DynamicOps<String>
      Parameters:
      value - The boolean value.
      Returns:
      "true" or "false".
    • createList

      public String createList(List<String> elements)
      Joins a list of strings into a bracketed, comma-separated string.
      Specified by:
      createList in class DynamicOps<String>
      Parameters:
      elements - The list of serialized elements.
      Returns:
      A string formatted as [elem1,elem2].
    • createMap

      public String createMap(Map<String,String> map)
      Formats a map into a curly-bracketed string of key-value pairs.
      Specified by:
      createMap in class DynamicOps<String>
      Parameters:
      map - The map of serialized keys and values.
      Returns:
      A string formatted as {key1:val1,key2:val2}.
    • getStringValue

      public Optional<String> getStringValue(String input)
      Attempts to unquote and unescape a string.
      Specified by:
      getStringValue in class DynamicOps<String>
      Parameters:
      input - The serialized string.
      Returns:
      Optional containing the raw string if correctly quoted.
    • getIntValue

      public Optional<Integer> getIntValue(String input)
      Parses an integer if no type suffixes are present.
      Specified by:
      getIntValue in class DynamicOps<String>
      Parameters:
      input - The serialized input.
      Returns:
      Optional containing the integer if parsing succeeds.
    • getLongValue

      public Optional<Long> getLongValue(String input)
      Parses a long by checking for the 'L' suffix.
      Specified by:
      getLongValue in class DynamicOps<String>
      Parameters:
      input - The serialized input.
      Returns:
      Optional containing the long.
    • getFloatValue

      public Optional<Float> getFloatValue(String input)
      Parses a float by checking for the 'f' suffix.
      Specified by:
      getFloatValue in class DynamicOps<String>
      Parameters:
      input - The serialized input.
      Returns:
      Optional containing the float.
    • getDoubleValue

      public Optional<Double> getDoubleValue(String input)
      Parses a double by checking for the 'd' suffix.
      Specified by:
      getDoubleValue in class DynamicOps<String>
      Parameters:
      input - The serialized input.
      Returns:
      Optional containing the double.
    • getBooleanValue

      public Optional<Boolean> getBooleanValue(String input)
      Parses a boolean value.
      Specified by:
      getBooleanValue in class DynamicOps<String>
      Parameters:
      input - The string to check.
      Returns:
      Optional containing true/false if valid.
    • getList

      public Optional<List<String>> getList(String input)
      Parses a list by stripping brackets and splitting content at the top level.
      Specified by:
      getList in class DynamicOps<String>
      Parameters:
      input - The serialized list string.
      Returns:
      Optional list of serialized element strings.
    • getMap

      public Optional<Map<String,String>> getMap(String input)
      Parses a map by stripping brackets and splitting entries at the top level.
      Specified by:
      getMap in class DynamicOps<String>
      Parameters:
      input - The serialized map string.
      Returns:
      Optional map of serialized key-value strings.
    • empty

      public String empty()
      Specified by:
      empty in class DynamicOps<String>
      Returns:
      An empty string representation.