Class Composer

java.lang.Object
org.snakeyaml.engine.v2.composer.Composer
All Implemented Interfaces:
Iterator<Node>

public class Composer extends Object implements Iterator<Node>
Creates a node graph from parser events.

Corresponds to the 'Composer' step as described in chapter 3.1.2 of the YAML Specification.

It implements Iterator to get the stream of Nodes from the input.
  • Field Details

    • parser

      protected final Parser parser
      Event parser
    • scalarResolver

      private final ScalarResolver scalarResolver
    • anchors

      private final Map<Anchor,Node> anchors
    • recursiveNodes

      private final Set<Node> recursiveNodes
    • settings

      private final LoadSettings settings
    • blockCommentsCollector

      private final CommentEventsCollector blockCommentsCollector
    • inlineCommentsCollector

      private final CommentEventsCollector inlineCommentsCollector
    • nonScalarAliasesCount

      private int nonScalarAliasesCount
  • Constructor Details

    • Composer

      @Deprecated public Composer(Parser parser, LoadSettings settings)
      Deprecated.
      use the other constructor with LoadSettings first
      Parameters:
      parser - - the input
      settings - - configuration options
    • Composer

      public Composer(LoadSettings settings, Parser parser)
      Create
      Parameters:
      settings - - configuration options
      parser - - the input
  • Method Details

    • hasNext

      public boolean hasNext()
      Checks if further documents are available.
      Specified by:
      hasNext in interface Iterator<Node>
      Returns:
      true if there is at least one more document.
    • getSingleNode

      public Optional<Node> getSingleNode()
      Reads a document from a source that contains only one document.

      If the stream contains more than one document an exception is thrown.

      Returns:
      The root node of the document or Optional.empty() if no document is available.
    • next

      public Node next()
      Reads and composes the next document.
      Specified by:
      next in interface Iterator<Node>
      Returns:
      The root node of the document or null if no more documents are available.
    • composeNode

      private Node composeNode(Optional<Node> parent)
    • registerAnchor

      private void registerAnchor(Anchor anchor, Node node)
    • composeScalarNode

      protected Node composeScalarNode(Optional<Anchor> anchor, List<CommentLine> blockComments)
      Create ScalarNode
      Parameters:
      anchor - - anchor if present
      blockComments - - comments before the Node
      Returns:
      Node
    • composeSequenceNode

      protected SequenceNode composeSequenceNode(Optional<Anchor> anchor)
      Compose a sequence Node from the input starting with SequenceStartEvent
      Parameters:
      anchor - - anchor if present
      Returns:
      parsed Node
    • composeMappingNode

      protected Node composeMappingNode(Optional<Anchor> anchor)
      Create mapping Node
      Parameters:
      anchor - - anchor if present
      Returns:
      Node
    • composeMappingChildren

      protected void composeMappingChildren(List<NodeTuple> children, MappingNode node)
      Add the provided Node to the children as the last child
      Parameters:
      children - - the list to be extended
      node - - the child to the children
    • composeKeyNode

      protected Node composeKeyNode(MappingNode node)
      To be able to override composeNode(node) which is a key
      Parameters:
      node - - the source
      Returns:
      node
    • composeValueNode

      protected Node composeValueNode(MappingNode node)
      To be able to override composeNode(node) which is a value
      Parameters:
      node - - the source
      Returns:
      node