Example usage for com.google.common.collect SortedMapDifference entriesDiffering

List of usage examples for com.google.common.collect SortedMapDifference entriesDiffering

Introduction

In this page you can find the example usage for com.google.common.collect SortedMapDifference entriesDiffering.

Prototype

@Override
    SortedMap<K, ValueDifference<V>> entriesDiffering();

Source Link

Usage

From source file:org.geogit.api.plumbing.diff.TreeDifference.java

/**
 * Finds child refs that are named the same, point to different trees, but are not pure metadata
 * changes//from   w w w .  j a v a 2  s  . c  om
 * 
 * @return a sorted map of old/new references to a trees that have changed, deepest paths first
 */
public SortedMap<NodeRef, NodeRef> findChanges() {

    SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap();
    SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap();

    final Map<NodeRef, NodeRef> pureMetadataChanges = findPureMetadataChanges();

    SortedMapDifference<String, MutableTree> difference;
    difference = difference(leftEntries, rightEntries);

    SortedMap<String, ValueDifference<MutableTree>> entriesDiffering;
    entriesDiffering = difference.entriesDiffering();

    SortedMap<NodeRef, NodeRef> matches = Maps.newTreeMap(MutableTree.DEEPEST_FIRST_COMPARATOR);

    for (Map.Entry<String, ValueDifference<MutableTree>> e : entriesDiffering.entrySet()) {
        String nodePath = e.getKey();
        String parentPath = NodeRef.parentPath(nodePath);
        ValueDifference<MutableTree> vd = e.getValue();
        MutableTree left = vd.leftValue();
        MutableTree right = vd.rightValue();
        NodeRef lref = new NodeRef(left.getNode(), parentPath, ObjectId.NULL);
        NodeRef rref = new NodeRef(right.getNode(), parentPath, ObjectId.NULL);
        if (!pureMetadataChanges.containsKey(lref)) {
            matches.put(lref, rref);
        }
    }
    return matches;
}