From 36cf6dd505e1baf31b2eab92f7c238d0c2f92c0b Mon Sep 17 00:00:00 2001 From: Schankula Christopher <schankuc@mcmaster.ca> Date: Sun, 4 Mar 2018 14:49:46 -0500 Subject: [PATCH] cast to int instead of long for memory --- src/biotree/TaxonNode.java | 25 ++++++++++++++++++++----- src/biotree/WormsAPI.java | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/biotree/TaxonNode.java b/src/biotree/TaxonNode.java index e88a360..079e4d7 100644 --- a/src/biotree/TaxonNode.java +++ b/src/biotree/TaxonNode.java @@ -6,7 +6,7 @@ import java.util.ArrayList; public class TaxonNode { //JSON returns long - private final long taxonId; + private final int taxonId; private final TaxonType taxonType; private final String name; @@ -14,16 +14,16 @@ public class TaxonNode { private ArrayList<TaxonNode> children = new ArrayList<TaxonNode>(); private int count; - public TaxonNode(long taxonId, TaxonType taxonType, String name) { + public TaxonNode(int taxonId, TaxonType taxonType, String name) { this.taxonId = taxonId; this.taxonType = taxonType; this.name = name; this.parent = null; - this.children = null; + this.children = new ArrayList<TaxonNode>(); this.count = 0; } - //JSON returns long - public long getTaxonId() { + + public int getTaxonId() { return this.taxonId; } @@ -59,4 +59,19 @@ public class TaxonNode { public void incCount() { this.count ++; } + + public String toString() { + String s = ""; + s += String.format("%-20s%s\n", "Scientific Name:", name); + s += String.format("%-20s%s\n", "Taxon Type:", taxonType); + s += String.format("%-20s%d\n", "Taxon ID:", taxonId); + if (parent != null) s += String.format("%-20s%d\n", "Parent:", parent.getTaxonId()); + s += String.format("%-20s", "Children:"); + for (TaxonNode tx: children) { + s += String.format("%d ", tx.getTaxonId()); + } + s += "\n"; + s += String.format("%-20s%d\n", "Count:", count); + return s; + } } diff --git a/src/biotree/WormsAPI.java b/src/biotree/WormsAPI.java index 3a9b7fd..58bdc47 100644 --- a/src/biotree/WormsAPI.java +++ b/src/biotree/WormsAPI.java @@ -163,7 +163,7 @@ public class WormsAPI { JSONObject child = (JSONObject) current.get("child"); if (checktype == true) { - curNode = new TaxonNode((long) current.get("AphiaID"), TaxonType.valueOf((String) current.get("rank")), + curNode = new TaxonNode((int) (long) current.get("AphiaID"), TaxonType.valueOf((String) current.get("rank")), (String) current.get("scientificname")); nodes[n] = curNode; n++; -- GitLab