diff --git a/Proposals/.DS_Store b/Proposals/.DS_Store index f15975d6621e185c2e729fc3672df259aa712fcf..aae2b4c4fc898d3636803e688ef2162efafed52e 100644 Binary files a/Proposals/.DS_Store and b/Proposals/.DS_Store differ diff --git a/src/search/BasicSearchResult.java b/src/search/BasicSearchResult.java index c32548625c5495301b84a63c670785c47a91ca17..7ab7827e6613d738dd39eb65a6653bb2c67b2ed3 100644 --- a/src/search/BasicSearchResult.java +++ b/src/search/BasicSearchResult.java @@ -3,12 +3,23 @@ package search; import java.util.ArrayList; import data.Record; +<<<<<<< HEAD +import sort.GeneralRange; +======= +import java.lang.Math; +>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git public class BasicSearchResult { private ArrayList<Record> results; private final double time; private BST<Integer, Integer> histogram; private Integer sum; + private + + public static void main(String[] args) { + + //Graph g = new Graph(); + } public BasicSearchResult(ArrayList<Record> results, double time) { this.results = results; @@ -16,7 +27,7 @@ public class BasicSearchResult { } public Iterable<Record> results() { - return (Iterable<Record>) results; + return (Iterable<Record>) results; } public int n() { @@ -41,4 +52,27 @@ public class BasicSearchResult { } return this.sum; } + +<<<<<<< HEAD + /** + * + * @param area + */ + public Iterable<RecordCluster> cluster(double area){ + + } + + private ArrayList<GeneralRange> ranges(double lat, double lon, double area){ + ArrayList<GeneralRange>() + } +======= + private double lngRange(double dist, double lat){ + return dist/(Math.cos(lat)*222); + } + + private double latRange(double dist){ + return (dist/111)/2; + } + +>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git } diff --git a/src/search/Graph.java b/src/search/Graph.java index 093a437d93bbdb0074f1ea138e5359fb9c72e972..b7eb51de2c791c440e825f95a4290589e49ed10b 100644 --- a/src/search/Graph.java +++ b/src/search/Graph.java @@ -8,13 +8,7 @@ public class Graph { 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){ diff --git a/src/search/RedBlackTree.java b/src/search/RedBlackTree.java index 8d5728ef2d2d6a3315e9da2dabed2353e89b5002..45bfd91cb1aa30b1a4b2dbff4dead5cc6169dd8c 100644 --- a/src/search/RedBlackTree.java +++ b/src/search/RedBlackTree.java @@ -16,9 +16,22 @@ public class RedBlackTree<Key, Value> { 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++){ + + // Add first 5 nodes, expected get(6) result is null + for(int i = 0; i < 4; i++){ myTree.put(x[i]); } + assert(myTree.get((Comparable<Integer>) 6) == null); + + // Add remaining nodes, expected get(6) result is {6, 6} + for(int i = 5; i < x.length; i++){ + //System.out.println(x[i][0]); + myTree.put(x[i]); + } + + System.out.println("Root: " + myTree.root().key()); + System.out.println("myTree.get(6).key(): " + (Integer) myTree.get((Comparable<Integer>) 6).key()); + Node h = myTree.root(); System.out.println(h.key()); while (h.left() != null) { @@ -26,6 +39,11 @@ public class RedBlackTree<Key, Value> { h = h.left(); } } +<<<<<<< HEAD +======= + + +>>>>>>> 459508d... get method added to redBlackTree /** @@ -38,6 +56,41 @@ public class RedBlackTree<Key, Value> { field = fld; } + /** + * Wrapper method for retrieving the node that matches a desired key + * @param key Key pointing to the desired node + * @return A node containing who's key matches the input + */ + public Node<Key, Value> get(Comparable<Key> key) { + return get(this.root, key); + } + + /** + * Finds the node in a tree whose key matches a desired key (if the matching node exists) + * @param node Root of the subtree being searched + * @param key Desired key to be searched for in a tree + * @return The node containing the key, returns null if the key is not found + */ + private Node<Key, Value> get(Node<Key, Value> node, Comparable<Key> key) { + if (node.key() == key) + return node; + // If key is greater than current node, look right + if (this.compare.compare(node.key(), key) < 0) + if (node.right() != null) + return get(node.right(), key); + else + return null; + // If key is smaller than current node, look left + else if (this.compare.compare(node.key(), key) > 0) + if (node.left() != null) + return get(node.left(), key); + else + return null; + // If node == null, key does not exist in the tree + return null; + } + + /** * Getter method for the root of a tree * @return The root of a tree object diff --git a/src/search/RedBlackTreeTest.java b/src/search/RedBlackTreeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f319f0b759550125b7c8af45f2401a1ffcd0e9df --- /dev/null +++ b/src/search/RedBlackTreeTest.java @@ -0,0 +1,135 @@ +/** + * + */ +package search; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @author HaleyGlavina + * + */ +public class RedBlackTreeTest { + + private GeneralCompare<Integer> b1; + private Field<Integer, Integer[]> fld; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + b1 = (a1, a2) -> (Integer) a1 - (Integer) a2; + fld = (a1) -> (Integer) a1[0]; + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link search.RedBlackTree#root()}. + */ + @Test + public void testRoot() { + 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); + + // Add first 5 nodes, expected root is 2 + for(int i = 0; i < 4; i++){ + myTree.put(x[i]); + } + assert((Integer) myTree.root().key() == 2); + + // Add remaining nodes, expected root is 4 + for(int i = 5; i < x.length; i++){ + myTree.put(x[i]); + } + assert((Integer) myTree.root().key() == 4); + } + + /** + * Test method for {@link search.RedBlackTree#get(Node<Key, Value> node, Comparable<Key> key)}. + */ + @Test + public void testGet() { + 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); + + // Add first 5 nodes, expected get(6) result is null + for(int i = 0; i < 4; i++){ + myTree.put(x[i]); + } + assert(myTree.get((Comparable<Integer>) 6) == null); + + // Add remaining nodes, expected get(6) result is {6, 6} + for(int i = 5; i < x.length; i++){ + myTree.put(x[i]); + } + assert(myTree.get(6).key() == (Comparable<Integer>) 6); + + } + + /** + * Test method for {@link search.RedBlackTree#put(java.lang.Object)}. + */ + @Test + public void testPut() { + 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(); + + // Check if right-most branch of tree matches what is expected + Integer[] expect = {4, 6, 7, 8, 9}; + for (int i = 0 ; i < expect.length ; i++) { + assert(expect[i] == h.key()); + h = h.right(); + } + } + + /** + * Test method for {@link search.RedBlackTree#rotateLeft(search.Node)}. + */ + @Test + public void testRotateLeft() { + RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1); + Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}}; + myTree.put(x[0]); + myTree.put(x[1]); + assert((Integer) myTree.root().key() == 1); + + // Check if left rotation changes the root of the tree as expected + myTree.put(x[2]); + myTree.put(x[3]); + assert((Integer) myTree.root().key() == 2); + + } + + /** + * Test method for {@link search.RedBlackTree#rotateRight(search.Node)}. + */ + @Test + public void testRotateRight() { + RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1); + Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}}; + myTree.put(x[3]); + myTree.put(x[2]); + assert((Integer) myTree.root().key() == 4); + + // Check if right rotation changes the root of the tree as expected + myTree.put(x[1]); + myTree.put(x[0]); + assert((Integer) myTree.root().key() == 3); + } + +} diff --git a/tomcat/webapps/Trawl/script.js b/tomcat/webapps/Trawl/script.js index 79add29455d828bbc52b60b5bc1b63ab9532f0ba..753776d71102aac214c64d674fb4ccf14ff51303 100644 --- a/tomcat/webapps/Trawl/script.js +++ b/tomcat/webapps/Trawl/script.js @@ -33,11 +33,18 @@ function callUpdateSci(object){ function populateDropdown(childTagID, nodeList, subnode){ var x, y, content=""; - for (var i in nodeList[subnode]["taxonName"]){ - x = nodeList[subnode]["taxonId"][i]; - y = nodeList[subnode]["taxonName"][i]; - content += '"<option value="' + x + '">' + y + '</option>'; + console.log(nodeList[subnode]); + if(nodeList[subnode] != null){ + for (var i in nodeList[subnode]["taxonName"]){ + x = nodeList[subnode]["taxonId"][i]; + y = nodeList[subnode]["taxonName"][i]; + content += '"<option value="' + x + '">' + y + '</option>'; + } } + // else { + // content + // } + document.getElementById(childTagID).innerHTML = content; }