@@ -8,37 +8,34 @@ package org.fathomnet.worms.io.extended
88
99import org .fathomnet .worms .WormsNode
1010
11-
12-
1311object CombineTrees :
14-
15- /**
16- * Combine a sequence of trees into a single tree. It adjust the Aphia IDs of the
17- * combined tree so that they are unique. The inteneded usage is that the
18- * rootNode have a low aphiaId (0), then add the WormS tree first.
19- * Then the worms aphiaId's will not be changed. Ony the subsequent trees will
20- * have their aphiaId's incremented and then multiplied by -1 so that all fake
21- * aphiaId's are negative.
22- *
23- * @param rootNode The root node of the tree to add the other trees to
24- * @param trees The trees to add
25- * @param maxAphiaId The maximum aphiaId of the original WoRMS tree. Only aphiaId's
26- * greater than this value will be flipped to negative so that they
27- * are not confused with real aphiaId's.
28- * @return The combined tree
29- */
30- def combine (rootNode : WormsNode , trees : Seq [WormsNode ], maxAphiaId : Long ): WormsNode =
12+
13+ /**
14+ * Combine a sequence of trees into a single tree. It adjust the Aphia IDs of the combined tree so
15+ * that they are unique. The inteneded usage is that the rootNode have a low aphiaId (0), then add
16+ * the WormS tree first. Then the worms aphiaId's will not be changed. Ony the subsequent trees
17+ * will have their aphiaId's incremented and then multiplied by -1 so that all fake aphiaId's are
18+ * negative.
19+ *
20+ * @param rootNode
21+ * The root node of the tree to add the other trees to
22+ * @param trees
23+ * The trees to add
24+ * @param maxAphiaId
25+ * The maximum aphiaId of the original WoRMS tree. Only aphiaId's greater than this value will
26+ * be flipped to negative so that they are not confused with real aphiaId's.
27+ * @return
28+ * The combined tree
29+ */
30+ def combine (rootNode : WormsNode , trees : Seq [WormsNode ], maxAphiaId : Long ): WormsNode =
3131 var root = rootNode
32- trees.foreach(t => {
33- root = add(root, t, root.maxAphiaId)
34- })
32+ trees.foreach(t => root = add(root, t, root.maxAphiaId))
3533 flipFakeAphiaId(root, maxAphiaId)
3634
37- def add (rootNode : WormsNode , tree : WormsNode , maxAphiaId : Long ): WormsNode =
38- val node = incrementAphiaId(tree, maxAphiaId)
35+ def add (rootNode : WormsNode , tree : WormsNode , maxAphiaId : Long ): WormsNode =
36+ val node = incrementAphiaId(tree, maxAphiaId)
3937 val children = rootNode.children :+ node
4038 rootNode.copy(children = children)
41-
4239
4340 def incrementAphiaId (node : WormsNode , maxAphiaId : Long ): WormsNode =
4441 node.copy(
@@ -47,18 +44,18 @@ object CombineTrees:
4744 )
4845
4946 /**
50- * Flip the aphiaId of all nodes that have aphiaId > maxAphiaId so that
51- * fake aphiaId's are negative.
52- *
53- * @param node The node to flip
54- * @param maxAphiaId The maximum aphiaId of the original tree
55- * @return A new tree with fake aphiaId's flipped to negative
56- */
47+ * Flip the aphiaId of all nodes that have aphiaId > maxAphiaId so that fake aphiaId's are
48+ * negative.
49+ *
50+ * @param node
51+ * The node to flip
52+ * @param maxAphiaId
53+ * The maximum aphiaId of the original tree
54+ * @return
55+ * A new tree with fake aphiaId's flipped to negative
56+ */
5757 def flipFakeAphiaId (node : WormsNode , maxAphiaId : Long ): WormsNode =
5858 node.copy(
5959 aphiaId = if (node.aphiaId > maxAphiaId) - node.aphiaId else node.aphiaId,
6060 children = node.children.map(n => flipFakeAphiaId(n, maxAphiaId))
6161 )
62-
63-
64-
0 commit comments