All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javers.core.graph.ObjectGraph Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy