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

dev.sunnyday.test.impact.plugin.domain.graph.ImpactProjectGraph.kt Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package dev.sunnyday.test.impact.plugin.domain.graph

import dev.sunnyday.test.impact.plugin.domain.model.ImpactProject
import dev.sunnyday.test.impact.plugin.domain.model.ProjectPath
import java.io.Serializable

internal class ImpactProjectGraph(
    private val projects: Map,
    private val roots: Set,
    private val graph: Map>,
    private val filePathTrie: ProjectFilePathTrie,
) : Serializable {

    fun getProjectByProjectPath(name: String): ImpactProject {
        return projects.getValue(name)
    }

    fun getProjectByRelativePath(filePath: String): ImpactProject? {
        return filePathTrie.getProjectByRelativePath(filePath)
            ?.let(projects::get)
    }

    fun getDependentProjects(project: ImpactProject): List {
        return graph.getOrDefault(project.path, emptyList())
            .mapNotNull(projects::get)
    }

    fun clone(): ImpactProjectGraph {
        val clonedProjects = projects.mapValuesTo(hashMapOf()) { (_, project) ->
            project.copy()
        }

        val clonedRoots = roots.toHashSet()
        val clonedGraph = graph.toMap(hashMapOf())
        val clonedPathTrie = filePathTrie.clone()

        return ImpactProjectGraph(
            roots = clonedRoots,
            projects = clonedProjects,
            graph = clonedGraph,
            filePathTrie = clonedPathTrie,
        )
    }

    override fun toString(): String {
        return "ImpactProjectGraph($graph)"
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy