diff --git a/.gitignore b/.gitignore index 3e44dc3a5fc617ca79a27ecb90884f53a5182d61..54a63ca7b617a3b932d20c9439b1b178442dd532 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ *.blg *DS_Store* *.csv +*/bin *.ser .idea/ *.class +logs/ \ No newline at end of file diff --git a/Proposals/.DS_Store b/Proposals/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f15975d6621e185c2e729fc3672df259aa712fcf Binary files /dev/null and b/Proposals/.DS_Store differ diff --git a/Proposals/Chris/.DS_Store b/Proposals/Chris/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f5ba65c9459514dcc1c0f74d2dfae2553fa06873 Binary files /dev/null and b/Proposals/Chris/.DS_Store differ diff --git a/makefile b/makefile index 0c059edb65f32c66ba1f17c281a6a521ab5fa86b..d750ca571ccf2d3e331435c95388ce95f4cd69b6 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,8 @@ server: + mkdir -p tomcat/webapps/Trawl/WEB-INF/classes + chmod u+x tomcat/bin/startup.sh + chmod u+x tomcat/bin/shutdown.sh + chmod u+x tomcat/bin/catalina.sh cp -rf bin/* tomcat/webapps/Trawl/WEB-INF/classes start: server diff --git a/makefile2 b/makefile2 deleted file mode 100644 index 28215d0e481bfe2408af690471b82002441d7427..0000000000000000000000000000000000000000 --- a/makefile2 +++ /dev/null @@ -1,69 +0,0 @@ -TOMCAT_DIR = tomcat/webapps/Trawl -BIN_DIR = tomcat/webapps/Trawl/bin - -server: $(BIN_DIR)/TrawlExpert.class $(BIN_DIR)/../WEB-INF/classes/com/example/web/Director.class - javac -d $(TOMCAT_DIR)/WEB-INF/classes/ -classpath tomcat/lib/servlet-api.jar $(TOMCAT_DIR)/src/com/example/listener/StartUpContext.java - - -start: - tomcat/bin/startup.sh - -stop: - tomcat/bin/shutdown.sh - -$(BIN_DIR)/TrawlExpert.class: $(BIN_DIR)/data/BioTree.class $(BIN_DIR)/data/DataStore.class $(BIN_DIR)/data/Date.class $(BIN_DIR)/data/FileProcessor.class $(BIN_DIR)/data/Record.class $(BIN_DIR)/data/TaxonNode.class $(BIN_DIR)/data/TaxonType.class $(BIN_DIR)/data/WormsAPI.class $(BIN_DIR)/search/BasicSearch.class $(BIN_DIR)/search/BST.class $(BIN_DIR)/search/Histogram.class $(BIN_DIR)/sort/Bound.class $(BIN_DIR)/sort/GeneralCompare.class $(BIN_DIR)/sort/GeneralRange.class $(BIN_DIR)/sort/KDT.class $(BIN_DIR)/sort/MergeSort.class $(BIN_DIR)/sort/RangeHelper.class - javac -d $(TOMCAT_DIR)/WEB-INF/classes/ -classpath $(TOMCAT_DIR)/lib/servlet-api.jar:$(BIN_DIR):bin:json-simple-1.1.1.jar $(TOMCAT_DIR)/src/com/example/model/TrawlExpert.java - -$(BIN_DIR)/data/BioTree.class: src/data/BioTree.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/BioTree.java - -$(BIN_DIR)/data/DataStore.class: src/data/DataStore.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/DataStore.java - -$(BIN_DIR)/data/Date.class: src/Data/date.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/Date.java - -$(BIN_DIR)/data/FileProcessor.class: src/data/FileProcessor.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/FileProcessor.java - -$(BIN_DIR)/data/Record.class: src/data/Record.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/Record.java - -$(BIN_DIR)/data/TaxonNode.class: src/data/TaxonNode.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/TaxonNode.java - -$(BIN_DIR)/data/TaxonType.class: src/data/TaxonType.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/TaxonType.java - -$(BIN_DIR)/data/WormsAPI.class: src/data/WormsAPI.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/data/WormsAPI.java - -$(BIN_DIR)/search/BasicSearch.class: src/search/BasicSearch.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/search/BasicSearch.java - -$(BIN_DIR)/search/BST.class: src/search/BST.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/search/BST.java - -$(BIN_DIR)/search/Histogram.class: src/search/Histogram.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/search/Histogram.java - -$(BIN_DIR)/sort/Bound.class: src/sort/Bound.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/Bound.java - -$(BIN_DIR)/sort/GeneralCompare.class: src/sort/GeneralCompare.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/GeneralCompare.java - -$(BIN_DIR)/sort/GeneralRange.class: src/sort/GeneralRange.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/GeneralRange.java - -$(BIN_DIR)/sort/KDT.class: src/sort/KDT.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/KDT.java - -$(BIN_DIR)/sort/MergeSort.class: src/sort/MergeSort.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/MergeSort.java - -$(BIN_DIR)/sort/RangeHelper.class: src/sort/RangeHelper.java - javac -d $(BIN_DIR) -classpath bin::json-simple-1.1.1.jar src/sort/RangeHelper.java - -$(BIN_DIR)/../WEB-INF/classes/com/example/web/Director.class: $(BIN_DIR)/com/example/web/Director.java - javac -d $(TOMCAT_DIR)/WEB-INF/classes -classpath src/tomcat/lib/servlet-api.jar:$(BIN_DIR) $(BIN_DIR)/com/example/web/Director.java \ No newline at end of file diff --git a/makefile~ b/makefile~ deleted file mode 100644 index 5bc815d4da2f6aca25833081d6e0572c112575eb..0000000000000000000000000000000000000000 --- a/makefile~ +++ /dev/null @@ -1,2 +0,0 @@ -server: /TrawlExpert.java - javac -classpath diff --git a/src/Main.java b/src/Main.java index db3c0ff20b675352bdde51d4eabd7f5230222477..ec16db1494800f43bae2ba9076e14ad40522fa79 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,13 +1,28 @@ import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.json.simple.parser.ParseException; import data.BioTree; import data.DataStore; +import data.Date; import data.FileProcessor; import data.Record; +import data.WormsAPI; +import search.BST; import search.BasicSearch; +import search.BasicSearchResult; +import search.Histogram; +import sort.Bound; +import sort.GeneralRange; import sort.KDT; +import sort.RangeHelper; +import utils.Stopwatch; public class Main { public static void main(String[] args) { @@ -27,7 +42,7 @@ public class Main { BioTree.write("data/biotree/"); DataStore.records.writeToFile("data/kdt.ser"); }; - BasicSearch.init(); + init(); } private static void printLogo() { @@ -53,4 +68,135 @@ public class Main { " `-' `````````"); System.out.println("Loading......."); } + + public static void init() { + System.out.println("Welcome!"); + while(true) { + System.out.println("Main Menu"); + System.out.println("Available commands:"); + System.out.println("\ttree [taxonId / scientific name]"); + System.out.println("\trecords (taxonId / scientific name) [-t start end]"); + System.out.print("> "); + Pattern pat = Pattern.compile("([a-zA-Z]+)[ ]?([0-9a-zA-Z ]+[0-9a-zA-Z])?[ ]?[-]?([a-zA-Z])?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?"); + Scanner s = new Scanner(System.in); + String line = s.nextLine(); + Matcher matcher = pat.matcher(line); + if (!matcher.find()) continue; + + //tree + //tree taxonId + //tree scientific name + //records taxonId + //records scientific name + String command = matcher.group(1); + + if (command.equals("records")) + rangeSearch(matcher); + else if (command.equals("tree")) + printTree(matcher); + } + } + + private static void rangeSearch(Matcher matcher) { + Integer start = null; + Integer end = null; + if (matcher.group(3) != null) + if (matcher.group(3).equals("t")) { + if (matcher.group(4) != null) + start = Integer.parseInt(matcher.group(4)); + if (matcher.group(5) != null) + end = Integer.parseInt(matcher.group(5)); + } + + Integer taxonId = null; + try { + taxonId = Integer.parseInt(matcher.group(2)); + } catch (NumberFormatException e) { + if (taxonId == null) { + try { + taxonId = WormsAPI.nameToRecordID(matcher.group(2)); + } catch (IOException e1) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + BasicSearchResult result = BasicSearch.range(taxonId, start, end); + + System.out.println("Found " + result.n() + " records in " + result.time() + " seconds."); + + while(true) { + System.out.println("Available commands: list, histogram, sum, exit"); + System.out.print("> "); + + Scanner s = new Scanner(System.in); + String command = s.nextLine(); + + if (command.equals("list")) + printRecords(result.results()); + else if (command.equals("histogram")) { + printHistogram(result.histogram()); + } else if (command.equals("exit")) + return; + else if (command.equals("sum")) { + System.out.println(result.sum()); + } + } + } + + private static void printRecords(Iterable<Record> results) { + String format = "|%1$-45s|%2$-15s|%3$-15s|%4$-15s|%5$-15s|%6$-15s\n"; + System.out.format(format, "Scientific Name", "IndividualCount", "Latitude", "Longitude","Year","Month","Day"); + for (Record r: results) { + System.out.println(r); + } + } + + private static void printTree(Matcher matcher) { + Integer taxonId; + String name; + if (matcher.group(2) == null) + BioTree.printTree(); + else { + name = matcher.group(2); + try { + taxonId = Integer.parseInt(name); + BioTree.printTree(taxonId); + } catch (Exception e) { + BioTree.printTree(name); + } + } + System.out.println(); + } + + /** + * Prints a histogram based on a BST of records + * + * @param record -An BST of records + */ + public static void printHistogram(BST<Integer,Integer> record) { + int max = 0; + int scale = 100; + Iterable<Integer> results = record.keys(); + for (Integer year: results) { + if (max < record.get(year)) max =record.get(year); + + } + System.out.println(" |" + (new String(new char[scale]).replace('\0', '-')) + "|"); + String format = "%1$-5d|%2$-" + (scale + 1) + "s"; + for (Integer year: results) { + String s = "="; + int loopc = (int) ((float)(record.get(year)/ (float) max) * scale); + for (int j=0; j< loopc; j++) { + s+="="; + } + System.out.format(format, year, s); + System.out.println("| " + record.get(year)); + } + System.out.format("Scale: one = is %d individuals.\n", max / scale); + } } diff --git a/src/data/BioTree.java b/src/data/BioTree.java index 642816afae625001d883bdfe316e14f562e6fb2b..97ec7ed0dcde1b616d81fc38d9f2ede1a6b7bf93 100644 --- a/src/data/BioTree.java +++ b/src/data/BioTree.java @@ -2,6 +2,7 @@ package data; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -169,33 +170,10 @@ public class BioTree implements Serializable { */ public static Integer processRecord(String scientificName) throws IOException, ParseException { //reverse lookup based on name, try adding the found taxonId. - System.out.println("Processing " + scientificName); - TaxonNode res = strNodes.get(scientificName); - if (res == null) { - System.out.println("Not already found."); - Integer incorrectNameId = incorrectNames.get(scientificName); - if (incorrectNameId != null) if (incorrectNameId == -1) return null; - res = idNodes.get(incorrectNameId); - } - Integer taxonId = null; - //if the taxonId was not found in the local database - if (res == null) { - try { - taxonId = WormsAPI.nameToID(scientificName); - } catch (Exception e) { - taxonId = WormsAPI.nameToRecordID(scientificName); - if (taxonId != null) - incorrectNames.put(scientificName, taxonId); - else { - incorrectNames.put(scientificName, -1); - } - } - } - else - taxonId = res.getTaxonId(); + Integer taxonId = nameToTaxonId(scientificName); + System.out.println(scientificName + ": " + taxonId); if (taxonId == null) return null; - if (taxonId == -999) - taxonId = WormsAPI.nameToRecordID(scientificName); + if (taxonId == -1) return null; if (processTaxonId(taxonId)) return null; return taxonId; } @@ -259,6 +237,58 @@ 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. + * As such, it is best to use this function once all the data has been parsed + * and the BioTree has been built. + * + * @param scientificName + * The scientific name of the taxon. + * @return The Species object. + * @throws ParseException + * @throws IOException + */ + 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); + if (tx != null) return tx.getTaxonId(); + else System.out.println(scientificName + " not in local db"); + //look up in local incorrect names database, return if it exists + taxonId = incorrectNames.get(scientificName); + if (taxonId != null) { + tx = idNodes.get(taxonId); + if (tx != null) return tx.getTaxonId(); + } else { //otherwise use Worms to look it up + System.out.println(scientificName + " not in incor db"); + taxonId = WormsAPI.nameToRecordID(scientificName); + if (taxonId == null) //if nothing is found, mark this species as not existing. + incorrectNames.put(scientificName, -1); + else { + System.out.println(scientificName + " found in Worms: " + taxonId); + incorrectNames.put(scientificName, taxonId); + } + } + return taxonId; + } + public static Iterable<Integer> getNonEmptyChildren(int taxonId){ ArrayList<Integer> result = new ArrayList<Integer>(); diff --git a/src/data/FileProcessor.java b/src/data/FileProcessor.java index d224fc5101d4ec570fd24d0416e669b410a8d3d0..af5b7f26b4c6e5100fec39d9524edd040a36fa15 100644 --- a/src/data/FileProcessor.java +++ b/src/data/FileProcessor.java @@ -153,7 +153,9 @@ public class FileProcessor { int errorCount=0; // TESTING ONLY if (!matchEventId.group(10).equals("NA")) { try{ - al.add(createRecord(Integer.parseInt(matchEventId.group(3)), matchEventId.group(1), BioTree.processRecord(matchEventId.group(10)), Integer.parseInt(matchEventId.group(2)), Float.parseFloat(matchEventId.group(7)), Float.parseFloat(matchEventId.group(8)), Integer.parseInt(matchEventId.group(4)), Integer.parseInt(matchEventId.group(5)), Integer.parseInt(matchEventId.group(6)))); + Integer taxonId = BioTree.processRecord(matchEventId.group(10)); + if (taxonId != null) + al.add(createRecord(Integer.parseInt(matchEventId.group(3)), matchEventId.group(1), taxonId, Integer.parseInt(matchEventId.group(2)), Float.parseFloat(matchEventId.group(7)), Float.parseFloat(matchEventId.group(8)), Integer.parseInt(matchEventId.group(4)), Integer.parseInt(matchEventId.group(5)), Integer.parseInt(matchEventId.group(6)))); } catch(IOException e) { System.out.println("Input Error:" + e); } catch(NullPointerException e) { diff --git a/src/data/WormsAPI.java b/src/data/WormsAPI.java index f27f141521b822094b9e2d68edb499e82b0a695f..fff3b5c5894ffebfc095850f5cfd34cc86b9cca6 100644 --- a/src/data/WormsAPI.java +++ b/src/data/WormsAPI.java @@ -31,7 +31,7 @@ public class WormsAPI { * System.out.println(taxnodes[i].getTaxonType()); * System.out.println(taxnodes[i].getName()); } */ - + System.out.println(nameToRecordID("Hello")); } /** @@ -107,8 +107,6 @@ public class WormsAPI { int id = (int) (long) ((JSONObject)json.get(0)).get("AphiaID"); return id; - - } /** diff --git a/src/model/TrawlExpert.java b/src/model/TrawlExpert.java index f6fa8c307b582346668ffd4e7f54ac5909b28020..a0a1ed490366e6760ad7b60002fa7af1297b5f50 100644 --- a/src/model/TrawlExpert.java +++ b/src/model/TrawlExpert.java @@ -1,12 +1,16 @@ 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; public class TrawlExpert { @@ -32,4 +36,22 @@ public class TrawlExpert { public Iterable<Integer> listAllSpecies(){ return BioTree.getNonEmptyChildren(2); } + + 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; + } } diff --git a/src/model/TrawlExpert2.java b/src/model/TrawlExpert2.java deleted file mode 100755 index ab61e04b0ac93590eb01670df06d255726439717..0000000000000000000000000000000000000000 --- a/src/model/TrawlExpert2.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.model; -import java.util.*; -public class TrawlExpert { - -public List getBrands(String phylum) { - List brands = new ArrayList(); - if (phylum.equals("Arthropoda")) { - brands.add("Some arthropoda data"); - brands.add("Some more Arthropoda data"); - } - else { - brands.add("This aint arthropoda"); - brands.add("Under construction"); - } - return brands; - } -} - -// For Testing on Java's Console -// public static void main(String[]args){ -// String color = "amber"; -// System.out.println(brand.get(0)); -// } \ No newline at end of file diff --git a/src/sandbox/.classpath b/src/sandbox/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ac37fb2e4bca5ec7510383d7e55ea7b6b759e05a --- /dev/null +++ b/src/sandbox/.classpath @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/src/sandbox/.project b/src/sandbox/.project new file mode 100644 index 0000000000000000000000000000000000000000..ff1db54e8e75fcedb2a0b27c0661b0b6c87fc009 --- /dev/null +++ b/src/sandbox/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>sandbox</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/src/sandbox/GeneralCompare.java b/src/sandbox/GeneralCompare.java new file mode 100644 index 0000000000000000000000000000000000000000..9e7584c7399a163c5ff6ef9ec6c98829ce1735dc --- /dev/null +++ b/src/sandbox/GeneralCompare.java @@ -0,0 +1,6 @@ +package sandbox; + +public interface GeneralCompare { + public int eval(Comparable a1, Comparable a2); + +} diff --git a/src/sandbox/Point.java b/src/sandbox/Point.java index ea0d0fde7d1e43fe54b5b71bdc0010f3901daffe..ffd4e0c7a98961077f109edd67f0b42fa20877a8 100644 --- a/src/sandbox/Point.java +++ b/src/sandbox/Point.java @@ -7,19 +7,19 @@ public class Point implements Comparable<Point>, Serializable { * */ private static final long serialVersionUID = 5361956730616676054L; - private final int x; - private final int y; + private final double x; + private final double y; - public Point(int x, int y) { + public Point(double x, double y) { this.x = x; this.y = y; } - public int getX() { + public double getX() { return this.x; } - public int getY() { + public double getY() { return this.y; } diff --git a/src/sandbox/TestLambdas.java b/src/sandbox/TestLambdas.java index 69ac2bc4ac76ff8d89bbf350715f975842e96eef..91dc35c0120ef2193dd16f11cc8e5e4a4c8f975e 100644 --- a/src/sandbox/TestLambdas.java +++ b/src/sandbox/TestLambdas.java @@ -7,9 +7,9 @@ package sandbox; public class TestLambdas { public static void main(String[] args) { //declare the instances of BinaryIntExpression - BinaryIntExpression b0; - BinaryIntExpression b1; - BinaryIntExpression b2; + GeneralCompare<Integer> b0; + GeneralCompare<Integer> b1; + GeneralCompare<Integer> b2; BinaryIntExpression b3; BinaryIntExpression b4; BinaryIntExpression b5; @@ -34,13 +34,13 @@ public class TestLambdas { }; //call the main function using the instances as a parameter. - result = binaryOperation(1,2,b0); + result = binaryIntegerOperation(1,2,b0); System.out.println(result); - result = binaryOperation(1,2,b1); + result = binaryIntegerOperation(1,2,b1); System.out.println(result); - result = binaryOperation(1,2,b2); + result = binaryIntegerOperation(1,2,b2); System.out.println(result); result = binaryOperation(1,2,b3); @@ -61,4 +61,9 @@ public class TestLambdas { return exp.eval(a1, a2); } + public static int binaryIntegerOperation(int a1, int a2, GeneralCompare<Integer> exp) { + //call the eval() function in the given BinaryIntExpression. + return exp.eval(a1, a2); + } + } diff --git a/src/search/BasicSearch.java b/src/search/BasicSearch.java index 97cdb49d90124c76e19b0a2b4023a232cc1988eb..ec7894aa92b82a9f8d845bf7091c968987bfc82c 100644 --- a/src/search/BasicSearch.java +++ b/src/search/BasicSearch.java @@ -1,84 +1,37 @@ package search; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.json.simple.parser.ParseException; - import utils.Stopwatch; import data.BioTree; import data.DataStore; import data.Date; import data.Record; -import data.WormsAPI; import sort.Bound; import sort.GeneralRange; import sort.RangeHelper; +/** + * Provides functionality for range searching the Record database. + * @author Christopher W. Schankula + * + */ public class BasicSearch { - public static void init() { - System.out.println("Welcome!"); - while(true) { - System.out.println("Main Menu"); - System.out.println("Available commands:"); - System.out.println("\ttree [taxonId / scientific name]"); - System.out.println("\trecords (taxonId / scientific name) [-t start end]"); - System.out.print("> "); - Pattern pat = Pattern.compile("([a-zA-Z]+)[ ]?([0-9a-zA-Z ]+[0-9a-zA-Z])?[ ]?[-]?([a-zA-Z])?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?([A-Za-z0-9]+)?[ ]?"); - Scanner s = new Scanner(System.in); - String line = s.nextLine(); - Matcher matcher = pat.matcher(line); - if (!matcher.find()) continue; - - //tree - //tree taxonId - //tree scientific name - //records taxonId - //records scientific name - String command = matcher.group(1); - - if (command.equals("records")) - rangeSearch(matcher); - else if (command.equals("tree")) - printTree(matcher); - } - } - - private static void rangeSearch(Matcher matcher) { - Integer start = null; - Integer end = null; + /** + * Returns all records matching any of the children of the given TaxonID and in the + * date range given + * @param taxonId The TaxonID for which to search + * @param yearLo The lower bound on the year range + * @param yearHi The upper bound on the year range + * @return + */ + public static BasicSearchResult range(Integer taxonId, Integer yearLo, Integer yearHi){ GeneralRange<Record> a0 = RangeHelper.date(Bound.ANY); - if (matcher.group(3) != null) - if (matcher.group(3).equals("t")) { - if (matcher.group(4) != null) - start = Integer.parseInt(matcher.group(4)); - if (matcher.group(5) != null) - end = Integer.parseInt(matcher.group(5)); - Date lower = new Date(start,01,01); - Date upper = new Date(end+1,01,01); - - a0 = RangeHelper.date(Bound.LOWHIGH, lower, upper); - } - Integer taxonId = null; - try { - taxonId = Integer.parseInt(matcher.group(2)); - } catch (NumberFormatException e) { - if (taxonId == null) { - try { - taxonId = WormsAPI.nameToRecordID(matcher.group(2)); - } catch (IOException e1) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ParseException e1) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + if ((yearLo != null) && (yearHi != null)) { + Date lower = new Date(yearLo,01,01); + Date upper = new Date(yearHi+1,01,01); + a0 = RangeHelper.date(Bound.LOWHIGH, lower, upper); } GeneralRange<Record> a2 = r -> 0; @@ -86,9 +39,9 @@ public class BasicSearch { GeneralRange<Record> a1; - Stopwatch sw = new Stopwatch(); Iterable<Integer> searches = BioTree.getNonEmptyChildren(taxonId); + Stopwatch sw = new Stopwatch(); ArrayList<Record> results = new ArrayList<Record>(); for (Integer txId: searches) { a1 = RangeHelper.taxonID(Bound.EQUALS, txId); @@ -98,53 +51,8 @@ public class BasicSearch { results.addAll((Collection<? extends Record>) DataStore.records.rangeSearch(axes)); } + double time = sw.elapsedTime(); - double elapsed = sw.elapsedTime(); - - System.out.println("Found " + ((ArrayList<Record>) results).size() + " records in " + elapsed + " seconds."); - - while(true) { - System.out.println("Available commands: list, histogram, sum, exit"); - System.out.print("> "); - - Scanner s = new Scanner(System.in); - String command = s.nextLine(); - - if (command.equals("list")) - printRecords(results); - else if (command.equals("histogram")) { - Histogram.printHistogram(Histogram.histogram(results)); - } else if (command.equals("exit")) - return; - else if (command.equals("sum")) { - int sum = Histogram.sum(results); - System.out.println(sum); - } - } - } - - private static void printRecords(Iterable<Record> results) { - String format = "|%1$-45s|%2$-15s|%3$-15s|%4$-15s|%5$-15s|%6$-15s\n"; - System.out.format(format, "Scientific Name", "IndividualCount", "Latitude", "Longitude","Year","Month","Day"); - for (Record r: results) { - System.out.println(r); - } - } - - private static void printTree(Matcher matcher) { - Integer taxonId; - String name; - if (matcher.group(2) == null) - BioTree.printTree(); - else { - name = matcher.group(2); - try { - taxonId = Integer.parseInt(name); - BioTree.printTree(taxonId); - } catch (Exception e) { - BioTree.printTree(name); - } - } - System.out.println(); + return new BasicSearchResult(results, time); } } diff --git a/src/search/BasicSearchResult.java b/src/search/BasicSearchResult.java new file mode 100644 index 0000000000000000000000000000000000000000..c32548625c5495301b84a63c670785c47a91ca17 --- /dev/null +++ b/src/search/BasicSearchResult.java @@ -0,0 +1,44 @@ +package search; + +import java.util.ArrayList; + +import data.Record; + +public class BasicSearchResult { + private ArrayList<Record> results; + private final double time; + private BST<Integer, Integer> histogram; + private Integer sum; + + public BasicSearchResult(ArrayList<Record> results, double time) { + this.results = results; + this.time = time; + } + + public Iterable<Record> results() { + return (Iterable<Record>) results; + } + + public int n() { + return results.size(); + } + + public double time() { + return time; + } + + public BST<Integer, Integer> histogram() { + if (this.histogram == null) + this.histogram = Histogram.histogram(results()); + return histogram; + } + + public int sum() { + if (sum == null) { + sum = 0; + for (Record r: results()) + sum += r.getCount(); + } + return this.sum; + } +} diff --git a/src/search/CC.java b/src/search/CC.java new file mode 100644 index 0000000000000000000000000000000000000000..7726bac67040148ddff0916c89ef584aa57ac3fc --- /dev/null +++ b/src/search/CC.java @@ -0,0 +1,50 @@ +package search; + +public class CC { + + private boolean[] marked; + private int[] id; + private int count; + + public static void main(String[] args) { + Graph g = new Graph(5); + g.addEdge(4, 3); + g.addEdge(2, 3); + g.addEdge(1, 2); + g.addEdge(0, 2); + CC component = new CC(g); + System.out.println(component.connected(0, 2)); + } + + public CC(Graph G){ + marked = new boolean[G.V()]; + id = new int[G.V()]; + for(int s = 0; s < G.V(); s++){ + if(!marked[s]){ + dfs(G,s); + count++; + } + } + } + + private void dfs(Graph G, int v){ + marked[v] = true; + id[v] = count; + for(int w : G.adj(v)){ + if(!marked[w]) + dfs(G, w); + } + } + + public boolean connected(int v, int w){ + return id[v] == id[w]; + } + + public int id(int v){ + return id[v]; + } + + public int count(){ + return count; + } +} diff --git a/src/search/DepthFirstSearch.java b/src/search/DepthFirstSearch.java new file mode 100644 index 0000000000000000000000000000000000000000..000a3e93fbee5c6246a3cbeb2683973a2f6da02f --- /dev/null +++ b/src/search/DepthFirstSearch.java @@ -0,0 +1,39 @@ +package search; + +public class DepthFirstSearch { + + private boolean[] marked; + private int count; + + public static void main(String[] args) { + + Graph g = new Graph(5); + g.addEdge(4, 3); + g.addEdge(2, 3); + g.addEdge(1, 2); + g.addEdge(0, 2); + DepthFirstSearch s = new DepthFirstSearch(g, g.V()); + } + + public DepthFirstSearch(Graph G, int s){ + marked = new boolean[G.V()]; + dfs(G, s); + + } + + public void dfs(Graph G, int v){ + marked[v] = true; + count++; + for(int w : G.adj(v)) + if(!marked[w]) + dfs(G, w); + } + + public boolean marked(int w){ + return marked[w]; + } + + public int count(){ + return count; + } +} diff --git a/src/search/Field.java b/src/search/Field.java new file mode 100644 index 0000000000000000000000000000000000000000..46c5d2179860ef9ba54f7c1d77bb965d9fef3a60 --- /dev/null +++ b/src/search/Field.java @@ -0,0 +1,7 @@ +package search; + +// The interface for a function that returns one field (piece of data) from a record +public interface Field<Key, Value> { + public Comparable<Key> field(Value a1); +} + diff --git a/src/search/Fish.java b/src/search/Fish.java new file mode 100644 index 0000000000000000000000000000000000000000..3cc9e20d05861a7b7d65b829a30d00becee1de9b --- /dev/null +++ b/src/search/Fish.java @@ -0,0 +1,49 @@ +package search; + +import java.util.Iterator; + +public class Fish<Integer> implements Iterable<Integer> { + + private Node first; + + private class Node{ + Integer item; + Node next; + } + + public void add(Integer item){ + Node oldfirst = first; + first = new Node(); + first.item = item; + first.next = oldfirst; + } + + @Override + public Iterator<Integer> iterator() { + return new ListIterator(); + } + + private class ListIterator implements Iterator<Integer>{ + + private Node current = first; + + public boolean hasNext(){ + return current != null; + } + public void remove(){ + current.next = current.next.next; + } + public Integer next(){ + + Integer item = current.item; + current = current.next; + return item; + + } + } + + + + + +} diff --git a/src/search/GeneralCompare.java b/src/search/GeneralCompare.java new file mode 100644 index 0000000000000000000000000000000000000000..215fddf629ae39a3fec841758c91034af5e200f2 --- /dev/null +++ b/src/search/GeneralCompare.java @@ -0,0 +1,5 @@ +package search; + +public interface GeneralCompare<T> { + public int compare(Comparable<T> a1, Comparable<T> a2); +} diff --git a/src/search/Graph.java b/src/search/Graph.java new file mode 100644 index 0000000000000000000000000000000000000000..093a437d93bbdb0074f1ea138e5359fb9c72e972 --- /dev/null +++ b/src/search/Graph.java @@ -0,0 +1,45 @@ +package search; + +public class Graph { + + private final int V; // Number of nodes + private int E; // Number of edges + private Fish<Integer>[] adj; // Adjacency list for a node + + public static void main(String[] args) { + + Graph g = new Graph(5); + g.addEdge(4, 3); + g.addEdge(2, 3); + g.addEdge(1, 2); + g.addEdge(0, 2); + for(int i = 0; i < 5; i++) + System.out.println(g.adj(i)); + } + + public Graph(int V){ + this.V = V; + this.E = 0; + adj = (Fish<Integer>[]) new Fish[V]; + for(int v = 0; v < V; v++) + adj[v] = new Fish<Integer>(); + } + + public int V(){ + return V; + } + + public int E(){ + return E; + } + + public void addEdge(int v, int w){ + adj[v].add(w); + adj[w].add(v); + E++; + } + + public Iterable<Integer> adj(int V){ + return adj[V]; + } +} diff --git a/src/search/Histogram.java b/src/search/Histogram.java index f8d145eebf90b1eb6966017992783715843a6ba7..48354f0d5242863a681763667fd338489196a904 100644 --- a/src/search/Histogram.java +++ b/src/search/Histogram.java @@ -72,6 +72,7 @@ public class Histogram { for (Record r: records) sum += r.getCount(); return sum; + } - +} \ No newline at end of file diff --git a/src/search/In.java b/src/search/In.java new file mode 100644 index 0000000000000000000000000000000000000000..f9fe5bbd6f86ff16949b2ec06eb178d6e54e7f2f --- /dev/null +++ b/src/search/In.java @@ -0,0 +1,731 @@ +package search; + +import java.io.*; +import java.util.*; +import java.util.regex.Pattern; +import java.net.*; + +public final class In { + + ///// begin: section (1 of 2) of code duplicated from In to StdIn. + + // assume Unicode UTF-8 encoding + private static final String CHARSET_NAME = "UTF-8"; + + // assume language = English, country = US for consistency with System.out. + private static final Locale LOCALE = Locale.US; + + // the default token separator; we maintain the invariant that this value + // is held by the scanner's delimiter between calls + private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\p{javaWhitespace}+"); + + // makes whitespace characters significant + private static final Pattern EMPTY_PATTERN = Pattern.compile(""); + + // used to read the entire input. source: + // http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html + private static final Pattern EVERYTHING_PATTERN = Pattern.compile("\\A"); + + //// end: section (1 of 2) of code duplicated from In to StdIn. + + private Scanner scanner; + + /** + * Initializes an input stream from standard input. + */ + public In() { + scanner = new Scanner(new BufferedInputStream(System.in), CHARSET_NAME); + scanner.useLocale(LOCALE); + } + + /** + * Initializes an input stream from a socket. + * + * @param socket the socket + * @throws IllegalArgumentException if cannot open {@code socket} + * @throws IllegalArgumentException if {@code socket} is {@code null} + */ + public In(Socket socket) { + if (socket == null) throw new IllegalArgumentException("socket argument is null"); + try { + InputStream is = socket.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), CHARSET_NAME); + scanner.useLocale(LOCALE); + } + catch (IOException ioe) { + throw new IllegalArgumentException("Could not open " + socket, ioe); + } + } + + /** + * Initializes an input stream from a URL. + * + * @param url the URL + * @throws IllegalArgumentException if cannot open {@code url} + * @throws IllegalArgumentException if {@code url} is {@code null} + */ + public In(URL url) { + if (url == null) throw new IllegalArgumentException("url argument is null"); + try { + URLConnection site = url.openConnection(); + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), CHARSET_NAME); + scanner.useLocale(LOCALE); + } + catch (IOException ioe) { + throw new IllegalArgumentException("Could not open " + url, ioe); + } + } + + /** + * Initializes an input stream from a file. + * + * @param file the file + * @throws IllegalArgumentException if cannot open {@code file} + * @throws IllegalArgumentException if {@code file} is {@code null} + */ + public In(File file) { + if (file == null) throw new IllegalArgumentException("file argument is null"); + try { + // for consistency with StdIn, wrap with BufferedInputStream instead of use + // file as argument to Scanner + FileInputStream fis = new FileInputStream(file); + scanner = new Scanner(new BufferedInputStream(fis), CHARSET_NAME); + scanner.useLocale(LOCALE); + } + catch (IOException ioe) { + throw new IllegalArgumentException("Could not open " + file, ioe); + } + } + + + /** + * Initializes an input stream from a filename or web page name. + * + * @param name the filename or web page name + * @throws IllegalArgumentException if cannot open {@code name} as + * a file or URL + * @throws IllegalArgumentException if {@code name} is {@code null} + */ + public In(String name) { + if (name == null) throw new IllegalArgumentException("argument is null"); + try { + // first try to read file from local file system + File file = new File(name); + if (file.exists()) { + // for consistency with StdIn, wrap with BufferedInputStream instead of use + // file as argument to Scanner + FileInputStream fis = new FileInputStream(file); + scanner = new Scanner(new BufferedInputStream(fis), CHARSET_NAME); + scanner.useLocale(LOCALE); + return; + } + + // next try for files included in jar + URL url = getClass().getResource(name); + + // try this as well + if (url == null) { + url = getClass().getClassLoader().getResource(name); + } + + // or URL from web + if (url == null) { + url = new URL(name); + } + + URLConnection site = url.openConnection(); + + // in order to set User-Agent, replace above line with these two + // HttpURLConnection site = (HttpURLConnection) url.openConnection(); + // site.addRequestProperty("User-Agent", "Mozilla/4.76"); + + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), CHARSET_NAME); + scanner.useLocale(LOCALE); + } + catch (IOException ioe) { + throw new IllegalArgumentException("Could not open " + name, ioe); + } + } + + /** + * Initializes an input stream from a given {@link Scanner} source; use with + * {@code new Scanner(String)} to read from a string. + * <p> + * Note that this does not create a defensive copy, so the + * scanner will be mutated as you read on. + * + * @param scanner the scanner + * @throws IllegalArgumentException if {@code scanner} is {@code null} + */ + public In(Scanner scanner) { + if (scanner == null) throw new IllegalArgumentException("scanner argument is null"); + this.scanner = scanner; + } + + /** + * Returns true if this input stream exists. + * + * @return {@code true} if this input stream exists; {@code false} otherwise + */ + public boolean exists() { + return scanner != null; + } + + //// begin: section (2 of 2) of code duplicated from In to StdIn, + //// with all methods changed from "public" to "public static". + + /** + * Returns true if input stream is empty (except possibly whitespace). + * Use this to know whether the next call to {@link #readString()}, + * {@link #readDouble()}, etc will succeed. + * + * @return {@code true} if this input stream is empty (except possibly whitespace); + * {@code false} otherwise + */ + public boolean isEmpty() { + return !scanner.hasNext(); + } + + /** + * Returns true if this input stream has a next line. + * Use this method to know whether the + * next call to {@link #readLine()} will succeed. + * This method is functionally equivalent to {@link #hasNextChar()}. + * + * @return {@code true} if this input stream has more input (including whitespace); + * {@code false} otherwise + */ + public boolean hasNextLine() { + return scanner.hasNextLine(); + } + + /** + * Returns true if this input stream has more input (including whitespace). + * Use this method to know whether the next call to {@link #readChar()} will succeed. + * This method is functionally equivalent to {@link #hasNextLine()}. + * + * @return {@code true} if this input stream has more input (including whitespace); + * {@code false} otherwise + */ + public boolean hasNextChar() { + scanner.useDelimiter(EMPTY_PATTERN); + boolean result = scanner.hasNext(); + scanner.useDelimiter(WHITESPACE_PATTERN); + return result; + } + + + /** + * Reads and returns the next line in this input stream. + * + * @return the next line in this input stream; {@code null} if no such line + */ + public String readLine() { + String line; + try { + line = scanner.nextLine(); + } + catch (NoSuchElementException e) { + line = null; + } + return line; + } + + /** + * Reads and returns the next character in this input stream. + * + * @return the next {@code char} in this input stream + * @throws NoSuchElementException if the input stream is empty + */ + public char readChar() { + scanner.useDelimiter(EMPTY_PATTERN); + try { + String ch = scanner.next(); + assert ch.length() == 1 : "Internal (Std)In.readChar() error!" + + " Please contact the authors."; + scanner.useDelimiter(WHITESPACE_PATTERN); + return ch.charAt(0); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attempts to read a 'char' value from input stream, but there are no more tokens available"); + } + } + + + /** + * Reads and returns the remainder of this input stream, as a string. + * + * @return the remainder of this input stream, as a string + */ + public String readAll() { + if (!scanner.hasNextLine()) + return ""; + + String result = scanner.useDelimiter(EVERYTHING_PATTERN).next(); + // not that important to reset delimeter, since now scanner is empty + scanner.useDelimiter(WHITESPACE_PATTERN); // but let's do it anyway + return result; + } + + + /** + * Reads the next token from this input stream and returns it as a {@code String}. + * + * @return the next {@code String} in this input stream + * @throws NoSuchElementException if the input stream is empty + */ + public String readString() { + try { + return scanner.next(); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attempts to read a 'String' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code int}, + * and returns the {@code int}. + * + * @return the next {@code int} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as an {@code int} + */ + public int readInt() { + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read an 'int' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read an 'int' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code double}, + * and returns the {@code double}. + * + * @return the next {@code double} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code double} + */ + public double readDouble() { + try { + return scanner.nextDouble(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read a 'double' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read a 'double' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code float}, + * and returns the {@code float}. + * + * @return the next {@code float} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code float} + */ + public float readFloat() { + try { + return scanner.nextFloat(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read a 'float' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read a 'float' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code long}, + * and returns the {@code long}. + * + * @return the next {@code long} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code long} + */ + public long readLong() { + try { + return scanner.nextLong(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read a 'long' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read a 'long' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code short}, + * and returns the {@code short}. + * + * @return the next {@code short} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code short} + */ + public short readShort() { + try { + return scanner.nextShort(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read a 'short' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read a 'short' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code byte}, + * and returns the {@code byte}. + * <p> + * To read binary data, use {@link BinaryIn}. + * + * @return the next {@code byte} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code byte} + */ + public byte readByte() { + try { + return scanner.nextByte(); + } + catch (InputMismatchException e) { + String token = scanner.next(); + throw new InputMismatchException("attempts to read a 'byte' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attemps to read a 'byte' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads the next token from this input stream, parses it as a {@code boolean} + * (interpreting either {@code "true"} or {@code "1"} as {@code true}, + * and either {@code "false"} or {@code "0"} as {@code false}). + * + * @return the next {@code boolean} in this input stream + * @throws NoSuchElementException if the input stream is empty + * @throws InputMismatchException if the next token cannot be parsed as a {@code boolean} + */ + public boolean readBoolean() { + try { + String token = readString(); + if ("true".equalsIgnoreCase(token)) return true; + if ("false".equalsIgnoreCase(token)) return false; + if ("1".equals(token)) return true; + if ("0".equals(token)) return false; + throw new InputMismatchException("attempts to read a 'boolean' value from input stream, but the next token is \"" + token + "\""); + } + catch (NoSuchElementException e) { + throw new NoSuchElementException("attempts to read a 'boolean' value from input stream, but there are no more tokens available"); + } + } + + /** + * Reads all remaining tokens from this input stream and returns them as + * an array of strings. + * + * @return all remaining tokens in this input stream, as an array of strings + */ + public String[] readAllStrings() { + // we could use readAll.trim().split(), but that's not consistent + // since trim() uses characters 0x00..0x20 as whitespace + String[] tokens = WHITESPACE_PATTERN.split(readAll()); + if (tokens.length == 0 || tokens[0].length() > 0) + return tokens; + String[] decapitokens = new String[tokens.length-1]; + for (int i = 0; i < tokens.length-1; i++) + decapitokens[i] = tokens[i+1]; + return decapitokens; + } + + /** + * Reads all remaining lines from this input stream and returns them as + * an array of strings. + * + * @return all remaining lines in this input stream, as an array of strings + */ + public String[] readAllLines() { + ArrayList<String> lines = new ArrayList<String>(); + while (hasNextLine()) { + lines.add(readLine()); + } + return lines.toArray(new String[lines.size()]); + } + + + /** + * Reads all remaining tokens from this input stream, parses them as integers, + * and returns them as an array of integers. + * + * @return all remaining lines in this input stream, as an array of integers + */ + public int[] readAllInts() { + String[] fields = readAllStrings(); + int[] vals = new int[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Integer.parseInt(fields[i]); + return vals; + } + + /** + * Reads all remaining tokens from this input stream, parses them as longs, + * and returns them as an array of longs. + * + * @return all remaining lines in this input stream, as an array of longs + */ + public long[] readAllLongs() { + String[] fields = readAllStrings(); + long[] vals = new long[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Long.parseLong(fields[i]); + return vals; + } + + /** + * Reads all remaining tokens from this input stream, parses them as doubles, + * and returns them as an array of doubles. + * + * @return all remaining lines in this input stream, as an array of doubles + */ + public double[] readAllDoubles() { + String[] fields = readAllStrings(); + double[] vals = new double[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Double.parseDouble(fields[i]); + return vals; + } + + ///// end: section (2 of 2) of code duplicated from In to StdIn */ + + /** + * Closes this input stream. + */ + public void close() { + scanner.close(); + } + + /** + * Reads all integers from a file and returns them as + * an array of integers. + * + * @param filename the name of the file + * @return the integers in the file + * @deprecated Replaced by {@code new In(filename)}.{@link #readAllInts()}. + */ + @Deprecated + public static int[] readInts(String filename) { + return new In(filename).readAllInts(); + } + + /** + * Reads all doubles from a file and returns them as + * an array of doubles. + * + * @param filename the name of the file + * @return the doubles in the file + * @deprecated Replaced by {@code new In(filename)}.{@link #readAllDoubles()}. + */ + @Deprecated + public static double[] readDoubles(String filename) { + return new In(filename).readAllDoubles(); + } + + /** + * Reads all strings from a file and returns them as + * an array of strings. + * + * @param filename the name of the file + * @return the strings in the file + * @deprecated Replaced by {@code new In(filename)}.{@link #readAllStrings()}. + */ + @Deprecated + public static String[] readStrings(String filename) { + return new In(filename).readAllStrings(); + } + + /** + * Reads all integers from standard input and returns them + * an array of integers. + * + * @return the integers on standard input + * @deprecated Replaced by {@link StdIn#readAllInts()}. + */ + @Deprecated + public static int[] readInts() { + return new In().readAllInts(); + } + + /** + * Reads all doubles from standard input and returns them as + * an array of doubles. + * + * @return the doubles on standard input + * @deprecated Replaced by {@link StdIn#readAllDoubles()}. + */ + @Deprecated + public static double[] readDoubles() { + return new In().readAllDoubles(); + } + + /** + * Reads all strings from standard input and returns them as + * an array of strings. + * + * @return the strings on standard input + * @deprecated Replaced by {@link StdIn#readAllStrings()}. + */ + @Deprecated + public static String[] readStrings() { + return new In().readAllStrings(); + } + + /** + * Unit tests the {@code In} data type. + * + * @param args the command-line arguments + */ + public static void main(String[] args) { + In in; + String urlName = "https://introcs.cs.princeton.edu/stdlib/InTest.txt"; + + // read from a URL + System.out.println("readAll() from URL " + urlName); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In(urlName); + System.out.println(in.readAll()); + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + // read one line at a time from URL + System.out.println("readLine() from URL " + urlName); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In(urlName); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + // read one string at a time from URL + System.out.println("readString() from URL " + urlName); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In(urlName); + while (!in.isEmpty()) { + String s = in.readString(); + System.out.println(s); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + + // read one line at a time from file in current directory + System.out.println("readLine() from current directory"); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In("./InTest.txt"); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + + // read one line at a time from file using relative path + System.out.println("readLine() from relative path"); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In("../stdlib/InTest.txt"); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + // read one char at a time + System.out.println("readChar() from file"); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In("InTest.txt"); + while (!in.isEmpty()) { + char c = in.readChar(); + System.out.print(c); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + System.out.println(); + + // read one line at a time from absolute OS X / Linux path + System.out.println("readLine() from absolute OS X / Linux path"); + System.out.println("---------------------------------------------------------------------------"); + in = new In("/n/fs/introcs/www/java/stdlib/InTest.txt"); + try { + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + + // read one line at a time from absolute Windows path + System.out.println("readLine() from absolute Windows path"); + System.out.println("---------------------------------------------------------------------------"); + try { + in = new In("G:\\www\\introcs\\stdlib\\InTest.txt"); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + System.out.println(); + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + System.out.println(); + + } + +} \ No newline at end of file diff --git a/src/search/Node.java b/src/search/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..b661f73b6f20207437721739e1f00aa98acf07dd --- /dev/null +++ b/src/search/Node.java @@ -0,0 +1,113 @@ +package search; + +// An abstract data type that represents a node in a Red Black Search Tree +public class Node<Key, Value>{ + + private final Comparable<Key> key; + private Value val; + private Node<Key, Value> left, right; + private int n; + private boolean color; + + /** + * Constructor + * @param key Used to assign order amongst the nodes/implement comparability + * @param val The value stored at a node + * @param n How many nodes are in the subtree beneath this node (inclusive) + * @param color True represents a red connection between the current node and its parent, black represents false + */ + public Node(Comparable<Key> key, Value val, int n, boolean color){ + this.key = key; + this.val = val; + this.n = n; + this.color = color; + } + + /** + * Getter for a node's key + * @return The node's key + */ + public Comparable<Key> key(){ + return this.key; + } + + /** + * Getter for a node's value + * @return The node's value + */ + public Value val(){ + return this.val; + } + + /** + * Setter for a node's value + * @param val New value being assigned + */ + public void val(Value val){ + this.val = val; + } + + /** + * Getter for a node's left child + * @return The node's left child + */ + public Node<Key, Value> left(){ + return this.left; + } + + /** + * Setter for a node's left child + * @param left The node's new left child + */ + public void left(Node<Key, Value> left){ + this.left = left; + } + + /** + * Getter for a node's right child + * @return The node's right child + */ + public Node<Key, Value> right(){ + return this.right; + } + + /** + * Setter for a node's right child + * @param left The node's new right child + */ + public void right(Node<Key, Value> right){ + this.right = right; + } + + /** + * Getter for the subtree size beneath the current node + * @return Subtree size + */ + public int n(){ + return this.n; + } + + /** + * Setter for a subtree's size + * @param n New subtree size + */ + public void n(int n){ + this.n = n; + } + + /** + * Getter method for a node's color + * @return The node's color + */ + public boolean color(){ + return this.color; + } + + /** + * Setter for a node's color + * @param color New node color + */ + public void color(boolean color){ + this.color = color; + } +} diff --git a/src/search/RecordCluster.java b/src/search/RecordCluster.java new file mode 100644 index 0000000000000000000000000000000000000000..e896722d99576a106e6e3fbf1ac7dd1dcc4d5346 --- /dev/null +++ b/src/search/RecordCluster.java @@ -0,0 +1,38 @@ +package search; + +import java.util.ArrayList; + +import data.Record; +import sandbox.Point; + +public class RecordCluster { + private ArrayList<Record> records; + private Point centroid; + + public void addRecord(Record r) { + records.add(r); + } + + public Iterable<Record> records(){ + return records; + } + + public int N() { + return records.size(); + } + + public Point centroid() { + double x = 0; + double y = 0; + + for (Record r: records()) { + x += r.getLongitude(); + y += r.getLatitude(); + } + + x /= N(); + y /= N(); + + return new Point(x, y); + } +} diff --git a/src/search/RedBlackTree.java b/src/search/RedBlackTree.java new file mode 100644 index 0000000000000000000000000000000000000000..8d5728ef2d2d6a3315e9da2dabed2353e89b5002 --- /dev/null +++ b/src/search/RedBlackTree.java @@ -0,0 +1,184 @@ +package search; + +public class RedBlackTree<Key, Value> { + private Node<Key, Value> root; // Root of the tree + private GeneralCompare<Key> compare; + private Field<Key, Value> field; + + // Main method only used for testing + + public static void main(String[] args) { + GeneralCompare<Integer> b1; + b1 = (a1, a2) -> (Integer) a1 - (Integer) a2; + Field<Integer, Integer[]> fld; + fld = (a1) -> (Integer) a1[0]; + + + Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}}; + RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1); + for(int i = 0; i < x.length; i++){ + myTree.put(x[i]); + } + Node h = myTree.root(); + System.out.println(h.key()); + while (h.left() != null) { + System.out.println(h.left().key()); + h = h.left(); + } + } + + + /** + * Constructor for a red black tree object + * @param fld A function that retrieves the desired field from an array of comparable items + * @param gc A function that compares two comparable items + */ + public RedBlackTree(Field<Key, Value> fld, GeneralCompare<Key> gc) { + compare = gc; + field = fld; + } + + /** + * Getter method for the root of a tree + * @return The root of a tree object + */ + public Node<Key, Value> root() { + return root; + } + + /** + * Wrapper method for adding a new node + * @param val A new record + */ + public void put(Value val){ + Node<Key, Value> newNode = new Node<Key, Value>(field.field(val), val, 1, true); + root = put(root, newNode); + } + + /** + * Adds a new node to an existing tree + * @param h An existing node on the tree + * @param newNode A node to be added to the tree + * @return + */ + private Node<Key, Value> put(Node<Key, Value> h, Node<Key, Value> newNode){ + // Placing the first node in a tree + if (root == null) { + root = newNode; + root.color(false); + return root; + } + + // Place new element in the tree + int cmp = compare.compare(newNode.key(), h.key()); + if (cmp < 0 && (h.left() == null)) + h.left(newNode); + else if (cmp < 0 ) + h.left(put(h.left(), newNode)); + else if (cmp > 0 && (h.right() == null)) + h.right(newNode); + else if (cmp > 0) + h.right(put(h.right(), newNode)); + else + h = newNode; + + // Rearrange the tree to maintain balance + if(h.n() > 2){ + if(isRed(h.right()) && !isRed(h.left())) + h = rotateLeft(h); + if(isRed(h.left()) && isRed(h.left().left())) + h = rotateRight(h); + if(isRed(h.left()) && isRed(h.right())) + flipColors(h); + } + + // Increment how many nodes are in a subtree + if ((h.left() != null) && (h.right() != null)) + h.n(h.left().n() + h.right().n() + 1); + else if (h.left() != null) + h.n(h.left().n() + 1); + else if (h.right() != null) + h.n(h.right().n() + 1); + else + h.n(1); + + return h; + } + + /** + * Check if the link to a node's parent is red + * @param x Node in a tree + * @return Boolean result of whether the node is red or not + */ + private boolean isRed(Node<Key, Value> x){ + if (x == null) + return false; + return x.color(); + } + + /** + * Rotates a subtree in a counterclockwise direction + * @param h Root of a tree segment to be rotated + * @return New root of the rotated segment + */ + public Node<Key, Value> rotateLeft(Node<Key, Value> h){ + System.out.println("Rotate left!"); + Node<Key, Value> x = h.right(); + h.right(x.left()); + x.left(h); + x.color(h.color()); + h.color(true); + x.n(h.n()); + + // Increment how many nodes are in a subtree + if (h.left() != null & h.right() != null) + h.n(h.left().n() + h.right().n() + 1); + else if (h.left() != null) + h.n(h.left().n() + 1); + else if (h.right() != null) + h.n(h.right().n() + 1); + else + h.n(1); + + return x; + } + + /** + * Rotates a subtree in a clockwise direction + * @param h Root of a tree segment to be rotated + * @return New root of the rotated segment + */ + public Node<Key, Value> rotateRight(Node<Key, Value> h){ + Node<Key, Value> x = h.left(); + h.left(x.right()); + x.right(h); + x.color(h.color()); + h.color(true); + x.n(h.n()); + + // Increment how many nodes are in a subtree + if (h.left() != null & h.right() != null) + h.n(h.left().n() + h.right().n() + 1); + else if (h.left() != null) + h.n(h.left().n() + 1); + else if (h.right() != null) + h.n(h.right().n() + 1); + else + h.n(1); + + return x; + + } + + /** + * Changes two red connections from a single node to black + * @param h Root of tree segment whose colors are to be switched + */ + private void flipColors(Node<Key, Value> h){ + if(h.left() != null && h.right() != null){ + h.left().color(false); + h.right().color(false); + h.color(true); + } + } +} \ No newline at end of file diff --git a/src/sort/Bound.java b/src/sort/Bound.java index d6b4b7f3c65aa330faebca302ac14480fcbc3c75..47b0eea9de7c3246259a0bda1d866292b606956a 100644 --- a/src/sort/Bound.java +++ b/src/sort/Bound.java @@ -1,9 +1,14 @@ +<<<<<<< HEAD package sort; /** * Enumeration of bound types. * @author Christopher W. Schankula * */ +======= +package sort; + +>>>>>>> b093c71758057e7a5b83b69a7632a229ad1469bf public enum Bound { LOWER, UPPER, LOWHIGH, ANY, EQUALS; -} +} diff --git a/src/sort/KDT.java b/src/sort/KDT.java index 8709fc5cb21d0a07f24894f66fe353053f7ed7bc..cb6b9bc21953ff04f2cfba118aab87cec794d21e 100644 --- a/src/sort/KDT.java +++ b/src/sort/KDT.java @@ -1,217 +1,217 @@ -package sort; - -import sandbox.Point; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; - -public class KDT<KeyVal extends Comparable<KeyVal>> implements Serializable { - /** - * - */ - private static final long serialVersionUID = 8807259801436570835L; - /** - * - */ - KDNode root; - ArrayList<GeneralCompare<KeyVal>> axes; - - public static void main(String[] args) { - GeneralCompare<Point> compX = (p1, p2) -> ((Point) p1).getX() - ((Point) p2).getX(); - GeneralCompare<Point> compY = (p1, p2) -> ((Point) p1).getY() - ((Point) p2).getY(); - - //(2,3), (4,7), (5,4), (7,2), (8,1), (9,6) - //(8,1), (7,2), (2,3), (5,4), (9,6), (4,7) - Point p1 = new Point(2,3); - Point p2 = new Point(5,4); - Point p3 = new Point(9,6); - Point p4 = new Point(4,7); - Point p5 = new Point(8,1); - Point p6 = new Point(7,2); - - ArrayList<GeneralCompare<Point>> axes = new ArrayList<GeneralCompare<Point>>(); - axes.add(compX); - axes.add(compY); - - Point[] pts = {p1, p2, p3, p4, p5, p6}; - - //KDT<Point> kdt = new KDT<Point>(axes, pts); - KDT<Point> kdt = new KDT<Point>("kdtree.ser"); - System.out.println(kdt.size()); - System.out.println(kdt.height()); - - //GeneralRange<Point> xRange = p -> 4 <= p.getX() && p.getX() <= 6; - //GeneralRange<Point> yRange = p -> 3 <= p.getY() && p.getY() <= 5; - - GeneralRange<Point> xRange = p -> p.getX() < 2 ? -1 : (p.getX() > 7 ? 1 : 0); - GeneralRange<Point> yRange = p -> 0;//p.getY() < 3 ? -1 : (p.getY() > 6 ? 1 : 0); - - - ArrayList<GeneralRange<Point>> ranges = new ArrayList<GeneralRange<Point>>(); - ranges.add(xRange); - ranges.add(yRange); - - Iterable<Point> results = kdt.rangeSearch(ranges); - - System.out.println("Results"); - for (Point p : results) { - System.out.println(p); - } - - System.out.println(kdt.toString()); - - kdt.writeToFile("kdtree.ser"); - } - - private class KDNode implements Serializable{ - /** - * - */ - private static final long serialVersionUID = -664511393872278542L; - /** - * - */ - private KeyVal keyval; - private KDNode left, right; - private int n; - - public KDNode(KeyVal keyval, int n) { - this.keyval = keyval; - this.n = n; - } - } - - /** - * Load a kd-tree from a serialized file. - * @param fn - */ - public KDT(String fn) { - KDT<KeyVal> kdt = null; - try { - FileInputStream fileIn = new FileInputStream(fn); - ObjectInputStream in = new ObjectInputStream(fileIn); - kdt = (KDT<KeyVal>) in.readObject(); - in.close(); - fileIn.close(); - } catch (IOException i) { - i.printStackTrace(); - } catch (ClassNotFoundException c) { - System.out.println("Employee class not found"); - c.printStackTrace(); - } - //https://stackoverflow.com/questions/26327956/set-this-in-a-class - this.root = kdt.root; - this.axes = kdt.axes; - } - - public KDT(ArrayList<GeneralCompare<KeyVal>> axes, Comparable<KeyVal>[] keyvals) { - this.axes = axes; - root = buildTree(keyvals, 0, keyvals.length - 1, 0); - } - - private KDNode buildTree(Comparable<KeyVal>[] keyvals, int lo, int hi, int depth) { - if (lo > hi) return null; - int axis = depth % getK(); - - int mid = (lo + hi) / 2; - MergeSort.sort(keyvals, lo, hi, axes.get(axis)); - KeyVal median = (KeyVal) keyvals[mid]; - - //TODO: fix size - KDNode newNode = new KDNode(median, 0); - newNode.left = buildTree(keyvals, lo, mid - 1, depth + 1); - newNode.right = buildTree(keyvals, mid + 1, hi, depth + 1); - - newNode.n = size(newNode.left) + size(newNode.right) + 1; - return newNode; - } - - public Iterable<KeyVal> rangeSearch(ArrayList<GeneralRange<KeyVal>> range){ - ArrayList<KeyVal> result = new ArrayList<KeyVal>(); - rangeSearch(root, range, result, 0); - return result; - } - - private void rangeSearch(KDNode x, ArrayList<GeneralRange<KeyVal>> range, ArrayList<KeyVal> result, int depth) { - if (x == null) return; - int axis = depth % getK(); - GeneralRange<KeyVal> rg = range.get(axis); - - //System.out.println("Try: " + x.keyval); - - int bounds = rg.isInBounds((KeyVal) x.keyval); - if (bounds == 0) { - //System.out.println(pointInside(x.keyval, range)); - if (pointInside(x.keyval, range)) { - result.add(x.keyval); - } - rangeSearch(x.left, range, result, depth + 1); - rangeSearch(x.right, range, result, depth + 1); - } else if (bounds > 0) { - rangeSearch(x.left, range, result, depth + 1); - } else if (bounds < 0) - rangeSearch(x.right, range, result, depth + 1); - - return; - } - - private boolean pointInside(KeyVal pt, ArrayList<GeneralRange<KeyVal>> range) { - for (int i = 0; i < axes.size(); i++) - if (range.get(i).isInBounds(pt) != 0) return false; - return true; - } - - public int size() { - return size(root); - } - - public int height() { - return height(root); - } - - private int height(KDNode x) { - if (x == null) return 0; - return 1 + Math.max(height(x.left), height(x.right)); - } - - private int size(KDNode x) { - if (x == null) return 0; - else return x.n; - } - - public int getK() { - return axes.size(); - } - - public String toString() { - return toString(root, ""); - } - - public void writeToFile(String fn) { - try { - FileOutputStream fileOut = - new FileOutputStream(fn); - ObjectOutputStream out = new ObjectOutputStream(fileOut); - out.writeObject(this); - out.close(); - fileOut.close(); - System.out.printf("Serialized data is saved in /tmp/kdtree.ser"); - } catch (IOException i) { - i.printStackTrace(); - } - } - - private String toString(KDNode x, String depth) { - if (x == null) return depth + "null\n"; - String result = ""; - result += depth + x.keyval.toString() + "\n"; - result += toString(x.left, depth + " "); - result += toString(x.right, depth + " "); - return result; - } -} +package sort; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; + +import sandbox.Point; + +public class KDT<KeyVal extends Comparable<KeyVal>> implements Serializable { + /** + * + */ + private static final long serialVersionUID = 8807259801436570835L; + /** + * + */ + KDNode root; + ArrayList<GeneralCompare<KeyVal>> axes; + + public static void main(String[] args) { + GeneralCompare<Point> compX = (p1, p2) -> (int) ((Point) p1).getX() - (int) ((Point) p2).getX(); + GeneralCompare<Point> compY = (p1, p2) -> (int) ((Point) p1).getY() - (int) ((Point) p2).getY(); + + //(2,3), (4,7), (5,4), (7,2), (8,1), (9,6) + //(8,1), (7,2), (2,3), (5,4), (9,6), (4,7) + Point p1 = new Point(2,3); + Point p2 = new Point(5,4); + Point p3 = new Point(9,6); + Point p4 = new Point(4,7); + Point p5 = new Point(8,1); + Point p6 = new Point(7,2); + + ArrayList<GeneralCompare<Point>> axes = new ArrayList<GeneralCompare<Point>>(); + axes.add(compX); + axes.add(compY); + + Point[] pts = {p1, p2, p3, p4, p5, p6}; + + //KDT<Point> kdt = new KDT<Point>(axes, pts); + KDT<Point> kdt = new KDT<Point>("kdtree.ser"); + System.out.println(kdt.size()); + System.out.println(kdt.height()); + + //GeneralRange<Point> xRange = p -> 4 <= p.getX() && p.getX() <= 6; + //GeneralRange<Point> yRange = p -> 3 <= p.getY() && p.getY() <= 5; + + GeneralRange<Point> xRange = p -> p.getX() < 2 ? -1 : (p.getX() > 7 ? 1 : 0); + GeneralRange<Point> yRange = p -> 0;//p.getY() < 3 ? -1 : (p.getY() > 6 ? 1 : 0); + + + ArrayList<GeneralRange<Point>> ranges = new ArrayList<GeneralRange<Point>>(); + ranges.add(xRange); + ranges.add(yRange); + + Iterable<Point> results = kdt.rangeSearch(ranges); + + System.out.println("Results"); + for (Point p : results) { + System.out.println(p); + } + + System.out.println(kdt.toString()); + + kdt.writeToFile("kdtree.ser"); + } + + private class KDNode implements Serializable{ + /** + * + */ + private static final long serialVersionUID = -664511393872278542L; + /** + * + */ + private KeyVal keyval; + private KDNode left, right; + private int n; + + public KDNode(KeyVal keyval, int n) { + this.keyval = keyval; + this.n = n; + } + } + + /** + * Load a kd-tree from a serialized file. + * @param fn + */ + public KDT(String fn) { + KDT<KeyVal> kdt = null; + try { + FileInputStream fileIn = new FileInputStream(fn); + ObjectInputStream in = new ObjectInputStream(fileIn); + kdt = (KDT<KeyVal>) in.readObject(); + in.close(); + fileIn.close(); + } catch (IOException i) { + i.printStackTrace(); + } catch (ClassNotFoundException c) { + System.out.println("Employee class not found"); + c.printStackTrace(); + } + //https://stackoverflow.com/questions/26327956/set-this-in-a-class + this.root = kdt.root; + this.axes = kdt.axes; + } + + public KDT(ArrayList<GeneralCompare<KeyVal>> axes, Comparable<KeyVal>[] keyvals) { + this.axes = axes; + root = buildTree(keyvals, 0, keyvals.length - 1, 0); + } + + private KDNode buildTree(Comparable<KeyVal>[] keyvals, int lo, int hi, int depth) { + if (lo > hi) return null; + int axis = depth % getK(); + + int mid = (lo + hi) / 2; + MergeSort.sort(keyvals, lo, hi, axes.get(axis)); + KeyVal median = (KeyVal) keyvals[mid]; + + //TODO: fix size + KDNode newNode = new KDNode(median, 0); + newNode.left = buildTree(keyvals, lo, mid - 1, depth + 1); + newNode.right = buildTree(keyvals, mid + 1, hi, depth + 1); + + newNode.n = size(newNode.left) + size(newNode.right) + 1; + return newNode; + } + + public Iterable<KeyVal> rangeSearch(ArrayList<GeneralRange<KeyVal>> range){ + ArrayList<KeyVal> result = new ArrayList<KeyVal>(); + rangeSearch(root, range, result, 0); + return result; + } + + private void rangeSearch(KDNode x, ArrayList<GeneralRange<KeyVal>> range, ArrayList<KeyVal> result, int depth) { + if (x == null) return; + int axis = depth % getK(); + GeneralRange<KeyVal> rg = range.get(axis); + + //System.out.println("Try: " + x.keyval); + + int bounds = rg.isInBounds((KeyVal) x.keyval); + if (bounds == 0) { + //System.out.println(pointInside(x.keyval, range)); + if (pointInside(x.keyval, range)) { + result.add(x.keyval); + } + rangeSearch(x.left, range, result, depth + 1); + rangeSearch(x.right, range, result, depth + 1); + } else if (bounds > 0) { + rangeSearch(x.left, range, result, depth + 1); + } else if (bounds < 0) + rangeSearch(x.right, range, result, depth + 1); + + return; + } + + private boolean pointInside(KeyVal pt, ArrayList<GeneralRange<KeyVal>> range) { + for (int i = 0; i < axes.size(); i++) + if (range.get(i).isInBounds(pt) != 0) return false; + return true; + } + + public int size() { + return size(root); + } + + public int height() { + return height(root); + } + + private int height(KDNode x) { + if (x == null) return 0; + return 1 + Math.max(height(x.left), height(x.right)); + } + + private int size(KDNode x) { + if (x == null) return 0; + else return x.n; + } + + public int getK() { + return axes.size(); + } + + public String toString() { + return toString(root, ""); + } + + public void writeToFile(String fn) { + try { + FileOutputStream fileOut = + new FileOutputStream(fn); + ObjectOutputStream out = new ObjectOutputStream(fileOut); + out.writeObject(this); + out.close(); + fileOut.close(); + System.out.printf("Serialized data is saved in /tmp/kdtree.ser"); + } catch (IOException i) { + i.printStackTrace(); + } + } + + private String toString(KDNode x, String depth) { + if (x == null) return depth + "null\n"; + String result = ""; + result += depth + x.keyval.toString() + "\n"; + result += toString(x.left, depth + " "); + result += toString(x.right, depth + " "); + return result; + } +} diff --git a/src/sort/MergeSort.java b/src/sort/MergeSort.java index defaccfa246c3f0af1d334286489f02e0307f907..836eac549e103cf15d16c4643b70abe2e8f6aac0 100644 --- a/src/sort/MergeSort.java +++ b/src/sort/MergeSort.java @@ -1,7 +1,7 @@ package sort; public class MergeSort{ - + /*// Main Function for Testing Purposes Only public static void main(String[] args) { GeneralCompare<Integer> b1; b1 = (a1, a2) -> (Integer) a1 - (Integer) a2; @@ -12,16 +12,30 @@ public class MergeSort{ for (int i = 0 ; i < (test.length) ; i++) { System.out.println(test[i]); } - } + }*/ + /** + * Wrapper function for the MergeSort implementation + * @param x Array of comparable items to be sorted + * @param lo Lower bound of a sub-array to be sorted + * @param hi Upper bound of a sub-array to be sorted + * @param gc A lambda function that compares two comparable items + */ public static <T> void sort(Comparable<T>[] x, int lo, int hi, GeneralCompare<T> gc) { Comparable<T>[] aux; aux = (Comparable<T>[]) new Comparable[x.length]; sortWrapped(x, lo, hi, gc, aux); } + /** + * Recursively sort each half of a sub-array + * @param lo + * @param hi + * @param gc + * @param aux Auxiliary array to accommodate temporary memory use in the algorithm + */ private static <T> void sortWrapped(Comparable<T>[] x, int lo, int hi, GeneralCompare<T> gc, Comparable<T>[] aux) { - int n = hi - lo; + int n = hi - lo; if(n < 1) return; // Recursively sort each half of the array @@ -31,13 +45,18 @@ public class MergeSort{ merge(x, lo, hi, gc, aux); } + /** + * Merges two sorted sub-arrays into a single sorted array + * @param x + * @param lo + * @param hi + * @param gc + * @param aux + */ private static <T> void merge(Comparable<T>[] x, int lo, int hi, GeneralCompare<T> gc, Comparable<T>[] aux){ int n = hi - lo; int mid = lo + (n/2); - - // Fill auxiliary array - //System.out.println("lo, mid, hi: " + lo + ", " + mid + ", " + hi); for(int k = lo; k <= hi; k++){ aux[k] = x[k]; diff --git a/src/sort/QuickSelect.java b/src/sort/QuickSelect.java new file mode 100644 index 0000000000000000000000000000000000000000..623352224c0c0e228cba2167722fedb2b5d63e87 --- /dev/null +++ b/src/sort/QuickSelect.java @@ -0,0 +1,105 @@ +package sort; + +import search.GeneralCompare; + +// Code from "Algorithms: 4th Edition" by Robert Sedgewick +// Adapted from the Sedgewick Quicksort implementation + +public class QuickSelect { + + /* + // Main function for testing purposes only + public static void main(String[] args) { + //{1, 2, 3, 4, 5, 6, 7, 8, 9} 5 is median. + Integer[] test = {4, 6, 7, 2, 2, 2, 2,2, 2, 2,2 ,2 ,2, 2, 2}; + GeneralCompare<Integer> b1; + b1 = (a1, a2) -> (Integer) a1 - (Integer) a2; + + median(test, b1); + System.out.println(test[test.length/2]); + } + */ + + /** + * Partially sorts a comparable array such that elements smaller than the median occur in + * the first half of the array, and elements larger than the median occur in the second half + * @param a Array of comparable items + * @param gc Lambda function to compare items + */ + public static <T> void median(Comparable<T>[] a, GeneralCompare<T> gc) { + sort(a, 0, a.length - 1, a.length/2, gc); + } + + /** + * Partially sorts a comparable array such that elements smaller than the kth largest element + * occur in the first half of the array, and larger elements occur in the second half + * @param a Array of comparable items + * @param k Pivot element that will be in its sorted place in the array + * @param gc Lambda function to compare items + */ + public static <T> void partialSort(Comparable<T>[] a, int k, GeneralCompare<T> gc) { + sort(a, 0, a.length - 1, k, gc); + } + + /** + * Sorts the half of the array containing the kth (or median) index + * @param a Array of comparable items + * @param lo Lower bound index of the subarray to be sorted + * @param hi Upper bound index of the subarray to be sorted + * @param k Pivot element that will be in its sorted place in the array + * @param gc Lambda function to compare items + */ + public static <T> void sort(Comparable<T>[] a, int lo, int hi, int k, GeneralCompare<T> gc) { + if (hi <= lo) + return; + int j = partition(a, lo, hi, gc); + if (j < k) + sort(a, j + 1, hi, k, gc); // Sort right part a[j+1 .. hi]. + else if (j > k) + sort(a, lo, j - 1, k, gc); // Sort left part a[lo .. j-1]. + return; + } + + /** + * Places elements smaller than a partitioning element at smaller indices than the partitioning element + * Same algorithm for partitioning as standard QuickSort from + * @param a Array of comparable items + * @param lo Index that scans from the left side of the array, points to an item to be compared + * @param hi Index that scans from the right side of the array, points to an item to be compared + * @param gc Lambda function to compare items + * @return + */ + private static <T> int partition(Comparable<T>[] a, int lo, int hi, GeneralCompare<T> gc) { + // Partition into a[lo..i-1], a[i], a[i+1..hi]. + int i = lo, j = hi + 1; // left and right scan indices + Comparable<T> v = a[lo]; // partitioning item + + while (true) { // Scan right, scan left, check for scan complete, and exchange. + while (gc.compare(a[++i], v) < 0) + if (i == hi) + break; + while (gc.compare(v, a[--j]) < 0) + if (j == lo) + break; + if (i >= j) + break; + exch(a, i, j); + } + + exch(a, lo, j); + return j; + } + + /** + * Exchanges the values at two indices of an array + * @param a Array of comparable items + * @param b Index of an item to be swapped + * @param c Index of an item to be swapped + */ + private static <T> void exch(Comparable<T>[] a, int b, int c) { + Comparable<T> temp = a[c]; + a[c] = a[b]; + a[b] = temp; + } + +} diff --git a/src/sort/Range.java b/src/sort/Range.java index 4ffa5e71db4df84c414b149504a36e7a32847fcc..59b943785f9b3188d8a55f6dbdd4898114a9874e 100644 --- a/src/sort/Range.java +++ b/src/sort/Range.java @@ -37,11 +37,15 @@ public class Range<Key extends Comparable<Key>> { this.boundType = bt; } +<<<<<<< HEAD + public <T> boolean inBounds(T key) { +======= <<<<<<< HEAD public <T> boolean inBounds(T key) { ======= public boolean inBounds(Key key, GeneralCompare<Key> gc) { >>>>>>> fd3aa70... add Bound and Range +>>>>>>> refs/remotes/origin/master if (boundType == Bound.ANY) return true; else if (boundType == Bound.LOWER) return gc.compare(lower, key) <= 0; else if (boundType == Bound.UPPER) return gc.compare(upper, key) >= 0; diff --git a/src/web/Director.java b/src/web/Director.java index 6225be3a4d45618d1fd4e4934f380599fcb91a00..669a712f8ce27b54b2008fef2ff9b5ea73ada418 100755 --- a/src/web/Director.java +++ b/src/web/Director.java @@ -2,10 +2,14 @@ package web; import javax.servlet.*; import javax.servlet.http.*; + +import data.Record; + import java.io.*; import java.util.*; //import com.example.model.TrawlExpert; // notice this import model.*; // notice this +import search.BasicSearchResult; public class Director extends HttpServlet { @@ -14,11 +18,13 @@ public class Director extends HttpServlet { //if (req == "doBioLookup.do") //doBioLookup(request, response); - TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl"); + TrawlExpert te = (TrawlExpert) request.getServletContext().getAttribute("trawl"); //very basic example of listing all species - Iterable<Integer> result = te.listAllSpecies(); + // Iterable<Integer> result = te.listAllSpecies(); + + BasicSearchResult result = te.rangeSearch(159512, 1960, 2016); - request.setAttribute("species", result); + request.setAttribute("results", result); RequestDispatcher view = request.getRequestDispatcher("result.jsp"); view.forward(request, response); } diff --git a/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.classpath b/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ac37fb2e4bca5ec7510383d7e55ea7b6b759e05a --- /dev/null +++ b/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.classpath @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.project b/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.project new file mode 100644 index 0000000000000000000000000000000000000000..ff1db54e8e75fcedb2a0b27c0661b0b6c87fc009 --- /dev/null +++ b/tomcat/webapps/Trawl/WEB-INF/classes/sandbox/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>sandbox</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/tomcat/webapps/Trawl/handles.html b/tomcat/webapps/Trawl/handles.html deleted file mode 100644 index 9b1e515ca31f8f426c9e863ad86f577f5e2a2684..0000000000000000000000000000000000000000 --- a/tomcat/webapps/Trawl/handles.html +++ /dev/null @@ -1,38 +0,0 @@ -<!doctype html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - - <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> - <!--<link rel="stylesheet" href="/resources/demos/style.css">--> - <script src="https://code.jquery.com/jquery-1.12.4.js"></script> - <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> - <script> - $( function() { - $( "#slider-range" ).slider({ - range: true, - min: 0, - max: 500, - values: [ 75, 300 ], - slide: function( event, ui ) { - $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] ); - } - }); - $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + - " - $" + $( "#slider-range" ).slider( "values", 1 ) ); - } ); - </script> -</head> -<body> - -<p> - <label for="amount">Price range:</label> - <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> -</p> - -<div id="slider-range"></div> - - -</body> -</html> \ No newline at end of file diff --git a/tomcat/webapps/Trawl/result.jsp b/tomcat/webapps/Trawl/result.jsp index 9ebd56779f74fb31e1f6871ce11c8470d54770fd..61848365c86730b9f99fd382a4cc94e7071909f1 100644 --- a/tomcat/webapps/Trawl/result.jsp +++ b/tomcat/webapps/Trawl/result.jsp @@ -1,14 +1,35 @@ -<%@ page import="java.util.*" %> +<%@page import="search.BasicSearchResult"%> +<%@ page import="java.util.*, data.Record, model.TrawlExpert" %> <html> <body> <h1 align="center">Trawl Results</h1> <p> +<table> +<tr> + <th>Scientific Name</th> + <th>Year</th> + <th>Month</th> + <th>Day</th> + <th>Latitude</th> + <th>Longitude</th> + <th>Individual Count</th> +</tr> <% - Iterable<Integer> species = (Iterable<Integer>)request.getAttribute("species"); - for (Integer s: species) - out.print("SpeciesID: " + s + "<br>"); - out.print((String) request.getAttribute("url")); + TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl"); + BasicSearchResult results = (BasicSearchResult) request.getAttribute("results"); + for (Record r: results.results()){ + out.print("<tr>\n"); + out.print("<th>" + te.getTaxonRecord(r.getTaxonId()).getName() + "</th>\n"); + out.print("<th>" + r.getDate().getYear() + "</th>\n"); + out.print("<th>" + r.getDate().getMonth() + "</th>\n"); + out.print("<th>" + r.getDate().getDay() + "</th>\n"); + out.print("<th>" + r.getLatitude() + "</th>\n"); + out.print("<th>" + r.getLongitude() + "</th>\n"); + out.print("<th>" + r.getCount() + "</th>\n"); + out.print("</tr>\n"); + } %> +</table> </body> </html> \ No newline at end of file diff --git a/tomcat/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java b/tomcat/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java index 21fd28856e91315da464559a24ce0739d18f6a78..96c9919315a8ac4d87491aaf561b754c8b992f70 100644 --- a/tomcat/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java +++ b/tomcat/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java @@ -1,7 +1,7 @@ /* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat/9.0.6 - * Generated at: 2018-03-12 20:39:19 UTC + * Generated at: 2018-03-27 23:07:19 UTC * Note: The last modified time of this file was set to * the last modified time of the source file after * generation to assist with modification tracking. @@ -111,8 +111,8 @@ public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase out = pageContext.getOut(); _jspx_out = out; - out.write("\r\n"); - out.write("\r\n"); + out.write('\n'); + out.write('\n'); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy"); request.setAttribute("year", sdf.format(new java.util.Date())); @@ -120,302 +120,302 @@ request.setAttribute("tomcatUrl", "http://tomcat.apache.org/"); request.setAttribute("tomcatDocUrl", "/docs/"); request.setAttribute("tomcatExamplesUrl", "/examples/"); - out.write("\r\n"); - out.write("<!DOCTYPE html>\r\n"); - out.write("<html lang=\"en\">\r\n"); - out.write(" <head>\r\n"); - out.write(" <meta charset=\"UTF-8\" />\r\n"); + out.write("\n"); + out.write("<!DOCTYPE html>\n"); + out.write("<html lang=\"en\">\n"); + out.write(" <head>\n"); + out.write(" <meta charset=\"UTF-8\" />\n"); out.write(" <title>"); out.print(request.getServletContext().getServerInfo() ); - out.write("</title>\r\n"); - out.write(" <link href=\"favicon.ico\" rel=\"icon\" type=\"image/x-icon\" />\r\n"); - out.write(" <link href=\"favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" />\r\n"); - out.write(" <link href=\"tomcat.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n"); - out.write(" </head>\r\n"); - out.write("\r\n"); - out.write(" <body>\r\n"); - out.write(" <div id=\"wrapper\">\r\n"); - out.write(" <div id=\"navigation\" class=\"curved container\">\r\n"); + out.write("</title>\n"); + out.write(" <link href=\"favicon.ico\" rel=\"icon\" type=\"image/x-icon\" />\n"); + out.write(" <link href=\"favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" />\n"); + out.write(" <link href=\"tomcat.css\" rel=\"stylesheet\" type=\"text/css\" />\n"); + out.write(" </head>\n"); + out.write("\n"); + out.write(" <body>\n"); + out.write(" <div id=\"wrapper\">\n"); + out.write(" <div id=\"navigation\" class=\"curved container\">\n"); out.write(" <span id=\"nav-home\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("\">Home</a></span>\r\n"); + out.write("\">Home</a></span>\n"); out.write(" <span id=\"nav-hosts\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("\">Documentation</a></span>\r\n"); + out.write("\">Documentation</a></span>\n"); out.write(" <span id=\"nav-config\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("config/\">Configuration</a></span>\r\n"); + out.write("config/\">Configuration</a></span>\n"); out.write(" <span id=\"nav-examples\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatExamplesUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("\">Examples</a></span>\r\n"); - out.write(" <span id=\"nav-wiki\"><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Wiki</a></span>\r\n"); + out.write("\">Examples</a></span>\n"); + out.write(" <span id=\"nav-wiki\"><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Wiki</a></span>\n"); out.write(" <span id=\"nav-lists\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html\">Mailing Lists</a></span>\r\n"); + out.write("lists.html\">Mailing Lists</a></span>\n"); out.write(" <span id=\"nav-help\"><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("findhelp.html\">Find Help</a></span>\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"asf-box\">\r\n"); + out.write("findhelp.html\">Find Help</a></span>\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" </div>\n"); + out.write(" <div id=\"asf-box\">\n"); out.write(" <h1>"); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.servletContext.serverInfo}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("</h1>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"upper\" class=\"curved container\">\r\n"); - out.write(" <div id=\"congrats\" class=\"curved container\">\r\n"); - out.write(" <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"notice\">\r\n"); - out.write(" <img src=\"tomcat.png\" alt=\"[tomcat logo]\" />\r\n"); - out.write(" <div id=\"tasks\">\r\n"); - out.write(" <h3>Recommended Reading:</h3>\r\n"); + out.write("</h1>\n"); + out.write(" </div>\n"); + out.write(" <div id=\"upper\" class=\"curved container\">\n"); + out.write(" <div id=\"congrats\" class=\"curved container\">\n"); + out.write(" <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>\n"); + out.write(" </div>\n"); + out.write(" <div id=\"notice\">\n"); + out.write(" <img src=\"tomcat.png\" alt=\"[tomcat logo]\" />\n"); + out.write(" <div id=\"tasks\">\n"); + out.write(" <h3>Recommended Reading:</h3>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("security-howto.html\">Security Considerations HOW-TO</a></h4>\r\n"); + out.write("security-howto.html\">Security Considerations HOW-TO</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("manager-howto.html\">Manager Application HOW-TO</a></h4>\r\n"); + out.write("manager-howto.html\">Manager Application HOW-TO</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("cluster-howto.html\">Clustering/Session Replication HOW-TO</a></h4>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"actions\">\r\n"); - out.write(" <div class=\"button\">\r\n"); - out.write(" <a class=\"container shadow\" href=\"/manager/status\"><span>Server Status</span></a>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"button\">\r\n"); - out.write(" <a class=\"container shadow\" href=\"/manager/html\"><span>Manager App</span></a>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"button\">\r\n"); - out.write(" <a class=\"container shadow\" href=\"/host-manager/html\"><span>Host Manager</span></a>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <!--\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" -->\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"middle\" class=\"curved container\">\r\n"); - out.write(" <h3>Developer Quick Start</h3>\r\n"); - out.write(" <div class=\"col25\">\r\n"); - out.write(" <div class=\"container\">\r\n"); + out.write("cluster-howto.html\">Clustering/Session Replication HOW-TO</a></h4>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div id=\"actions\">\n"); + out.write(" <div class=\"button\">\n"); + out.write(" <a class=\"container shadow\" href=\"/manager/status\"><span>Server Status</span></a>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"button\">\n"); + out.write(" <a class=\"container shadow\" href=\"/manager/html\"><span>Manager App</span></a>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"button\">\n"); + out.write(" <a class=\"container shadow\" href=\"/host-manager/html\"><span>Host Manager</span></a>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <!--\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" -->\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" </div>\n"); + out.write(" <div id=\"middle\" class=\"curved container\">\n"); + out.write(" <h3>Developer Quick Start</h3>\n"); + out.write(" <div class=\"col25\">\n"); + out.write(" <div class=\"container\">\n"); out.write(" <p><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("setup.html\">Tomcat Setup</a></p>\r\n"); + out.write("setup.html\">Tomcat Setup</a></p>\n"); out.write(" <p><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("appdev/\">First Web Application</a></p>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col25\">\r\n"); - out.write(" <div class=\"container\">\r\n"); + out.write("appdev/\">First Web Application</a></p>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col25\">\n"); + out.write(" <div class=\"container\">\n"); out.write(" <p><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("realm-howto.html\">Realms & AAA</a></p>\r\n"); + out.write("realm-howto.html\">Realms & AAA</a></p>\n"); out.write(" <p><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("jndi-datasource-examples-howto.html\">JDBC DataSources</a></p>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col25\">\r\n"); - out.write(" <div class=\"container\">\r\n"); + out.write("jndi-datasource-examples-howto.html\">JDBC DataSources</a></p>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col25\">\n"); + out.write(" <div class=\"container\">\n"); out.write(" <p><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatExamplesUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("\">Examples</a></p>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col25\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <p><a href=\"http://wiki.apache.org/tomcat/Specifications\">Servlet Specifications</a></p>\r\n"); - out.write(" <p><a href=\"http://wiki.apache.org/tomcat/TomcatVersions\">Tomcat Versions</a></p>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"lower\">\r\n"); - out.write(" <div id=\"low-manage\" class=\"\">\r\n"); - out.write(" <div class=\"curved container\">\r\n"); - out.write(" <h3>Managing Tomcat</h3>\r\n"); - out.write(" <p>For security, access to the <a href=\"/manager/html\">manager webapp</a> is restricted.\r\n"); - out.write(" Users are defined in:</p>\r\n"); - out.write(" <pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>\r\n"); - out.write(" <p>In Tomcat 9.0 access to the manager application is split between\r\n"); + out.write("\">Examples</a></p>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col25\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <p><a href=\"http://wiki.apache.org/tomcat/Specifications\">Servlet Specifications</a></p>\n"); + out.write(" <p><a href=\"http://wiki.apache.org/tomcat/TomcatVersions\">Tomcat Versions</a></p>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" </div>\n"); + out.write(" <div id=\"lower\">\n"); + out.write(" <div id=\"low-manage\" class=\"\">\n"); + out.write(" <div class=\"curved container\">\n"); + out.write(" <h3>Managing Tomcat</h3>\n"); + out.write(" <p>For security, access to the <a href=\"/manager/html\">manager webapp</a> is restricted.\n"); + out.write(" Users are defined in:</p>\n"); + out.write(" <pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>\n"); + out.write(" <p>In Tomcat 9.0 access to the manager application is split between\n"); out.write(" different users. <a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("manager-howto.html\">Read more...</a></p>\r\n"); - out.write(" <br />\r\n"); + out.write("manager-howto.html\">Read more...</a></p>\n"); + out.write(" <br />\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("RELEASE-NOTES.txt\">Release Notes</a></h4>\r\n"); + out.write("RELEASE-NOTES.txt\">Release Notes</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("changelog.html\">Changelog</a></h4>\r\n"); + out.write("changelog.html\">Changelog</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("migration.html\">Migration Guide</a></h4>\r\n"); + out.write("migration.html\">Migration Guide</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("security.html\">Security Notices</a></h4>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"low-docs\" class=\"\">\r\n"); - out.write(" <div class=\"curved container\">\r\n"); - out.write(" <h3>Documentation</h3>\r\n"); + out.write("security.html\">Security Notices</a></h4>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div id=\"low-docs\" class=\"\">\n"); + out.write(" <div class=\"curved container\">\n"); + out.write(" <h3>Documentation</h3>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("\">Tomcat 9.0 Documentation</a></h4>\r\n"); + out.write("\">Tomcat 9.0 Documentation</a></h4>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("config/\">Tomcat 9.0 Configuration</a></h4>\r\n"); - out.write(" <h4><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Tomcat Wiki</a></h4>\r\n"); - out.write(" <p>Find additional important configuration information in:</p>\r\n"); - out.write(" <pre>$CATALINA_HOME/RUNNING.txt</pre>\r\n"); - out.write(" <p>Developers may be interested in:</p>\r\n"); - out.write(" <ul>\r\n"); - out.write(" <li><a href=\"http://tomcat.apache.org/bugreport.html\">Tomcat 9.0 Bug Database</a></li>\r\n"); + out.write("config/\">Tomcat 9.0 Configuration</a></h4>\n"); + out.write(" <h4><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Tomcat Wiki</a></h4>\n"); + out.write(" <p>Find additional important configuration information in:</p>\n"); + out.write(" <pre>$CATALINA_HOME/RUNNING.txt</pre>\n"); + out.write(" <p>Developers may be interested in:</p>\n"); + out.write(" <ul>\n"); + out.write(" <li><a href=\"http://tomcat.apache.org/bugreport.html\">Tomcat 9.0 Bug Database</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("api/index.html\">Tomcat 9.0 JavaDocs</a></li>\r\n"); - out.write(" <li><a href=\"http://svn.apache.org/repos/asf/tomcat/tc9.0.x/\">Tomcat 9.0 SVN Repository</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"low-help\" class=\"\">\r\n"); - out.write(" <div class=\"curved container\">\r\n"); - out.write(" <h3>Getting Help</h3>\r\n"); + out.write("api/index.html\">Tomcat 9.0 JavaDocs</a></li>\n"); + out.write(" <li><a href=\"http://svn.apache.org/repos/asf/tomcat/tc9.0.x/\">Tomcat 9.0 SVN Repository</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div id=\"low-help\" class=\"\">\n"); + out.write(" <div class=\"curved container\">\n"); + out.write(" <h3>Getting Help</h3>\n"); out.write(" <h4><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); out.write("faq/\">FAQ</a> and <a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html\">Mailing Lists</a></h4>\r\n"); - out.write(" <p>The following mailing lists are available:</p>\r\n"); - out.write(" <ul>\r\n"); + out.write("lists.html\">Mailing Lists</a></h4>\n"); + out.write(" <p>The following mailing lists are available:</p>\n"); + out.write(" <ul>\n"); out.write(" <li id=\"list-announce\"><strong><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html#tomcat-announce\">tomcat-announce</a><br />\r\n"); - out.write(" Important announcements, releases, security vulnerability notifications. (Low volume).</strong>\r\n"); - out.write(" </li>\r\n"); + out.write("lists.html#tomcat-announce\">tomcat-announce</a><br />\n"); + out.write(" Important announcements, releases, security vulnerability notifications. (Low volume).</strong>\n"); + out.write(" </li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html#tomcat-users\">tomcat-users</a><br />\r\n"); - out.write(" User support and discussion\r\n"); - out.write(" </li>\r\n"); + out.write("lists.html#tomcat-users\">tomcat-users</a><br />\n"); + out.write(" User support and discussion\n"); + out.write(" </li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html#taglibs-user\">taglibs-user</a><br />\r\n"); + out.write("lists.html#taglibs-user\">taglibs-user</a><br />\n"); out.write(" User support and discussion for <a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("taglibs/\">Apache Taglibs</a>\r\n"); - out.write(" </li>\r\n"); + out.write("taglibs/\">Apache Taglibs</a>\n"); + out.write(" </li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html#tomcat-dev\">tomcat-dev</a><br />\r\n"); - out.write(" Development mailing list, including commit messages\r\n"); - out.write(" </li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" </div>\r\n"); - out.write(" <div id=\"footer\" class=\"curved container\">\r\n"); - out.write(" <div class=\"col20\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <h4>Other Downloads</h4>\r\n"); - out.write(" <ul>\r\n"); + out.write("lists.html#tomcat-dev\">tomcat-dev</a><br />\n"); + out.write(" Development mailing list, including commit messages\n"); + out.write(" </li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" </div>\n"); + out.write(" <div id=\"footer\" class=\"curved container\">\n"); + out.write(" <div class=\"col20\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <h4>Other Downloads</h4>\n"); + out.write(" <ul>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("download-connectors.cgi\">Tomcat Connectors</a></li>\r\n"); + out.write("download-connectors.cgi\">Tomcat Connectors</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("download-native.cgi\">Tomcat Native</a></li>\r\n"); + out.write("download-native.cgi\">Tomcat Native</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("taglibs/\">Taglibs</a></li>\r\n"); + out.write("taglibs/\">Taglibs</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("deployer-howto.html\">Deployer</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col20\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <h4>Other Documentation</h4>\r\n"); - out.write(" <ul>\r\n"); + out.write("deployer-howto.html\">Deployer</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col20\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <h4>Other Documentation</h4>\n"); + out.write(" <ul>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("connectors-doc/\">Tomcat Connectors</a></li>\r\n"); + out.write("connectors-doc/\">Tomcat Connectors</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("connectors-doc/\">mod_jk Documentation</a></li>\r\n"); + out.write("connectors-doc/\">mod_jk Documentation</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("native-doc/\">Tomcat Native</a></li>\r\n"); + out.write("native-doc/\">Tomcat Native</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("deployer-howto.html\">Deployer</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col20\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <h4>Get Involved</h4>\r\n"); - out.write(" <ul>\r\n"); + out.write("deployer-howto.html\">Deployer</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col20\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <h4>Get Involved</h4>\n"); + out.write(" <ul>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("getinvolved.html\">Overview</a></li>\r\n"); + out.write("getinvolved.html\">Overview</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("svn.html\">SVN Repositories</a></li>\r\n"); + out.write("svn.html\">SVN Repositories</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("lists.html\">Mailing Lists</a></li>\r\n"); - out.write(" <li><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Wiki</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col20\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <h4>Miscellaneous</h4>\r\n"); - out.write(" <ul>\r\n"); + out.write("lists.html\">Mailing Lists</a></li>\n"); + out.write(" <li><a href=\"http://wiki.apache.org/tomcat/FrontPage\">Wiki</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col20\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <h4>Miscellaneous</h4>\n"); + out.write(" <ul>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("contact.html\">Contact</a></li>\r\n"); + out.write("contact.html\">Contact</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("legal.html\">Legal</a></li>\r\n"); - out.write(" <li><a href=\"http://www.apache.org/foundation/sponsorship.html\">Sponsorship</a></li>\r\n"); - out.write(" <li><a href=\"http://www.apache.org/foundation/thanks.html\">Thanks</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <div class=\"col20\">\r\n"); - out.write(" <div class=\"container\">\r\n"); - out.write(" <h4>Apache Software Foundation</h4>\r\n"); - out.write(" <ul>\r\n"); + out.write("legal.html\">Legal</a></li>\n"); + out.write(" <li><a href=\"http://www.apache.org/foundation/sponsorship.html\">Sponsorship</a></li>\n"); + out.write(" <li><a href=\"http://www.apache.org/foundation/thanks.html\">Thanks</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <div class=\"col20\">\n"); + out.write(" <div class=\"container\">\n"); + out.write(" <h4>Apache Software Foundation</h4>\n"); + out.write(" <ul>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("whoweare.html\">Who We Are</a></li>\r\n"); + out.write("whoweare.html\">Who We Are</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("heritage.html\">Heritage</a></li>\r\n"); - out.write(" <li><a href=\"http://www.apache.org\">Apache Home</a></li>\r\n"); + out.write("heritage.html\">Heritage</a></li>\n"); + out.write(" <li><a href=\"http://www.apache.org\">Apache Home</a></li>\n"); out.write(" <li><a href=\""); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write("resources.html\">Resources</a></li>\r\n"); - out.write(" </ul>\r\n"); - out.write(" </div>\r\n"); - out.write(" </div>\r\n"); - out.write(" <br class=\"separator\" />\r\n"); - out.write(" </div>\r\n"); + out.write("resources.html\">Resources</a></li>\n"); + out.write(" </ul>\n"); + out.write(" </div>\n"); + out.write(" </div>\n"); + out.write(" <br class=\"separator\" />\n"); + out.write(" </div>\n"); out.write(" <p class=\"copyright\">Copyright ©1999-"); out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${year}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null)); - out.write(" Apache Software Foundation. All Rights Reserved</p>\r\n"); - out.write(" </div>\r\n"); - out.write(" </body>\r\n"); - out.write("\r\n"); - out.write("</html>\r\n"); + out.write(" Apache Software Foundation. All Rights Reserved</p>\n"); + out.write(" </div>\n"); + out.write(" </body>\n"); + out.write("\n"); + out.write("</html>\n"); } catch (java.lang.Throwable t) { if (!(t instanceof javax.servlet.jsp.SkipPageException)){ out = _jspx_out; diff --git a/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/index_jsp.java b/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/index_jsp.java index aab6c18a470b964a5035124d685af1c0cd268d1b..bfa0be71e488ffcd8dc0d7c37bed15464933faf9 100644 --- a/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/index_jsp.java +++ b/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/index_jsp.java @@ -1,7 +1,7 @@ /* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat/9.0.6 - * Generated at: 2018-03-22 23:33:57 UTC + * Generated at: 2018-03-27 23:07:59 UTC * Note: The last modified time of this file was set to * the last modified time of the source file after * generation to assist with modification tracking. @@ -212,7 +212,7 @@ public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase out.write(" <input type=\"radio\" name=\"gender\" value=\"female\"> Histogram\n"); out.write(" <input type=\"submit\">\n"); out.write(" </form>\n"); - out.write(" <form>\n"); + out.write(" <form method=\"POST\" action=\">\n"); out.write(" <input type=\"submit\" value=\"Individual Records\"> <!--To records.html-->\n"); out.write(" </form>\n"); out.write(" </section>\n"); diff --git a/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/result_jsp.java b/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/result_jsp.java index 6a8a4c5aaf32297ae2ab7b85b11147c8f9406383..6df0726c5606860db28aef0ab3299cb03c9e07df 100644 --- a/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/result_jsp.java +++ b/tomcat/work/Catalina/localhost/Trawl/org/apache/jsp/result_jsp.java @@ -1,7 +1,7 @@ /* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat/9.0.6 - * Generated at: 2018-03-22 23:11:01 UTC + * Generated at: 2018-03-28 02:31:35 UTC * Note: The last modified time of this file was set to * the last modified time of the source file after * generation to assist with modification tracking. @@ -11,7 +11,10 @@ package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; +import search.BasicSearchResult; import java.util.*; +import data.Record; +import model.TrawlExpert; public final class result_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent, @@ -32,7 +35,10 @@ public final class result_jsp extends org.apache.jasper.runtime.HttpJspBase _jspx_imports_packages.add("java.util"); _jspx_imports_packages.add("javax.servlet.http"); _jspx_imports_packages.add("javax.servlet.jsp"); - _jspx_imports_classes = null; + _jspx_imports_classes = new java.util.HashSet<>(); + _jspx_imports_classes.add("data.Record"); + _jspx_imports_classes.add("search.BasicSearchResult"); + _jspx_imports_classes.add("model.TrawlExpert"); } private volatile javax.el.ExpressionFactory _el_expressionfactory; @@ -115,19 +121,40 @@ public final class result_jsp extends org.apache.jasper.runtime.HttpJspBase out = pageContext.getOut(); _jspx_out = out; + out.write("\n"); out.write("\n"); out.write("<html>\n"); out.write("<body>\n"); out.write("<h1 align=\"center\">Trawl Results</h1>\n"); out.write("<p>\n"); out.write("\n"); - - Iterable<Integer> species = (Iterable<Integer>)request.getAttribute("species"); - for (Integer s: species) - out.print("SpeciesID: " + s + "<br>"); - out.print((String) request.getAttribute("url")); + out.write("<table>\n"); + out.write("<tr>\n"); + out.write("\t<th>Scientific Name</th>\n"); + out.write("\t<th>Year</th>\n"); + out.write("\t<th>Month</th>\n"); + out.write("\t<th>Day</th>\n"); + out.write("\t<th>Latitude</th>\n"); + out.write("\t<th>Longitude</th>\n"); + out.write("\t<th>Individual Count</th>\n"); + out.write("</tr>\n"); + + TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl"); + BasicSearchResult results = (BasicSearchResult) request.getAttribute("results"); + for (Record r: results.results()){ + out.print("<tr>\n"); + out.print("<th>" + te.getTaxonRecord(r.getTaxonId()).getName() + "</th>\n"); + out.print("<th>" + r.getDate().getYear() + "</th>\n"); + out.print("<th>" + r.getDate().getMonth() + "</th>\n"); + out.print("<th>" + r.getDate().getDay() + "</th>\n"); + out.print("<th>" + r.getLatitude() + "</th>\n"); + out.print("<th>" + r.getLongitude() + "</th>\n"); + out.print("<th>" + r.getCount() + "</th>\n"); + out.print("</tr>\n"); + } out.write("\n"); + out.write("</table>\n"); out.write("</body>\n"); out.write("</html>"); } catch (java.lang.Throwable t) {