Skip to content
Snippets Groups Projects
Commit f868953e authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

only call classification API if needed

parent 829eb44f
No related branches found
No related tags found
No related merge requests found
package biotree; package biotree;
import java.io.IOException; import java.io.IOException;
...@@ -13,6 +13,10 @@ public class BioTree { ...@@ -13,6 +13,10 @@ public class BioTree {
init(); init();
processRecord(125125); processRecord(125125);
processRecord(125125); processRecord(125125);
processRecord(125125);
processRecord(125125);
processRecord(125125);
processRecord(125125);
processRecord(125123); processRecord(125123);
processRecord(125122); processRecord(125122);
processRecord(125392); processRecord(125392);
...@@ -86,33 +90,34 @@ public class BioTree { ...@@ -86,33 +90,34 @@ public class BioTree {
*/ */
private static void processTaxonId(int taxonId) { private static void processTaxonId(int taxonId) {
TaxonNode[] newNodes = null; TaxonNode[] newNodes = null;
try { TaxonNode tx = nodes.get(taxonId);
newNodes = WormsAPI.idToClassification(taxonId);
} catch (IOException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TaxonNode tx = nodes.get(newNodes[newNodes.length - 1].getTaxonId());
if (tx != null) { if (tx != null) {
tx.incCount(); tx.incCount();
} else { } else {
try {
System.out.println("API Call");
newNodes = WormsAPI.idToClassification(taxonId);
} catch (IOException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
newNodes[newNodes.length - 1].incCount(); newNodes[newNodes.length - 1].incCount();
}
for (int i = newNodes.length - 1; i >= 0; i--) { for (int i = newNodes.length - 1; i >= 0; i--) {
tx = newNodes[i]; tx = newNodes[i];
TaxonNode result = nodes.get(tx.getTaxonId()); TaxonNode result = nodes.get(tx.getTaxonId());
TaxonNode parent = null; TaxonNode parent = null;
if (i > 0) { if (i > 0) {
parent = nodes.get(newNodes[i - 1].getTaxonId()); parent = nodes.get(newNodes[i - 1].getTaxonId());
if (parent == null) parent = newNodes[i - 1]; if (parent == null) parent = newNodes[i - 1];
}
if (result == null) { //if node is not found, add it
nodes.put(tx.getTaxonId(), tx);
tx.setParent(parent);
if (parent != null) parent.addChild(tx);
} else
break; //stop loop if this node already exists in the tree
} }
if (result == null) { //if node is not found, add it
nodes.put(tx.getTaxonId(), tx);
tx.setParent(parent);
if (parent != null) parent.addChild(tx);
} else
break; //stop loop if this node already exists in the tree
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment