Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/con 650 #389

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 {

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be more javadoc in this class. Please see other classes in the codebase for conventions on how methods, etc javadoced

* Valid latitude values are between -90 and 90, both inclusive.
*/
public static float MIN_Y = Float.valueOf("-90.0000");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there min and max values if a Point is generic as opposed to being lat/long?

public static float MAX_Y = Float.valueOf("90.0000");

/**
* 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be doubles instead of floats

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 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just name this method y()

return y;
}

public float getX() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just name this method 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,6 +71,8 @@ public static Type findByValue(int value) {
return NULL;
case 10:
return TIMESTAMP;
case 11:
return POINT;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -247,6 +248,12 @@ else if(object instanceof Timestamp) {
"Cannot convert string based Timestamp to a TObject");
}
}
else if(object instanceof Point) {
bytes = ByteBuffer.allocate(16);
bytes.putFloat(((Point) object).getX());
bytes.putFloat(((Point) object).getY());
type = Type.POINT;
}
else {
bytes = ByteBuffer.wrap(
object.toString().getBytes(StandardCharsets.UTF_8));
Expand Down
4 changes: 3 additions & 1 deletion interface/shared.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum Operator {
BETWEEN = 9,
LINKS_TO = 10,
LIKE = 11,
NOT_LIKE = 12
NOT_LIKE = 12,
WITHIN = 13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, since this PR is not tackling operators for Points

}

/**
Expand All @@ -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,
Expand Down