diff --git a/src/data/BioTree.java b/src/data/BioTree.java index 362adfcbb98a314e5bb9109d33e53162a5f96858..97ec7ed0dcde1b616d81fc38d9f2ede1a6b7bf93 100644 --- a/src/data/BioTree.java +++ b/src/data/BioTree.java @@ -170,7 +170,7 @@ public class BioTree implements Serializable { */ public static Integer processRecord(String scientificName) throws IOException, ParseException { //reverse lookup based on name, try adding the found taxonId. - Integer taxonId = getTaxonRecord(scientificName); + Integer taxonId = nameToTaxonId(scientificName); System.out.println(scientificName + ": " + taxonId); if (taxonId == null) return null; if (taxonId == -1) return null; @@ -237,6 +237,22 @@ public class BioTree implements Serializable { return idNodes.get(taxonId); } + /** + * Get the species at a given index (taxonId). This assumes that the + * node already exists or else it will return null. As such, it is best + * to use this function once all the data has been parsed and the BioTree + * has been built. + * + * @param i + * The speciesid (index) of the species. + * @return The Species object. + * @throws ParseException + * @throws IOException + */ + public static TaxonNode getTaxonRecord(String scientificName) throws IOException, ParseException { + return idNodes.get(nameToTaxonId(scientificName)); + } + /** * Get the TaxonNode containing information about the given scientific name. * This assumes that thenode already exists locally or else it will return null. @@ -249,7 +265,7 @@ public class BioTree implements Serializable { * @throws ParseException * @throws IOException */ - public static Integer getTaxonRecord(String scientificName) throws IOException, ParseException { + public static Integer nameToTaxonId(String scientificName) throws IOException, ParseException { Integer taxonId; //look up based on string literal, return if found TaxonNode tx = strNodes.get(scientificName); diff --git a/src/model/TrawlExpert.java b/src/model/TrawlExpert.java index 70b8667bbaaedfd5f1b6626a377bec2188051f73..a0a1ed490366e6760ad7b60002fa7af1297b5f50 100644 --- a/src/model/TrawlExpert.java +++ b/src/model/TrawlExpert.java @@ -1,11 +1,14 @@ package model; +import java.io.IOException; + import org.json.simple.parser.ParseException; import data.BioTree; import data.DataStore; import data.FileProcessor; import data.Record; +import data.TaxonNode; import search.BasicSearch; import search.BasicSearchResult; import sort.KDT; @@ -37,4 +40,18 @@ public class TrawlExpert { public BasicSearchResult rangeSearch(Integer taxonId, Integer yearLo, Integer yearHi) { return BasicSearch.range(taxonId, yearLo, yearHi); } + + public TaxonNode getTaxonRecord(Integer taxonId) { + return BioTree.getTaxonRecord(taxonId); + } + + public TaxonNode getTaxonRecord(String scientificName) { + try { + return BioTree.getTaxonRecord(scientificName); + } catch (IOException | ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } }