Class YamlModelUtils


  • public final class YamlModelUtils
    extends java.lang.Object
    Yaml model utils. Aggregates logic common for both parsers.
    Since:
    09.06.2021
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanPropertyName​(java.lang.String key)
      Property name may be quited in yaml file and contain escaped symbols.
      static java.lang.String cleanPropertyPath​(java.lang.String path, boolean replaceDots)
      Try to correctly split path elements and unescape quoted property names.
      static <T extends YamlLine<T>>
      T
      findNextLineRoot​(int padding, T previousNode)
      Searches for correct parent node by current node padding.
      static <T extends YamlLine<T>>
      void
      listItem​(T node)
      Marks node as list item.
      static java.lang.String removeLeadingPath​(java.lang.String element, java.lang.String path)
      Removes leading part of the path (specified).
      static <T extends YamlLine<T>>
      void
      virtualListItem​(T node)
      Marks node as virtual list item node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • findNextLineRoot

        public static <T extends YamlLine<T>> T findNextLineRoot​(int padding,
                                                                 T previousNode)
        Searches for correct parent node by current node padding. Used while parsing yaml file line-by-line.
        Type Parameters:
        T - type of target node
        Parameters:
        padding - current node padding
        previousNode - previously parsed node (usually prev. line)
        Returns:
        root node for current padding or null
      • listItem

        public static <T extends YamlLine<T>> void listItem​(T node)
        Marks node as list item. For scalar values, value node itself is marked as list item. For object items, it must be empty line with dash (otherwise virtual object must be created to properly aggregate item object).
        Type Parameters:
        T - node type
        Parameters:
        node - real node to mark as list item
      • virtualListItem

        public static <T extends YamlLine<T>> void virtualListItem​(T node)
        Marks node as virtual list item node. Such nodes used only for grouping item object properties, when first property is on the same line as dash (so without additional object it is impossible to preserve hierarchy). In case of virtual node two objects repsents same yaml line: this one for dash and first child is a property part.
        Type Parameters:
        T - node type
        Parameters:
        node - virtual node to mark
      • removeLeadingPath

        public static java.lang.String removeLeadingPath​(java.lang.String element,
                                                         java.lang.String path)
        Removes leading part of the path (specified). Cuts off separator after specified path if required.
        Parameters:
        element - leading element to remove from path
        path - complete path
        Returns:
        remaining path
      • cleanPropertyName

        public static java.lang.String cleanPropertyName​(java.lang.String key)
        Property name may be quited in yaml file and contain escaped symbols. Comments parser extracts property exactly as-is, but for inner comparisons cleaned version must be used. Single quoted property may contain only '' single quote escape. Double-quoted property may contain escapes with backslash, including unicode symbols (but not every symbol could be escaped! only supported symbols - see yaml spec).

        NOTE: cleanups should be unified with snakeyaml behaviour (same behavior)

        Parameters:
        key - property name to clean
        Returns:
        cleaned property name
      • cleanPropertyPath

        public static java.lang.String cleanPropertyPath​(java.lang.String path,
                                                         boolean replaceDots)
        Try to correctly split path elements and unescape quoted property names. For dot separator also correctly replace dots with paths (because dots might be under quotes simple replace would lead to incorrect name).
        Parameters:
        path - path to analyze
        replaceDots - assume dots used as separator, which must be replaced to normal separator
        Returns:
        clean string