Search in sources :

Example 1 with Maps.newTreeMap

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Maps.newTreeMap(com.google.common.collect.Maps.newTreeMap)

Example 2 with Maps.newTreeMap

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Maps.newTreeMap(com.google.common.collect.Maps.newTreeMap) Nullable(javax.annotation.Nullable)

Aggregations

Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 Maps.newTreeMap (com.google.common.collect.Maps.newTreeMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 NodeRef (org.locationtech.geogig.api.NodeRef)2 ValueDifference (com.google.common.collect.MapDifference.ValueDifference)1 Nullable (javax.annotation.Nullable)1 Node (org.locationtech.geogig.api.Node)1 ObjectId (org.locationtech.geogig.api.ObjectId)1