use of com.google.common.collect.Maps.newTreeMap in project GeoGig by boundlessgeo.
the class TreeDifference method findChanges.
/**
* Finds child refs that are named the same, point to different trees, but are not pure metadata
* changes
*
* @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;
}
use of com.google.common.collect.Maps.newTreeMap in project GeoGig by boundlessgeo.
the class TreeDifference method findPureMetadataChanges.
/**
* Finds tree pointers that point to the same tree (path and object id) on the left and right
* sides of the comparison but have different {@link NodeRef#getMetadataId() metadata ids}
*/
public Map<NodeRef, NodeRef> findPureMetadataChanges() {
SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap();
SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap();
Map<NodeRef, NodeRef> matches = Maps.newTreeMap();
for (Map.Entry<String, MutableTree> e : leftEntries.entrySet()) {
final String nodePath = e.getKey();
final MutableTree leftTree = e.getValue();
final Node leftNode = leftTree.getNode();
@Nullable final MutableTree rightTree = rightEntries.get(nodePath);
final Node rightNode = rightTree == null ? null : rightTree.getNode();
if (leftNode.equals(rightNode)) {
final Optional<ObjectId> leftMetadata = leftNode.getMetadataId();
final Optional<ObjectId> rightMetadata = rightNode.getMetadataId();
if (!leftMetadata.equals(rightMetadata)) {
String parentPath = NodeRef.parentPath(nodePath);
NodeRef leftRef = new NodeRef(leftNode, parentPath, ObjectId.NULL);
NodeRef rightRef = new NodeRef(rightNode, parentPath, ObjectId.NULL);
matches.put(leftRef, rightRef);
}
}
}
return matches;
}
Aggregations