Fix crash in addLivelyNode
This commit is contained in:
parent
43afa73df7
commit
07121d8b41
@ -20,10 +20,14 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
private val livelyNodesList = ArrayList<EnergyCableBlockEntity.Node>()
|
||||
|
||||
fun addLivelyNode(node: EnergyCableBlockEntity.Node) {
|
||||
require(node in nodesSet) { "$node does not belong to $this" }
|
||||
|
||||
if (livelyNodes.add(node)) {
|
||||
livelyNodesList.add(node)
|
||||
when (contains(node)) {
|
||||
ContainsStatus.ABOUT_TO_BE_REMOVED, ContainsStatus.ABOUT_TO_BE_ADDED -> { } // do nothing
|
||||
ContainsStatus.DOES_NOT_BELONG -> throw IllegalArgumentException("$node does not belong to $this")
|
||||
ContainsStatus.CONTAINS -> {
|
||||
if (livelyNodes.add(node)) {
|
||||
livelyNodesList.add(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,26 @@ open class GraphNodeList<N : GraphNode<N, G>, G : GraphNodeList<N, G>> : ICondit
|
||||
val nodesSet: Set<N> = Collections.unmodifiableSet(nodesSetInternal)
|
||||
val size get() = nodesInternal.size
|
||||
|
||||
enum class ContainsStatus(val belongs: Boolean, val potentiallyBelongs: Boolean) {
|
||||
ABOUT_TO_BE_REMOVED(true, false),
|
||||
DOES_NOT_BELONG(false, false),
|
||||
ABOUT_TO_BE_ADDED(false, true),
|
||||
CONTAINS(true, true)
|
||||
}
|
||||
|
||||
fun contains(node: N): ContainsStatus {
|
||||
if (node in nodesSet) {
|
||||
if (node in queuedRemove)
|
||||
return ContainsStatus.ABOUT_TO_BE_REMOVED
|
||||
|
||||
return ContainsStatus.CONTAINS
|
||||
} else if (node in queuedAdd) {
|
||||
return ContainsStatus.ABOUT_TO_BE_ADDED
|
||||
} else {
|
||||
return ContainsStatus.DOES_NOT_BELONG
|
||||
}
|
||||
}
|
||||
|
||||
var isValid = true
|
||||
private set
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user