Class MergeUtils


  • public abstract class MergeUtils
    extends java.lang.Object
    Utility to process merge keys (https://yaml.org/type/merge.html) of the MappingNode
    • Constructor Detail

      • MergeUtils

        public MergeUtils()
    • Method Detail

      • asMappingNode

        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 - The node to be transformed.
        Returns:
        A MappingNode representation of the input node.
      • flatten

        public java.util.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 - The MappingNode to process for merge keys.
        Returns:
        A list of NodeTuple containing the merged keys and values.
        See Also:
        YAML Merge Key Specification
      • filter

        private Tuple<java.util.List<NodeTuple>,​java.util.Set<java.lang.String>> filter​(java.util.List<NodeTuple> mergables,
                                                                                              java.util.Set<java.lang.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 - The list of NodeTuples to process.
        filter - A set of string values used as a filter. NodeTuples with keys in this set are omitted.
        Returns:
        A tuple of a list of filtered NodeTuples and a set containing the keys of the NodeTuples in the returned list.