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

com.synopsys.integration.bdio.graph.DependencyGraphUtil Maven / Gradle / Ivy

Go to download

A library to allow for easy and clear creation of Black Duck I/O (bdio) documents.

The newest version!
/*
 * integration-bdio
 *
 * Copyright (c) 2024 Synopsys, Inc.
 *
 * Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide.
 */
package com.synopsys.integration.bdio.graph;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;

import com.synopsys.integration.bdio.model.dependency.Dependency;

public class DependencyGraphUtil {
    private DependencyGraphUtil() {
        // Hiding constructor
    }

    public static void copyDirectDependencies(DependencyGraph destinationGraph, DependencyGraph sourceGraph) {
        copyDependencies(destinationGraph, sourceGraph, sourceGraph::getDirectDependencies);
    }

    public static void copyDirectDependenciesToParent(DependencyGraph destinationGraph, Dependency parent, DependencyGraph sourceGraph) {
        copyDependenciesToParent(destinationGraph, parent, sourceGraph, sourceGraph::getDirectDependencies);
    }

    public static void copyRootDependencies(DependencyGraph destinationGraph, DependencyGraph sourceGraph) {
        copyDependencies(destinationGraph, sourceGraph, sourceGraph::getRootDependencies);
    }

    public static void copyRootDependenciesToParent(DependencyGraph destinationGraph, Dependency parent, DependencyGraph sourceGraph) {
        copyDependenciesToParent(destinationGraph, parent, sourceGraph, sourceGraph::getRootDependencies);
    }

    public static void copyDependencies(DependencyGraph destinationGraph, DependencyGraph sourceGraph, Supplier> dependencies) {
        Set encountered = new HashSet<>();
        for (Dependency dependency : dependencies.get()) {
            destinationGraph.addDirectDependency(dependency);
            copyDependencyTreeFromGraph(destinationGraph, dependency, sourceGraph, encountered);
        }
    }

    public static void copyDependenciesToParent(DependencyGraph destinationGraph, Dependency parent, DependencyGraph sourceGraph, Supplier> dependencies) {
        Set encountered = new HashSet<>();
        for (Dependency dependency : dependencies.get()) {
            destinationGraph.addChildWithParent(dependency, parent);
            copyDependencyTreeFromGraph(destinationGraph, dependency, sourceGraph, encountered);
        }
    }

    private static void copyDependencyTreeFromGraph(
        DependencyGraph destinationGraph,
        Dependency parentDependency,
        DependencyGraph sourceGraph,
        Set encountered
    ) {
        for (Dependency dependency : sourceGraph.getChildrenForParent(parentDependency)) {
            if (!encountered.contains(dependency)) {
                encountered.add(dependency);
                copyDependencyTreeFromGraph(destinationGraph, dependency, sourceGraph, encountered);
            }
            destinationGraph.addChildWithParent(dependency, parentDependency);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy