1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Crash if a cycle is detected.

This commit is contained in:
Cedric Beust 2015-11-17 23:16:16 -08:00
parent e992d8b935
commit db69b4cc2a

View file

@ -1,5 +1,6 @@
package com.beust.kobalt.misc
import com.beust.kobalt.KobaltException
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.HashMultimap
import java.util.*
@ -29,6 +30,9 @@ class Topological<T> {
val freeNodes = all.filter {
dependMap.get(it).isEmpty()
}
if (freeNodes.isEmpty()) {
throw KobaltException("The dependency graph has a cycle: $all")
}
result.addAll(freeNodes)
all.removeAll(freeNodes)
val newMap = HashMultimap.create<T, T>()