TreeAdapter

interface TreeAdapter<T>

Platform-agnostic adapter that allows the layout engine to traverse any external tree structure without coupling to a specific domain model.

Identity contract

The layout algorithm relies on consistent node identity. Implementations must satisfy:

  1. Deterministic children: children must return the same elements in the same order every time it is called for a given node. Returning freshly allocated wrapper objects that are not equal to previously returned nodes violates this contract.

  2. Consistent parent–child relationship: For every child c returned by children(node), parent(c) must return node (the same instance or an equal object).

  3. Unique membership: Each node must appear exactly once in the tree. Sharing a node across multiple parents or including it in multiple sibling lists is not supported.

Violating these constraints leads to undefined layout results or runtime exceptions.

Type Parameters

T

The node type of the external tree.

Functions

Link copied to clipboard
abstract fun children(node: T): List<T>

Returns the children of node in left-to-right order.

Link copied to clipboard
open fun isLeaf(node: T): Boolean

Returns true if node has no children.

Link copied to clipboard
abstract fun parent(node: T): T?

Returns the parent of node, or null if node is the root.

Link copied to clipboard
abstract fun root(): T

Returns the root node of the tree.