Top Description Constructors Methods
org.snakeyaml.engine.v2.util

public abstract Class MergeUtils

extends Object
Class Inheritance
Imports
org.snakeyaml.engine.v2.nodes.MappingNode, .Node, .NodeTuple, .ScalarNode, .SequenceNode, java.util.ArrayList, .HashSet, .List, .Set

Utility to process merge keys (https://yaml.org/type/merge.html) of the MappingNode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract MappingNode

Returns:

A MappingNode representation of the input node.
asMappingNode
(Node
The node to be transformed.
node
)

Converts the specified node into a MappingNode.

private Tuple<List<NodeTuple>, Set<String>>

Returns:

A tuple of a list of filtered NodeTuples and a set containing the keys of the NodeTuples in the returned list.
filter
(List<NodeTuple>
The list of NodeTuples to process.
mergables
,
Set<String>
A set of string values used as a filter. NodeTuples with keys in this set are omitted.
filter
)

Filters out NodeTuples with ScalarNode keys that are present in the provided filter set.

public List<NodeTuple>

Returns:

A list of NodeTuple containing the merged keys and values.
flatten
(MappingNode
The MappingNode to process for merge keys.
node
)

Processes and resolves merge keys in a MappingNode, merging resolved key/values into the node.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MergeUtilsback to summary
public MergeUtils()

Method Detail

asMappingNodeback to summary
public abstract MappingNode asMappingNode(Node node)

Converts the specified node into a MappingNode.

This method is designed to transform various types of Node into a MappingNode, enabling further processing such as merging of keys.

Parameters
node:Node

The node to be transformed.

Returns:MappingNode

A MappingNode representation of the input node.

filterback to summary
private Tuple<List<NodeTuple>, Set<String>> filter(List<NodeTuple> mergables, Set<String> filter)

Filters out NodeTuples with ScalarNode keys that are present in the provided filter set.

This utility method supports the flatten(MappingNode) method by filtering out node tuples based on their key's presence in a set of strings. This ensures that the returned list of NodeTuples does not contain any keys that are present in the filter set. The set of strings returned alongside the list represents the keys of the NodeTuples in the returned list, facilitating the identification of newly added keys as part of the merge process.

Parameters
mergables:List<NodeTuple>

The list of NodeTuples to process.

filter:Set<String>

A set of string values used as a filter. NodeTuples with keys in this set are omitted.

Returns:Tuple<List<NodeTuple>, Set<String>>

A tuple of a list of filtered NodeTuples and a set containing the keys of the NodeTuples in the returned list.

flattenback to summary
public List<NodeTuple> flatten(MappingNode node)

Processes and resolves merge keys in a MappingNode, merging resolved key/values into the node.

Implements the YAML merge key feature by examining the nodes within the provided node and merging keys from referenced by "merge key" map(s) into the current mapping as per the YAML specification. Handling of duplicate keys is defined by the order of appearance in the mapping node, with priority given to the keys defined in node and the the earliest occurrences in the merging ones.

Parameters
node:MappingNode

The MappingNode to process for merge keys.

Returns:List<NodeTuple>

A list of NodeTuple containing the merged keys and values.

See Also
YAML Merge Key Specification