Class BaseConstructor
- java.lang.Object
-
- org.snakeyaml.engine.v2.constructor.BaseConstructor
-
- Direct Known Subclasses:
StandardConstructor
public abstract class BaseConstructor extends java.lang.Object
Base code
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BaseConstructor.RecursiveTuple<T,K>
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<Node,java.lang.Object>
constructedObjects
private java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Map<java.lang.Object,java.lang.Object>,BaseConstructor.RecursiveTuple<java.lang.Object,java.lang.Object>>>
maps2fill
private java.util.Set<Node>
recursiveObjects
private java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Set<java.lang.Object>,java.lang.Object>>
sets2fill
protected LoadSettings
settings
keep the settingsprotected java.util.Map<Tag,ConstructNode>
tagConstructors
It maps the (explicit or implicit) tag to the Construct implementation.
-
Constructor Summary
Constructors Constructor Description BaseConstructor(LoadSettings settings)
Create
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
construct(Node node)
Construct complete YAML document.protected java.util.Map<java.lang.Object,java.lang.Object>
constructMapping(MappingNode node)
Create filled Map from the provided Nodeprotected void
constructMapping2ndStep(MappingNode node, java.util.Map<java.lang.Object,java.lang.Object> mapping)
Fill the mapping with the data from provided nodeprotected java.lang.Object
constructObject(Node node)
Construct object from the specified Node.protected java.lang.Object
constructObjectNoCheck(Node node)
Construct object from the specified Node.protected java.lang.String
constructScalar(ScalarNode node)
Create String from the provided scalar nodeprotected java.util.List<java.lang.Object>
constructSequence(SequenceNode node)
Create instance of Listprotected void
constructSequenceStep2(SequenceNode node, java.util.Collection<java.lang.Object> collection)
Fill the collection with the data from provided nodeprotected java.util.Set<java.lang.Object>
constructSet(MappingNode node)
Create instance of Set from mapping nodeprotected void
constructSet2ndStep(MappingNode node, java.util.Set<java.lang.Object> set)
Fill the Map with the data from the nodejava.lang.Object
constructSingleDocument(java.util.Optional<Node> optionalNode)
Ensure that the stream contains a single document and construct itprotected java.util.List<java.lang.Object>
createEmptyListForNode(SequenceNode node)
Create List implementation.protected java.util.Map<java.lang.Object,java.lang.Object>
createEmptyMapFor(MappingNode node)
Create Map implementation.protected java.util.Set<java.lang.Object>
createEmptySetForNode(MappingNode node)
Create Set implementation.private void
fillRecursive()
protected java.util.Optional<ConstructNode>
findConstructorFor(Node node)
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.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.
-
-
-
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
-
maps2fill
private final java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Map<java.lang.Object,java.lang.Object>,BaseConstructor.RecursiveTuple<java.lang.Object,java.lang.Object>>> maps2fill
-
sets2fill
private final java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Set<java.lang.Object>,java.lang.Object>> sets2fill
-
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)
- 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 sourcecollection
- - 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 sourcemapping
- - 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/valuekey
- - the key to add to mapvalue
- - 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 sourceset
- - 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 keykey
- - the item to add to the set
-
-