Class CmtNodeFactory


  • public final class CmtNodeFactory
    extends java.lang.Object
    Helper factory class for creating correct node objects. It is not used by main code and exists only for tests and to simplify manual tree modifications in custom UpdateListener implementations.

    It is important to keep in mind that comments parser does not care of exact value, but care how many lines it takes (it is important to write node back exactly as-is). Value is everything after semicolon.

    Like value, comment is also stored as-is, from line start. Comment is everything above node before previous node. Comment-only node (without key or value) may go last on any tree level to represent trailing comment (but, usually, it's only useful for root node to represent comment at the end of file because in other cases all comment lines would simply be assigned to the following node (no matter what level - in some cases impossible to track)).

    Since:
    18.08.2021
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CmtNode createListObject​(CmtNode root, int padding, int lineNum, CmtNode... props)
      Creates list item node for object.
      static CmtNode createListValue​(CmtNode root, int padding, int lineNum, java.lang.String... value)
      Creates scalar list value.
      static CmtNode createProperty​(CmtNode root, int padding, int lineNum, java.lang.String key, java.lang.String... value)
      Could be used to create any node type: with both key and value it would be property, without value - subtree root and without both key and value - stub for virtualized list item.
      • Methods inherited from class java.lang.Object

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

      • createProperty

        public static CmtNode createProperty​(CmtNode root,
                                             int padding,
                                             int lineNum,
                                             java.lang.String key,
                                             java.lang.String... value)
        Could be used to create any node type: with both key and value it would be property, without value - subtree root and without both key and value - stub for virtualized list item.

        PAY ATTENTION: value include EVERYTHING after colon! (including separating space)

        Parameters:
        root - root node (may be null)
        padding - padding
        lineNum - target line number
        key - property name (may be null)
        value - property value lines (may be null for subtree root)
        Returns:
        created node
      • createListObject

        public static CmtNode createListObject​(CmtNode root,
                                               int padding,
                                               int lineNum,
                                               CmtNode... props)
        Creates list item node for object. Grouping node is required to preserve object structure.
        Parameters:
        root - root node (may be null)
        padding - padding
        lineNum - target dash line number
        props - list item object properties (each could be subtree)
        Returns:
        created node
      • createListValue

        public static CmtNode createListValue​(CmtNode root,
                                              int padding,
                                              int lineNum,
                                              java.lang.String... value)
        Creates scalar list value.

        PAY ATTENTION: value include EVERYTHING after colon! (including separating space)

        Parameters:
        root - root node (may be null)
        padding - padding
        lineNum - target dash line number
        value - property value lines (may be null)
        Returns:
        created node