Class YamlOps

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

public class YamlOps extends DynamicOps<Object>
An implementation of DynamicOps using SnakeYAML.

This class treats the serialized format as a tree of standard Java objects (Maps, Lists, and Primitives), allowing for bidirectional conversion between Java POJOs and YAML data.

  • Field Details

    • INSTANCE

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

    • createString

      public Object createString(String value)
      Specified by:
      createString in class DynamicOps<Object>
      Parameters:
      value - The string to wrap.
      Returns:
      The raw string object.
    • createInt

      public Object createInt(int value)
      Specified by:
      createInt in class DynamicOps<Object>
      Parameters:
      value - The integer to wrap.
      Returns:
      The raw Integer object.
    • createLong

      public Object createLong(long value)
      Specified by:
      createLong in class DynamicOps<Object>
      Parameters:
      value - The long to wrap.
      Returns:
      The raw Long object.
    • createFloat

      public Object createFloat(float value)
      Specified by:
      createFloat in class DynamicOps<Object>
      Parameters:
      value - The float to wrap.
      Returns:
      The raw Float object.
    • createDouble

      public Object createDouble(double value)
      Specified by:
      createDouble in class DynamicOps<Object>
      Parameters:
      value - The double to wrap.
      Returns:
      The raw Double object.
    • createBoolean

      public Object createBoolean(boolean value)
      Specified by:
      createBoolean in class DynamicOps<Object>
      Parameters:
      value - The boolean to wrap.
      Returns:
      The raw Boolean object.
    • createList

      public Object createList(List<Object> elements)
      Creates a YAML-compatible list.
      Specified by:
      createList in class DynamicOps<Object>
      Parameters:
      elements - The elements to include in the list.
      Returns:
      A new ArrayList containing the elements.
    • createMap

      public Object createMap(Map<Object,Object> map)
      Creates a YAML-compatible map.
      Specified by:
      createMap in class DynamicOps<Object>
      Parameters:
      map - The map entries to include.
      Returns:
      A new LinkedHashMap to preserve entry order.
    • getStringValue

      public Optional<String> getStringValue(Object input)
      Specified by:
      getStringValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the string if the input is a String.
    • getIntValue

      public Optional<Integer> getIntValue(Object input)
      Specified by:
      getIntValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the integer if the input is an Integer.
    • getLongValue

      public Optional<Long> getLongValue(Object input)
      Specified by:
      getLongValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the long if the input is a Long.
    • getFloatValue

      public Optional<Float> getFloatValue(Object input)
      Specified by:
      getFloatValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the float if the input is a Float.
    • getDoubleValue

      public Optional<Double> getDoubleValue(Object input)
      Specified by:
      getDoubleValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the double if the input is a Double.
    • getBooleanValue

      public Optional<Boolean> getBooleanValue(Object input)
      Specified by:
      getBooleanValue in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the boolean if the input is a Boolean.
    • getList

      public Optional<List<Object>> getList(Object input)
      Specified by:
      getList in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the list if the input is a List.
    • getMap

      public Optional<Map<Object,Object>> getMap(Object input)
      Specified by:
      getMap in class DynamicOps<Object>
      Parameters:
      input - The object to check.
      Returns:
      An Optional containing the map if the input is a Map.
    • empty

      public Object empty()
      Specified by:
      empty in class DynamicOps<Object>
      Returns:
      A null reference representing an empty YAML node.
    • parse

      public Object parse(String yamlText)
      Parses a YAML string into a normalized Java object structure.
      Parameters:
      yamlText - The raw YAML text.
      Returns:
      A normalized object (Map, List, or Primitive).
    • parse

      public Object parse(InputStream in)
      Parses YAML data from an InputStream into a normalized Java object structure.
      Parameters:
      in - The input stream containing YAML data.
      Returns:
      A normalized object.
    • dump

      public static String dump(Object obj)
      Serializes a Java object structure into a YAML string.
      Parameters:
      obj - The object to dump.
      Returns:
      The formatted YAML string.