Class Composer

  • All Implemented Interfaces:
    java.util.Iterator<Node>

    public class Composer
    extends java.lang.Object
    implements java.util.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 Detail

      • parser

        protected final Parser parser
        Event parser
      • anchors

        private final java.util.Map<Anchor,​Node> anchors
      • recursiveNodes

        private final java.util.Set<Node> recursiveNodes
      • nonScalarAliasesCount

        private int nonScalarAliasesCount
    • Constructor Detail

      • 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 Detail

      • hasNext

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

        public java.util.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 java.util.Iterator<Node>
        Returns:
        The root node of the document or null if no more documents are available.
      • composeNode

        private Node composeNode​(java.util.Optional<Node> parent)
      • registerAnchor

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

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

        protected SequenceNode composeSequenceNode​(java.util.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​(java.util.Optional<Anchor> anchor)
        Create mapping Node
        Parameters:
        anchor - - anchor if present
        Returns:
        Node
      • composeMappingChildren

        protected void composeMappingChildren​(java.util.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