From e79a31ae0298dc46889ccb15cfe1553172d9c68e Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Tue, 23 Jul 2019 11:13:04 -0400 Subject: [PATCH 1/8] Basic Point Implementation --- .../java/com/cinchapi/concourse/Point.java | 34 +++++++++++++++++++ .../com/cinchapi/concourse/thrift/Type.java | 5 ++- .../com/cinchapi/concourse/util/Convert.java | 6 ++++ interface/shared.thrift | 4 ++- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java new file mode 100644 index 0000000000..8527bba84f --- /dev/null +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -0,0 +1,34 @@ +package com.cinchapi.concourse; + +import javax.annotation.concurrent.Immutable; + +@Immutable +public final class Point implements Comparable { + + private float latitude; + private float longitude; + + public Point(float latitude, float longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public static Point to(float latitude, float longitude) { + return new Point(latitude, longitude); + } + + public float getLatitude() { + return latitude; + } + + public float getLongitude() { + return longitude; + } + + @Override + public int compareTo(Point o) { + //TODO: Fix + return getLatitude() == o.getLatitude() && getLongitude() == o.getLongitude() ? 0 : 1; + } + +} diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Type.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Type.java index 97c9b29651..39dade0fa7 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Type.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Type.java @@ -28,7 +28,8 @@ public enum Type implements org.apache.thrift.TEnum { STRING(7), TAG(8), NULL(9), - TIMESTAMP(10); + TIMESTAMP(10), + POINT(11); private final int value; @@ -70,6 +71,8 @@ public static Type findByValue(int value) { return NULL; case 10: return TIMESTAMP; + case 11: + return POINT; default: return null; } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java index 24902fab8c..bf3ed355e6 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java @@ -37,6 +37,7 @@ import com.cinchapi.common.base.CheckedExceptions; import com.cinchapi.concourse.Concourse; import com.cinchapi.concourse.Link; +import com.cinchapi.concourse.Point; import com.cinchapi.concourse.Tag; import com.cinchapi.concourse.Timestamp; import com.cinchapi.concourse.annotate.PackagePrivate; @@ -246,6 +247,11 @@ else if(object instanceof Timestamp) { throw new UnsupportedOperationException( "Cannot convert string based Timestamp to a TObject"); } + }else if(object instanceof Point) { + bytes = ByteBuffer.allocate(16); + bytes.putFloat(((Point) object).getLatitude()); + bytes.putFloat(((Point) object).getLongitude()); + type = Type.POINT; } else { bytes = ByteBuffer.wrap( diff --git a/interface/shared.thrift b/interface/shared.thrift index 4eda83931f..53597846a5 100644 --- a/interface/shared.thrift +++ b/interface/shared.thrift @@ -48,7 +48,8 @@ enum Operator { BETWEEN = 9, LINKS_TO = 10, LIKE = 11, - NOT_LIKE = 12 + NOT_LIKE = 12, + WITHIN = 13 } /** @@ -65,6 +66,7 @@ enum Type { TAG = 8, NULL = 9, TIMESTAMP = 10, + POINT = 11 } /** When re-constructing the state of a record/field/index from some base state, From c81bfc8eb162f82ceb59a7f2efddbb06f6b1d20e Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Tue, 23 Jul 2019 11:17:04 -0400 Subject: [PATCH 2/8] Formatting, Added WITHIN Operator, Copyright --- .../java/com/cinchapi/concourse/Point.java | 32 ++++++++++++++----- .../cinchapi/concourse/thrift/Operator.java | 5 ++- .../com/cinchapi/concourse/util/Convert.java | 11 ++++--- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index 8527bba84f..f8572b019d 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -1,34 +1,50 @@ +/* + * Copyright (c) 2013-2019 Cinchapi Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.cinchapi.concourse; import javax.annotation.concurrent.Immutable; @Immutable public final class Point implements Comparable { - + private float latitude; private float longitude; - + public Point(float latitude, float longitude) { this.latitude = latitude; this.longitude = longitude; } - + public static Point to(float latitude, float longitude) { return new Point(latitude, longitude); } - + public float getLatitude() { return latitude; } - + public float getLongitude() { return longitude; } - + @Override public int compareTo(Point o) { - //TODO: Fix - return getLatitude() == o.getLatitude() && getLongitude() == o.getLongitude() ? 0 : 1; + // TODO: Fix + return getLatitude() == o.getLatitude() + && getLongitude() == o.getLongitude() ? 0 : 1; } } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java index baffb525f7..9ab421ea59 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java @@ -34,7 +34,8 @@ public enum Operator BETWEEN(9), LINKS_TO(10), LIKE(11), - NOT_LIKE(12); + NOT_LIKE(12), + WITHIN(13); private final int value; @@ -80,6 +81,8 @@ public static Operator findByValue(int value) { return LIKE; case 12: return NOT_LIKE; + case 13: + return WITHIN; default: return null; } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java index bf3ed355e6..0b70231b11 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java @@ -247,11 +247,12 @@ else if(object instanceof Timestamp) { throw new UnsupportedOperationException( "Cannot convert string based Timestamp to a TObject"); } - }else if(object instanceof Point) { - bytes = ByteBuffer.allocate(16); - bytes.putFloat(((Point) object).getLatitude()); - bytes.putFloat(((Point) object).getLongitude()); - type = Type.POINT; + } + else if(object instanceof Point) { + bytes = ByteBuffer.allocate(16); + bytes.putFloat(((Point) object).getLatitude()); + bytes.putFloat(((Point) object).getLongitude()); + type = Type.POINT; } else { bytes = ByteBuffer.wrap( From b13e528d7ec6834272d4ac5fed7943e482e90cac Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Tue, 23 Jul 2019 11:36:47 -0400 Subject: [PATCH 3/8] Added Point MIN, MAX Validation --- .../java/com/cinchapi/concourse/Point.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index f8572b019d..06f3e1435a 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -20,12 +20,23 @@ @Immutable public final class Point implements Comparable { + public static float MIN_LATITUDE = Float.valueOf("-90.0000"); + public static float MAX_LATITUDE = Float.valueOf("90.0000"); + public static float MIN_LONGITUDE = Float.valueOf("-180.0000"); + public static float MAX_LONGITUDE = Float.valueOf("180.0000"); + private float latitude; private float longitude; public Point(float latitude, float longitude) { - this.latitude = latitude; - this.longitude = longitude; + if(isValidLatitude(latitude) && isValidLongitude(longitude)) { + this.latitude = latitude; + this.longitude = longitude; + } + else { + throw new IllegalArgumentException( + "The specified latitude and longitude contain inproper values, please respect min, max values."); + } } public static Point to(float latitude, float longitude) { @@ -40,6 +51,14 @@ public float getLongitude() { return longitude; } + public static boolean isValidLatitude(float latitude) { + return latitude >= MIN_LATITUDE && latitude <= MAX_LATITUDE; + } + + public static boolean isValidLongitude(float longitude) { + return longitude >= MIN_LONGITUDE && longitude <= MAX_LONGITUDE; + } + @Override public int compareTo(Point o) { // TODO: Fix From 4c1b6c7c49fb473c29fb457c843e396710265cb2 Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Tue, 23 Jul 2019 12:16:45 -0400 Subject: [PATCH 4/8] Removed References to Latitude and Longitude, now X, Y --- .../java/com/cinchapi/concourse/Point.java | 58 +++++++++---------- .../com/cinchapi/concourse/util/Convert.java | 4 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index 06f3e1435a..8faf74039d 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -18,52 +18,52 @@ import javax.annotation.concurrent.Immutable; @Immutable -public final class Point implements Comparable { +public final class Point { - public static float MIN_LATITUDE = Float.valueOf("-90.0000"); - public static float MAX_LATITUDE = Float.valueOf("90.0000"); - public static float MIN_LONGITUDE = Float.valueOf("-180.0000"); - public static float MAX_LONGITUDE = Float.valueOf("180.0000"); + /** + * Valid latitude values are between -90 and 90, both inclusive. + */ + public static float MIN_Y = Float.valueOf("-90.0000"); + public static float MAX_Y = Float.valueOf("90.0000"); - private float latitude; - private float longitude; + /** + * Valid longitude values are between -180 and 180, both inclusive. + */ + public static float MIN_X = Float.valueOf("-180.0000"); + public static float MAX_X = Float.valueOf("180.0000"); - public Point(float latitude, float longitude) { - if(isValidLatitude(latitude) && isValidLongitude(longitude)) { - this.latitude = latitude; - this.longitude = longitude; + private float x; + private float y; + + public Point(float x, float y) { + if(isValidY(x) && isValidX(y)) { + this.x = x; + this.y = y; } else { throw new IllegalArgumentException( - "The specified latitude and longitude contain inproper values, please respect min, max values."); + "The specified x and y contain inproper values, please respect min, max values."); } } - public static Point to(float latitude, float longitude) { - return new Point(latitude, longitude); - } - - public float getLatitude() { - return latitude; + public static Point to(float x, float y) { + return new Point(x, y); } - public float getLongitude() { - return longitude; + public float getY() { + return y; } - public static boolean isValidLatitude(float latitude) { - return latitude >= MIN_LATITUDE && latitude <= MAX_LATITUDE; + public float getX() { + return x; } - public static boolean isValidLongitude(float longitude) { - return longitude >= MIN_LONGITUDE && longitude <= MAX_LONGITUDE; + public static boolean isValidY(float latitude) { + return latitude >= MIN_Y && latitude <= MAX_Y; } - @Override - public int compareTo(Point o) { - // TODO: Fix - return getLatitude() == o.getLatitude() - && getLongitude() == o.getLongitude() ? 0 : 1; + public static boolean isValidX(float longitude) { + return longitude >= MIN_X && longitude <= MAX_X; } } diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java index 0b70231b11..afda7e2cb1 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/util/Convert.java @@ -250,8 +250,8 @@ else if(object instanceof Timestamp) { } else if(object instanceof Point) { bytes = ByteBuffer.allocate(16); - bytes.putFloat(((Point) object).getLatitude()); - bytes.putFloat(((Point) object).getLongitude()); + bytes.putFloat(((Point) object).getX()); + bytes.putFloat(((Point) object).getY()); type = Type.POINT; } else { From c3141959c523536857184b4812e2bb6acbbe3efb Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Tue, 23 Jul 2019 12:17:39 -0400 Subject: [PATCH 5/8] Removed References to Latitude and Longitude --- .../src/main/java/com/cinchapi/concourse/Point.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index 8faf74039d..c27a3da7f0 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -58,12 +58,12 @@ public float getX() { return x; } - public static boolean isValidY(float latitude) { - return latitude >= MIN_Y && latitude <= MAX_Y; + public static boolean isValidY(float y) { + return y >= MIN_Y && y <= MAX_Y; } - public static boolean isValidX(float longitude) { - return longitude >= MIN_X && longitude <= MAX_X; + public static boolean isValidX(float x) { + return x >= MIN_X && x <= MAX_X; } } From 9630f51d4cd8748f15a74f8949d2d58a5df4a41e Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Sun, 28 Jul 2019 18:27:57 -0400 Subject: [PATCH 6/8] removed WITHIN, it's a future feature, removed PluginInspectTest as that's a different branch... --- .../main/java/com/cinchapi/concourse/thrift/Operator.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java index 9ab421ea59..baffb525f7 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/thrift/Operator.java @@ -34,8 +34,7 @@ public enum Operator BETWEEN(9), LINKS_TO(10), LIKE(11), - NOT_LIKE(12), - WITHIN(13); + NOT_LIKE(12); private final int value; @@ -81,8 +80,6 @@ public static Operator findByValue(int value) { return LIKE; case 12: return NOT_LIKE; - case 13: - return WITHIN; default: return null; } From c2679eb3d25b35a0e398723f728415cd2409ce87 Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Sun, 28 Jul 2019 18:37:21 -0400 Subject: [PATCH 7/8] renamed x() y(), removed min,max, removed WITHIN, switched floats to double --- .../java/com/cinchapi/concourse/Point.java | 36 +++---------------- interface/shared.thrift | 3 +- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index c27a3da7f0..c1cff3e60a 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -20,50 +20,24 @@ @Immutable public final class Point { - /** - * Valid latitude values are between -90 and 90, both inclusive. - */ - public static float MIN_Y = Float.valueOf("-90.0000"); - public static float MAX_Y = Float.valueOf("90.0000"); + private double x; + private double y; - /** - * Valid longitude values are between -180 and 180, both inclusive. - */ - public static float MIN_X = Float.valueOf("-180.0000"); - public static float MAX_X = Float.valueOf("180.0000"); - - private float x; - private float y; - - public Point(float x, float y) { - if(isValidY(x) && isValidX(y)) { + public Point(double x, double y) { this.x = x; this.y = y; - } - else { - throw new IllegalArgumentException( - "The specified x and y contain inproper values, please respect min, max values."); - } } public static Point to(float x, float y) { return new Point(x, y); } - public float getY() { + public double y() { return y; } - public float getX() { + public double x() { return x; } - public static boolean isValidY(float y) { - return y >= MIN_Y && y <= MAX_Y; - } - - public static boolean isValidX(float x) { - return x >= MIN_X && x <= MAX_X; - } - } diff --git a/interface/shared.thrift b/interface/shared.thrift index 53597846a5..4b6bebcde3 100644 --- a/interface/shared.thrift +++ b/interface/shared.thrift @@ -48,8 +48,7 @@ enum Operator { BETWEEN = 9, LINKS_TO = 10, LIKE = 11, - NOT_LIKE = 12, - WITHIN = 13 + NOT_LIKE = 12 } /** From 85160af5bf3132a85ec998e5c5327b14aed05243 Mon Sep 17 00:00:00 2001 From: asyncRobert Date: Sun, 28 Jul 2019 18:41:44 -0400 Subject: [PATCH 8/8] basic javadoc on Point --- .../src/main/java/com/cinchapi/concourse/Point.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java index c1cff3e60a..f29ca3f04d 100644 --- a/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java +++ b/concourse-driver-java/src/main/java/com/cinchapi/concourse/Point.java @@ -17,6 +17,12 @@ import javax.annotation.concurrent.Immutable; +/** + * A {@link Point} is a data type which harbors 2-doubles. + *

+ * A Point represents a specific location. + *

+ */ @Immutable public final class Point { @@ -24,8 +30,8 @@ public final class Point { private double y; public Point(double x, double y) { - this.x = x; - this.y = y; + this.x = x; + this.y = y; } public static Point to(float x, float y) {