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

Geo: Add GeoJson parser to libs/geo classes #41575

Merged
merged 6 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -102,7 +102,7 @@ public int hashCode() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Geometry {

ShapeType type();

<T> T visit(GeometryVisitor<T> visitor);
<T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E;

boolean isEmpty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@
*
* @see <a href="https://en.wikipedia.org/wiki/Visitor_pattern">Visitor Pattern</a>
*/
public interface GeometryVisitor<T> {
public interface GeometryVisitor<T, E extends Exception> {

T visit(Circle circle);
T visit(Circle circle) throws E;

T visit(GeometryCollection<?> collection);
T visit(GeometryCollection<?> collection) throws E;

T visit(Line line);
T visit(Line line) throws E;

T visit(LinearRing ring);
T visit(LinearRing ring) throws E;

T visit(MultiLine multiLine);
T visit(MultiLine multiLine) throws E;

T visit(MultiPoint multiPoint);
T visit(MultiPoint multiPoint) throws E;

T visit(MultiPolygon multiPolygon);
T visit(MultiPolygon multiPolygon) throws E;

T visit(Point point);
T visit(Point point) throws E;

T visit(Polygon polygon);
T visit(Polygon polygon) throws E;

T visit(Rectangle rectangle);
T visit(Rectangle rectangle) throws E;

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ShapeType type() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public int hashCode() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public LinearRing getHole(int i) {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public int hashCode() {
}

@Override
public <T> T visit(GeometryVisitor<T> visitor) {
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
return visitor.visit(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.geo.geometry;

import java.util.Locale;

/**
* Shape types supported by elasticsearch
*/
Expand All @@ -33,4 +35,8 @@ public enum ShapeType {
LINEARRING, // not serialized by itself in WKT or WKB
ENVELOPE, // not part of the actual WKB spec
CIRCLE; // not part of the actual WKB spec

public static ShapeType forName(String shapeName) {
return ShapeType.valueOf(shapeName.toUpperCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void toWKT(Geometry geometry, StringBuilder sb) {
if (geometry.isEmpty()) {
sb.append(EMPTY);
} else {
geometry.visit(new GeometryVisitor<Void>() {
geometry.visit(new GeometryVisitor<Void, RuntimeException>() {
@Override
public Void visit(Circle circle) {
sb.append(LPAREN);
Expand Down Expand Up @@ -543,7 +543,7 @@ private static String nextCloserOrComma(StreamTokenizer stream) throws IOExcepti
}

public static String getWKTName(Geometry geometry) {
return geometry.visit(new GeometryVisitor<String>() {
return geometry.visit(new GeometryVisitor<String, RuntimeException>() {
@Override
public String visit(Circle circle) {
return "circle";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testVisitor() {

public static void testVisitor(Geometry geom) {
AtomicBoolean called = new AtomicBoolean(false);
Object result = geom.visit(new GeometryVisitor<Object>() {
Object result = geom.visit(new GeometryVisitor<Object, RuntimeException>() {
private Object verify(Geometry geometry, String expectedClass) {
assertFalse("Visitor should be called only once", called.getAndSet(true));
assertSame(geom, geometry);
Expand Down
Loading