changesTo

Every TopologyChange that turns this tree into after, in document order: walking the tree from the root down, a node's own changes come before its children's, and within a group the children of after come in the order written, followed by the children it no longer has, in the order they were written before. Empty exactly when the two trees differ in nothing but the order of siblings.

Children are matched by name among their siblings: a child with the same name under the same group is the same child, whatever its kind or position. That is how the ledger identifies a group too, so the list says honestly what keeps its history: a moved or renamed child is a TopologyChange.Removed and a TopologyChange.Added, never a move. See TopologyChange.

Sibling order is not a change. Nothing in heddle reads it: Topology.lower sorts edges by id, and Topology.diff lists no step for a reordering. An admin page that wants to show a reorder can compare the two trees' child names itself.

To compare two TopologyDocuments, check each with Topology.from first: a change is only defined between valid trees, whose names identify their children.

Samples

val running = draft("pool") {
    group("acme", Weight.of(3)) {
        lane("interactive")
        lane("batch")
    }
    group("hobby") { lane("batch") }
}
val edited = draft("pool") {
    group("acme", Weight.of(4)) {
        lane("interactive", maxConcurrent = 2)
    }
    group("hobby") {
        lane("batch")
        lane("nightly")
    }
}
check(
    running.changesTo(edited) == listOf(
        TopologyChange.WeightChanged(listOf(0), listOf("pool", "acme"), Weight.of(3), Weight.of(4)),
        TopologyChange.CeilingChanged(listOf(0, 0), listOf("pool", "acme", "interactive"), null, 2L),
        // A removed child is addressed where it was, in the running tree.
        TopologyChange.Removed(listOf(0, 1), listOf("pool", "acme", "batch"), Topology.Lane("batch")),
        TopologyChange.Added(listOf(1, 1), listOf("pool", "hobby", "nightly"), Topology.Lane("nightly")),
    ),
)
// Nothing changed, nothing listed.
check(running.changesTo(running).isEmpty())