convert method
void
convert(
- T name,
- dynamic value
This method must be used on the root ConversionNode of the conversion. It
converts all the ConversionNode of the tree from the ConversionNode which name is equal to
name
(value
is assigned to this ConversionNode) to all the other ConversionNodes of
the tree.
Implementation
void convert(T name, dynamic value) {
assert(value is String || value is double);
List<ConversionNode> 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<ConversionNode> queue = Queue.from([this]);
while (queue.isNotEmpty) {
ConversionNode node = queue.removeFirst();
if (node.leafNodes.isNotEmpty) {
for (ConversionNode leafNode in node.leafNodes) {
if (!leafNode.isConverted) {
_convertTwoNodes(parent: node, child: leafNode);
}
queue.addLast(leafNode);
}
}
}
}