org.javers.core.diff.ObjectGraph 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.core.graph.ObjectNode;
import org.javers.core.metamodel.object.Cdo;
import org.javers.core.metamodel.object.GlobalId;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author bartosz walacik
*/
public abstract class ObjectGraph {
private final Set nodes;
public ObjectGraph(Set nodes) {
this.nodes = nodes;
}
public Set nodes() {
return nodes;
}
public Set cdos() {
return nodes().stream().map(node -> (T) node.getCdo()).collect(Collectors.toSet());
}
public Set globalIds() {
return nodes().stream().map(ObjectNode::getGlobalId).collect(Collectors.toSet());
}
public Optional get(GlobalId globalId) {
return nodes.stream()
.filter(node -> globalId.equals(node.getGlobalId()))
.findFirst()
.map(node -> (T) node.getCdo());
}
}