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

org.javers.core.diff.GraphPair Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
package org.javers.core.diff;

import org.javers.core.graph.ObjectNode;
import java.util.Collections;
import java.util.Set;
import static org.javers.common.collections.Sets.difference;

/**
 * @author bartosz walacik
 */
public class GraphPair {

    private final ObjectGraph leftGraph;
    private final ObjectGraph rightGraph;

    private final Set onlyOnLeft;
    private final Set onlyOnRight;

    public GraphPair(ObjectGraph leftGraph, ObjectGraph rightGraph) {
        this.leftGraph = leftGraph;
        this.rightGraph = rightGraph;

        this.onlyOnLeft = difference(leftGraph.nodes(), rightGraph.nodes());
        this.onlyOnRight = difference(rightGraph.nodes(), leftGraph.nodes());
    }

    //for initial
    public GraphPair(ObjectGraph currentGraph) {
        this.leftGraph = new EmptyGraph();

        this.rightGraph = currentGraph;

        this.onlyOnLeft = Collections.emptySet();
        this.onlyOnRight = rightGraph.nodes();
    }

    private class EmptyGraph extends ObjectGraph {
        EmptyGraph() {
            super(Collections.emptySet());
        }
    }

    public Set getOnlyOnLeft() {
        return onlyOnLeft;
    }

    public Set getOnlyOnRight() {
        return onlyOnRight;
    }

    public Set getLeftNodeSet() {
        return leftGraph.nodes();
    }

    public Set getRightNodeSet() {
        return rightGraph.nodes();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy