Class YamlLine<T extends YamlLine<T>>
- java.lang.Object
-
- ru.vyarus.yaml.updater.parse.common.model.TreeNode<T>
-
- ru.vyarus.yaml.updater.parse.common.model.YamlLine<T>
-
- Type Parameters:
T- child nodes type
- All Implemented Interfaces:
LineNumberAware
- Direct Known Subclasses:
CmtNode,StructNode
public abstract class YamlLine<T extends YamlLine<T>> extends TreeNode<T> implements LineNumberAware
Base class for comments and structure parsers. In both cases model represent one or more yaml file lines. The only exception is lists: if list item contains object then it would be always a child of root list item (and so sometimes two structure lines should be rendered as a single line: special marker in list item used to indicate this).- Since:
- 07.05.2021
-
-
Field Summary
Fields Modifier and Type Field Description static charPATH_SEPARATORSeparator character for yaml paths.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tfind(java.lang.String path)Search for yaml node by path.java.util.List<T>getAllPropertiesIncludingScalarLists()Same asgetTreeLeaves()but also includes scalar list items for list nodes.abstract java.lang.StringgetIdentityValue()Returned values assumed to be used in node comparisons.java.lang.StringgetKey()intgetLineNum()intgetPadding()java.util.List<T>getTreeLeaves()Assumed iterative usage: first all properties selected and then list nodes are post processed (because almost always list nodes processing is situation-specific).java.lang.StringgetYamlPath()Note, for list items possible empty dash line is ignored (not a level in path).java.lang.StringgetYamlPathElement()Cases: - for property or object (or list) root: "name" - for list item: "[n]" (where n number from 0).booleanisEmptyDash()booleanisListItem()In all cases list item means "dash".booleanisListItemWithProperty()booleanisObjectListItem()booleanisProperty()voidsetKey(java.lang.String key)voidsetListItem(boolean listItem)voidsetListItemWithProperty(boolean listItemWithProperty)voidsetPadding(int padding)Changes item padding.-
Methods inherited from class ru.vyarus.yaml.updater.parse.common.model.TreeNode
add, addAll, getChildren, getRoot, getRootProperties, hasChildren, hasListValue, setRoot
-
-
-
-
Field Detail
-
PATH_SEPARATOR
public static final char PATH_SEPARATOR
Separator character for yaml paths. Not dot because yaml property could have dot in name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
YamlLine
public YamlLine(T root, int padding, int lineNum)
-
-
Method Detail
-
getPadding
public int getPadding()
- Returns:
- left padding of line (whitespace before)
-
setPadding
public void setPadding(int padding)
Changes item padding. Required for merge shifts (when old and new files has different paddings and must be unified).- Parameters:
padding- updated padding
-
getLineNum
public int getLineNum()
- Specified by:
getLineNumin interfaceLineNumberAware- Returns:
- yaml line number in file (counting from 1)
-
getKey
public java.lang.String getKey()
- Returns:
- property name or null if line does not represent property
-
setKey
public void setKey(java.lang.String key)
- Parameters:
key- property name
-
isListItem
public boolean isListItem()
In all cases list item means "dash". For scalar value property and (or) value would be in the same object. For object item, all properties would be children.- Returns:
- true to indicate list item
-
setListItem
public void setListItem(boolean listItem)
- Parameters:
listItem- indicate list item
-
isListItemWithProperty
public boolean isListItemWithProperty()
- Returns:
- true if children are object item and the first property must start on the same line as dash
-
setListItemWithProperty
public void setListItemWithProperty(boolean listItemWithProperty)
- Parameters:
listItemWithProperty- indicate first object property must start on the same line with dash
-
isProperty
public boolean isProperty()
- Returns:
- true for property line
-
isObjectListItem
public boolean isObjectListItem()
- Returns:
- true for list items containing object (not scalar value)
-
isEmptyDash
public boolean isEmptyDash()
- Returns:
- true when list item starts from new line and current line contains only dash
-
getIdentityValue
public abstract java.lang.String getIdentityValue()
Returned values assumed to be used in node comparisons.- Returns:
- maximally accurate node value (as much as possible for used parser)
-
getYamlPath
public java.lang.String getYamlPath()
Description copied from class:TreeNodeNote, for list items possible empty dash line is ignored (not a level in path).- Specified by:
getYamlPathin classTreeNode<T extends YamlLine<T>>- Returns:
- property path in yaml structure (like prop1/prop2[3]/sub) or null for tree root
-
getYamlPathElement
public java.lang.String getYamlPathElement()
Description copied from class:TreeNodeCases: - for property or object (or list) root: "name" - for list item: "[n]" (where n number from 0). Note that scalar value will be contained in the same node and for object item it would be "empty" wrapper containing object properties as children. - for comment only node: empty string (no identity)- Specified by:
getYamlPathElementin classTreeNode<T extends YamlLine<T>>- Returns:
- yaml path element represented by this node.
-
find
public T find(java.lang.String path)
Description copied from class:TreeNodeSearch for yaml node by path. For list items path should include exact item number (e.g. list[1]), wildcard search not supported.IMPORTANT: path must NOT include node itself (node from where search started)
-
getTreeLeaves
public java.util.List<T> getTreeLeaves()
Assumed iterative usage: first all properties selected and then list nodes are post processed (because almost always list nodes processing is situation-specific).- Specified by:
getTreeLeavesin classTreeNode<T extends YamlLine<T>>- Returns:
- all scalar properties (but not list items) and properties with list values (but not properties inside list values!)
-
getAllPropertiesIncludingScalarLists
public java.util.List<T> getAllPropertiesIncludingScalarLists()
Same asgetTreeLeaves()but also includes scalar list items for list nodes.- Returns:
- all scalar properties and properties with list values (but not props inside list values!)
-
-