convert method
void
convert(
- dynamic name,
- dynamic value
This method must be used on the root Node of the conversion. It
converts all the Node of the tree from the Node which name is equal to
name
(value
is assigned to this Node) to all the other Nodes of
the tree.
Implementation
void convert(dynamic name, dynamic value) {
assert(value is String || value is double);
List<Node> pathToConvertedNode = _getNodesPathAndSelectNode(name, value);
for (int i = pathToConvertedNode.length - 2; i >= 0; i--) {
_convertTwoNodes(
parent: pathToConvertedNode[i],
child: pathToConvertedNode[i + 1],
fromParentToChild: false);
}
//Now we use a BFS-like algorithm to convert everything from the root node
//to every other node.
Queue<Node> queue = Queue.from([this]);
while (queue.isNotEmpty) {
Node node = queue.removeFirst();
if (node.leafNodes.isNotEmpty) {
for (Node leafNode in node.leafNodes) {
if (!leafNode.isConverted) {
_convertTwoNodes(parent: node, child: leafNode);
}
queue.addLast(leafNode);
}
}
}
}