Package org.apache.commons.configuration2.tree

# Class MergeCombiner

java.lang.Object
org.apache.commons.configuration2.tree.NodeCombiner
org.apache.commons.configuration2.tree.MergeCombiner

public class MergeCombiner extends NodeCombiner

A specialized implementation of the `NodeCombiner` interface that performs a merge from two passed in node hierarchies.

This combiner performs the merge using a few rules:

1. Nodes can be merged when attributes that appear in both have the same value.
2. Only a single node in the second file is considered a match to the node in the first file.
3. Attributes in nodes that match are merged.
4. Nodes in both files that do not match are added to the result.

Since:
  1.7

- ## Field Summary

  ### Fields inherited from class org.apache.commons.configuration2.tree.NodeCombiner

  `HANDLER`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MergeCombiner()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addAttributes(ImmutableNode.Builder result, ImmutableNode node1, ImmutableNode node2)`
  Handles the attributes during a combination process.
  `protected ImmutableNode`
  `canCombine(ImmutableNode node2, ImmutableNode child, List<ImmutableNode> children2)`
  Tests if the first node can be combined with the second node.
  `ImmutableNode`
  `combine(ImmutableNode node1, ImmutableNode node2)`
  Combines the given nodes to a new union node.

  ### Methods inherited from class org.apache.commons.configuration2.tree.NodeCombiner

  `addListNode, getListNodes, isListNode`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MergeCombiner

    public MergeCombiner()
    Constructs a new instance.

- ## Method Details

  - ### addAttributes

    protected void addAttributes(ImmutableNode.Builder result, ImmutableNode node1, ImmutableNode node2)
    Handles the attributes during a combination process. First all attributes of the first node will be added to the result. Then all attributes of the second node, which are not contained in the first node, will also be added.
    Parameters:
      `result` - the builder for the resulting node
      `node1` - the first node
      `node2` - the second node

  - ### canCombine

    protected ImmutableNode canCombine(ImmutableNode node2, ImmutableNode child, List<ImmutableNode> children2)
    Tests if the first node can be combined with the second node. A node can only be combined if its attributes are all present in the second node and they all have the same value.
    Parameters:
      `node2` - the second node
      `child` - the child node (of the first node)
      `children2` - the children of the 2nd node
    Returns:
      a child of the second node, with which a combination is possible

  - ### combine

    public ImmutableNode combine(ImmutableNode node1, ImmutableNode node2)
    Combines the given nodes to a new union node.
    Specified by:
      `combine` in class `NodeCombiner`
    Parameters:
      `node1` - the first source node
      `node2` - the second source node
    Returns:
      the union node