From 12ac6314e9adb7b46d00903140636dfd06dd06bb Mon Sep 17 00:00:00 2001
From: Schankula Christopher <schankuc@mcmaster.ca>
Date: Thu, 29 Mar 2018 09:37:51 -0400
Subject: [PATCH] range search including lat / long

---
 src/search/BasicSearch.java | 18 +++++++++++++++---
 src/sort/RangeHelper.java   | 12 ++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/search/BasicSearch.java b/src/search/BasicSearch.java
index ec7894a..1a906ba 100644
--- a/src/search/BasicSearch.java
+++ b/src/search/BasicSearch.java
@@ -17,6 +17,10 @@ import sort.RangeHelper;
  *
  */
 public class BasicSearch {
+	public static BasicSearchResult range(Integer taxonId, Integer yearLo, Integer yearHi){
+		return range(taxonId, yearLo, yearHi, -90.0, 90.0, -180.0, 180.0);
+	}
+	
 	/**
 	 * Returns all records matching any of the children of the given TaxonID and in the 
 	 * date range given
@@ -25,7 +29,7 @@ public class BasicSearch {
 	 * @param yearHi The upper bound on the year range
 	 * @return
 	 */
-	public static BasicSearchResult range(Integer taxonId, Integer yearLo, Integer yearHi){
+	public static BasicSearchResult range(Integer taxonId, Integer yearLo, Integer yearHi, Double latLo, Double latHi, Double longLo, Double longHi){
 		GeneralRange<Record> a0 = RangeHelper.date(Bound.ANY);
 		
 		if ((yearLo != null) && (yearHi != null)) {
@@ -34,8 +38,16 @@ public class BasicSearch {
 			a0 = RangeHelper.date(Bound.LOWHIGH, lower, upper);
 		}
 		
-		GeneralRange<Record> a2 = r -> 0;
-		GeneralRange<Record> a3 = r -> 0;
+		GeneralRange<Record> a2 = RangeHelper.latitude(Bound.ANY);
+		GeneralRange<Record> a3 = RangeHelper.longitude(Bound.ANY);
+		
+		if ((latLo != null) && (latHi != null)) {
+			a2 = RangeHelper.latitude(Bound.LOWHIGH, latLo, latHi);
+		}
+		
+		if ((longLo != null) && (longHi != null)) {
+			a3 = RangeHelper.longitude(Bound.LOWHIGH, longLo, longHi);
+		}
 		
 		GeneralRange<Record> a1;
 		
diff --git a/src/sort/RangeHelper.java b/src/sort/RangeHelper.java
index 2a960cb..4110115 100644
--- a/src/sort/RangeHelper.java
+++ b/src/sort/RangeHelper.java
@@ -84,7 +84,7 @@ public class RangeHelper {
 	 * @param bound -Value of bound
 	 * @return -General range that matches the bound
 	 */
-	public static GeneralRange<Record> longitude(Bound boundtype, float bound) {
+	public static GeneralRange<Record> longitude(Bound boundtype, double bound) {
 		if (boundtype == Bound.LOWER) {
 			GeneralRange<Record> range = p -> p.getLongitude() < bound ? 0 : 1;
 			return range;
@@ -94,7 +94,7 @@ public class RangeHelper {
 			return range;
 		}
 		else if (boundtype == Bound.EQUALS) {
-			GeneralRange<Record> range = p -> Float.compare(p.getLongitude(), bound) ;
+			GeneralRange<Record> range = p -> Double.compare(p.getLongitude(), bound) ;
 			return range;
 		}
 		else return null;
@@ -108,7 +108,7 @@ public class RangeHelper {
 	 * @param rightbound -Value of right bound
 	 * @return -General range that matches the bound
 	 */
-	public static GeneralRange<Record> longitude(Bound boundtype, float leftbound, float rightbound) {
+	public static GeneralRange<Record> longitude(Bound boundtype, double leftbound, double rightbound) {
 		if (boundtype == Bound.LOWHIGH) {
 			GeneralRange<Record> range = p -> p.getLongitude() < leftbound ? -1 : (p.getLongitude() > rightbound ? 1 : 0);
 			return range;
@@ -138,7 +138,7 @@ public class RangeHelper {
 	 * @param bound -Value of bound
 	 * @return -General range that matches the bound
 	 */
-	public static GeneralRange<Record> latitude(Bound boundtype, float bound) {
+	public static GeneralRange<Record> latitude(Bound boundtype, double bound) {
 		if (boundtype == Bound.LOWER) {
 			GeneralRange<Record> range = p -> p.getLatitude() < bound ? 0 : 1;
 			return range;
@@ -148,7 +148,7 @@ public class RangeHelper {
 			return range;
 		}
 		else if (boundtype == Bound.EQUALS) {
-			GeneralRange<Record> range = p -> Float.compare(p.getLatitude(), bound);
+			GeneralRange<Record> range = p -> Double.compare(p.getLatitude(), bound);
 			return range;
 		}
 		else return null;
@@ -163,7 +163,7 @@ public class RangeHelper {
 	 * @param rightbound -Value of right bound
 	 * @return -General range that matches the bound
 	 */
-	public static GeneralRange<Record> latitude(Bound boundtype, int leftbound, int rightbound) {
+	public static GeneralRange<Record> latitude(Bound boundtype, double leftbound, double rightbound) {
 		if (boundtype == Bound.LOWHIGH) {
 			GeneralRange<Record> range = p -> p.getLatitude() < leftbound ? -1 : (p.getLatitude() > rightbound ? 1 : 0);
 			return range;
-- 
GitLab