Class BaseConstructor

  • Direct Known Subclasses:
    StandardConstructor

    public abstract class BaseConstructor
    extends java.lang.Object
    Base code
    • Field Detail

      • tagConstructors

        protected final java.util.Map<Tag,​ConstructNode> tagConstructors
        It maps the (explicit or implicit) tag to the Construct implementation.
      • constructedObjects

        final java.util.Map<Node,​java.lang.Object> constructedObjects
      • recursiveObjects

        private final java.util.Set<Node> recursiveObjects
      • settings

        protected LoadSettings settings
        keep the settings
    • Constructor Detail

      • BaseConstructor

        public BaseConstructor​(LoadSettings settings)
        Create
        Parameters:
        settings - - the configuration option
    • Method Detail

      • constructSingleDocument

        public java.lang.Object constructSingleDocument​(java.util.Optional<Node> optionalNode)
        Ensure that the stream contains a single document and construct it
        Parameters:
        optionalNode - - composed Node
        Returns:
        constructed instance
      • construct

        protected java.lang.Object construct​(Node node)
        Construct complete YAML document. Call the second step in case of recursive structures. At the end cleans all the state.
        Parameters:
        node - root Node
        Returns:
        Java instance
      • fillRecursive

        private void fillRecursive()
      • constructObject

        protected java.lang.Object constructObject​(Node node)
        Construct object from the specified Node. Return existing instance if the node is already constructed.
        Parameters:
        node - Node to be constructed
        Returns:
        Java instance
      • constructObjectNoCheck

        protected java.lang.Object constructObjectNoCheck​(Node node)
        Construct object from the specified Node. It does not check if existing instance the node is already constructed.
        Parameters:
        node - - the source
        Returns:
        instantiated object
      • findConstructorFor

        protected java.util.Optional<ConstructNode> findConstructorFor​(Node node)
        Select ConstructNode inside the provided Node or the one associated with the Tag
        Parameters:
        node - Node to construct an instance from
        Returns:
        ConstructNode implementation for the specified node
      • constructScalar

        protected java.lang.String constructScalar​(ScalarNode node)
        Create String from the provided scalar node
        Parameters:
        node - - the source
        Returns:
        value of the scalar node
      • createEmptyListForNode

        protected java.util.List<java.lang.Object> createEmptyListForNode​(SequenceNode node)
        Create List implementation. By default, it returns the value configured in the settings in getDefaultList(). Any custom List implementation can be provided.
        Parameters:
        node - - the node to fill the List
        Returns:
        empty List to fill
      • createEmptySetForNode

        protected java.util.Set<java.lang.Object> createEmptySetForNode​(MappingNode node)
        Create Set implementation. By default, it returns the value configured in the settings in getDefaultSet(). Any custom Set implementation can be provided.
        Parameters:
        node - - the node to fill the Set
        Returns:
        empty Set to fill
      • createEmptyMapFor

        protected java.util.Map<java.lang.Object,​java.lang.Object> createEmptyMapFor​(MappingNode node)
        Create Map implementation. By default, it returns the value configured in the settings in getDefaultMap(). Any custom Map implementation can be provided.
        Parameters:
        node - - the node to fill the Map
        Returns:
        empty Map to fill
      • constructSequence

        protected java.util.List<java.lang.Object> constructSequence​(SequenceNode node)
        Create instance of List
        Parameters:
        node - - the source
        Returns:
        filled List
      • constructSequenceStep2

        protected void constructSequenceStep2​(SequenceNode node,
                                              java.util.Collection<java.lang.Object> collection)
        Fill the collection with the data from provided node
        Parameters:
        node - - the source
        collection - - the collection to fill
      • constructSet

        protected java.util.Set<java.lang.Object> constructSet​(MappingNode node)
        Create instance of Set from mapping node
        Parameters:
        node - - the source
        Returns:
        filled Set
      • constructMapping

        protected java.util.Map<java.lang.Object,​java.lang.Object> constructMapping​(MappingNode node)
        Create filled Map from the provided Node
        Parameters:
        node - - the source
        Returns:
        filled Map
      • constructMapping2ndStep

        protected void constructMapping2ndStep​(MappingNode node,
                                               java.util.Map<java.lang.Object,​java.lang.Object> mapping)
        Fill the mapping with the data from provided node
        Parameters:
        node - - the source
        mapping - - empty map to be filled
      • postponeMapFilling

        protected void postponeMapFilling​(java.util.Map<java.lang.Object,​java.lang.Object> mapping,
                                          java.lang.Object key,
                                          java.lang.Object value)
        if keyObject is created it 2 steps we should postpone putting it in map because it may have different hash after initialization compared to clean just created one. And map of course does not observe key hashCode changes.
        Parameters:
        mapping - - the mapping to add key/value
        key - - the key to add to map
        value - - the value behind the key
      • constructSet2ndStep

        protected void constructSet2ndStep​(MappingNode node,
                                           java.util.Set<java.lang.Object> set)
        Fill the Map with the data from the node
        Parameters:
        node - - the source
        set - - empty set to fill
      • postponeSetFilling

        protected void postponeSetFilling​(java.util.Set<java.lang.Object> set,
                                          java.lang.Object key)
        if keyObject is created it 2 steps we should postpone putting it into the set because it may have different hash after initialization compared to clean just created one. And set of course does not observe value hashCode changes.
        Parameters:
        set - - the set to add the key
        key - - the item to add to the set