org.javers.core.graph.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.graph;
import org.javers.core.metamodel.object.GlobalId;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author bartosz walacik
*/
public abstract class ObjectGraph {
private final Set> nodes;
protected ObjectGraph(Set> nodes) {
this.nodes = Collections.unmodifiableSet(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());
}
}