org.javers.core.diff.NodeMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.core.diff;
import org.javers.common.validation.Validate;
import org.javers.core.graph.ObjectNode;
import org.javers.core.metamodel.object.GlobalId;
import java.util.*;
/**
* @author bartosz walacik
*/
class NodeMatcher {
/**
* matching based on {@link org.javers.core.metamodel.object.GlobalId}
*/
public List match(GraphPair graphPair) {
Validate.argumentIsNotNull(graphPair);
List pairs = new ArrayList<>();
Map rightMap = asMap(graphPair.getRightNodeSet());
for (ObjectNode left : graphPair.getLeftNodeSet()) {
GlobalId key = left.getGlobalId();
if (rightMap.containsKey(key)) {
pairs.add(new NodePair(left, rightMap.get(key), graphPair.getCommitMetadata()));
}
}
return pairs;
}
private Map asMap(Set nodes) {
Map map = new HashMap<>();
for (ObjectNode node : nodes) {
map.put(node.getGlobalId(),node);
}
return map;
}
}