Skip to content

Commit 1ed587d

Browse files
authored
Move orientation enum out of ShapeBuilder (#73824)
1 parent 6466ce7 commit 1ed587d

File tree

28 files changed

+150
-134
lines changed

28 files changed

+150
-134
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import org.elasticsearch.cluster.ClusterState;
1414
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
1515
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.geo.Orientation;
1617
import org.elasticsearch.common.geo.builders.PointBuilder;
17-
import org.elasticsearch.common.geo.builders.ShapeBuilder;
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.common.xcontent.XContentFactory;
2020
import org.elasticsearch.common.xcontent.XContentType;
@@ -84,10 +84,10 @@ public void testOrientationPersistence() throws Exception {
8484
assertThat(fieldType, instanceOf(GeoShapeFieldMapper.GeoShapeFieldType.class));
8585

8686
GeoShapeFieldMapper.GeoShapeFieldType gsfm = (GeoShapeFieldMapper.GeoShapeFieldType)fieldType;
87-
ShapeBuilder.Orientation orientation = gsfm.orientation();
88-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CLOCKWISE));
89-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.LEFT));
90-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CW));
87+
Orientation orientation = gsfm.orientation();
88+
assertThat(orientation, equalTo(Orientation.CLOCKWISE));
89+
assertThat(orientation, equalTo(Orientation.LEFT));
90+
assertThat(orientation, equalTo(Orientation.CW));
9191

9292
// right orientation test
9393
indicesService = internalCluster().getInstance(IndicesService.class, findNodeName(idxName+"2"));
@@ -97,9 +97,9 @@ public void testOrientationPersistence() throws Exception {
9797

9898
gsfm = (GeoShapeFieldMapper.GeoShapeFieldType)fieldType;
9999
orientation = gsfm.orientation();
100-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.COUNTER_CLOCKWISE));
101-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.RIGHT));
102-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CCW));
100+
assertThat(orientation, equalTo(Orientation.COUNTER_CLOCKWISE));
101+
assertThat(orientation, equalTo(Orientation.RIGHT));
102+
assertThat(orientation, equalTo(Orientation.CCW));
103103
}
104104

105105
/**

server/src/internalClusterTest/java/org/elasticsearch/search/geo/LegacyGeoShapeIntegrationIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.elasticsearch.cluster.ClusterState;
1515
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
1616
import org.elasticsearch.common.Strings;
17-
import org.elasticsearch.common.geo.builders.ShapeBuilder;
17+
import org.elasticsearch.common.geo.Orientation;
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.common.xcontent.ToXContent;
2020
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -80,10 +80,10 @@ public void testOrientationPersistence() throws Exception {
8080
assertThat(fieldType, instanceOf(LegacyGeoShapeFieldMapper.GeoShapeFieldType.class));
8181

8282
LegacyGeoShapeFieldMapper.GeoShapeFieldType gsfm = (LegacyGeoShapeFieldMapper.GeoShapeFieldType)fieldType;
83-
ShapeBuilder.Orientation orientation = gsfm.orientation();
84-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CLOCKWISE));
85-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.LEFT));
86-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CW));
83+
Orientation orientation = gsfm.orientation();
84+
assertThat(orientation, equalTo(Orientation.CLOCKWISE));
85+
assertThat(orientation, equalTo(Orientation.LEFT));
86+
assertThat(orientation, equalTo(Orientation.CW));
8787

8888
// right orientation test
8989
indicesService = internalCluster().getInstance(IndicesService.class, findNodeName(idxName+"2"));
@@ -93,9 +93,9 @@ public void testOrientationPersistence() throws Exception {
9393

9494
gsfm = (LegacyGeoShapeFieldMapper.GeoShapeFieldType)fieldType;
9595
orientation = gsfm.orientation();
96-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.COUNTER_CLOCKWISE));
97-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.RIGHT));
98-
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CCW));
96+
assertThat(orientation, equalTo(Orientation.COUNTER_CLOCKWISE));
97+
assertThat(orientation, equalTo(Orientation.RIGHT));
98+
assertThat(orientation, equalTo(Orientation.CCW));
9999
}
100100

101101
/**

server/src/main/java/org/elasticsearch/common/geo/GeoShapeType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.common.geo.builders.PointBuilder;
2020
import org.elasticsearch.common.geo.builders.PolygonBuilder;
2121
import org.elasticsearch.common.geo.builders.ShapeBuilder;
22-
import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation;
2322
import org.elasticsearch.common.geo.parsers.CoordinateNode;
2423
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
2524
import org.elasticsearch.common.unit.DistanceUnit;
@@ -288,7 +287,7 @@ public static GeoShapeType forName(String geoshapename) {
288287
}
289288

290289
public abstract ShapeBuilder<?, ?, ?> getBuilder(CoordinateNode coordinates, DistanceUnit.Distance radius,
291-
ShapeBuilder.Orientation orientation, boolean coerce);
290+
Orientation orientation, boolean coerce);
292291
abstract CoordinateNode validate(CoordinateNode coordinates, boolean coerce);
293292

294293
/** wkt shape name */
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.common.geo;
10+
11+
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.elasticsearch.common.io.stream.StreamOutput;
13+
14+
import java.io.IOException;
15+
import java.util.Locale;
16+
17+
public enum Orientation {
18+
LEFT,
19+
RIGHT;
20+
21+
public static final Orientation CLOCKWISE = Orientation.LEFT;
22+
public static final Orientation COUNTER_CLOCKWISE = Orientation.RIGHT;
23+
public static final Orientation CW = Orientation.LEFT;
24+
public static final Orientation CCW = Orientation.RIGHT;
25+
26+
public void writeTo (StreamOutput out) throws IOException {
27+
out.writeBoolean(this == Orientation.RIGHT);
28+
}
29+
30+
public static Orientation readFrom (StreamInput in) throws IOException {
31+
return in.readBoolean() ? Orientation.RIGHT : Orientation.LEFT;
32+
}
33+
34+
public boolean getAsBoolean() {
35+
return this == Orientation.RIGHT;
36+
}
37+
38+
public static Orientation fromString(String orientation) {
39+
orientation = orientation.toLowerCase(Locale.ROOT);
40+
switch (orientation) {
41+
case "right":
42+
case "counterclockwise":
43+
case "ccw":
44+
return Orientation.RIGHT;
45+
case "left":
46+
case "clockwise":
47+
case "cw":
48+
return Orientation.LEFT;
49+
default:
50+
throw new IllegalArgumentException("Unknown orientation [" + orientation + "]");
51+
}
52+
}
53+
}

server/src/main/java/org/elasticsearch/common/geo/builders/MultiPolygonBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.common.geo.GeoShapeType;
1212
import org.elasticsearch.common.geo.XShapeCollection;
13+
import org.elasticsearch.common.geo.Orientation;
1314
import org.elasticsearch.common.geo.parsers.GeoWKTParser;
1415
import org.elasticsearch.common.geo.parsers.ShapeParser;
1516
import org.elasticsearch.common.io.stream.StreamInput;

server/src/main/java/org/elasticsearch/common/geo/builders/PolygonBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.core.Tuple;
1212
import org.elasticsearch.common.geo.GeoShapeType;
13+
import org.elasticsearch.common.geo.Orientation;
1314
import org.elasticsearch.common.geo.parsers.ShapeParser;
1415
import org.elasticsearch.common.io.stream.StreamInput;
1516
import org.elasticsearch.common.io.stream.StreamOutput;

server/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Collection;
3434
import java.util.Comparator;
3535
import java.util.List;
36-
import java.util.Locale;
3736
import java.util.Objects;
3837

3938
/**
@@ -430,44 +429,6 @@ public int compare(Edge o1, Edge o2) {
430429
}
431430
}
432431

433-
public enum Orientation {
434-
LEFT,
435-
RIGHT;
436-
437-
public static final Orientation CLOCKWISE = Orientation.LEFT;
438-
public static final Orientation COUNTER_CLOCKWISE = Orientation.RIGHT;
439-
public static final Orientation CW = Orientation.LEFT;
440-
public static final Orientation CCW = Orientation.RIGHT;
441-
442-
public void writeTo (StreamOutput out) throws IOException {
443-
out.writeBoolean(this == Orientation.RIGHT);
444-
}
445-
446-
public static Orientation readFrom (StreamInput in) throws IOException {
447-
return in.readBoolean() ? Orientation.RIGHT : Orientation.LEFT;
448-
}
449-
450-
public boolean getAsBoolean() {
451-
return this == Orientation.RIGHT;
452-
}
453-
454-
public static Orientation fromString(String orientation) {
455-
orientation = orientation.toLowerCase(Locale.ROOT);
456-
switch (orientation) {
457-
case "right":
458-
case "counterclockwise":
459-
case "ccw":
460-
return Orientation.RIGHT;
461-
case "left":
462-
case "clockwise":
463-
case "cw":
464-
return Orientation.LEFT;
465-
default:
466-
throw new IllegalArgumentException("Unknown orientation [" + orientation + "]");
467-
}
468-
}
469-
}
470-
471432
protected static final boolean debugEnabled() {
472433
return LOGGER.isDebugEnabled() || DEBUG;
473434
}

server/src/main/java/org/elasticsearch/common/geo/parsers/GeoJsonParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import org.elasticsearch.ElasticsearchParseException;
1111
import org.elasticsearch.common.geo.GeoPoint;
1212
import org.elasticsearch.common.geo.GeoShapeType;
13+
import org.elasticsearch.common.geo.Orientation;
1314
import org.elasticsearch.common.geo.builders.CircleBuilder;
1415
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
1516
import org.elasticsearch.common.geo.builders.ShapeBuilder;
16-
import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation;
1717
import org.elasticsearch.common.unit.DistanceUnit;
1818
import org.elasticsearch.common.xcontent.XContentParser;
1919
import org.elasticsearch.common.xcontent.XContentSubParser;
@@ -92,7 +92,7 @@ protected static ShapeBuilder parse(XContentParser parser, AbstractShapeGeometry
9292
malformedException = "cannot have [" + ShapeParser.FIELD_ORIENTATION + "] with type set to [" + shapeType + "]";
9393
}
9494
subParser.nextToken();
95-
orientation = ShapeBuilder.Orientation.fromString(subParser.text());
95+
orientation = Orientation.fromString(subParser.text());
9696
} else {
9797
subParser.nextToken();
9898
subParser.skipChildren();

server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.common.geo.builders.PointBuilder;
2121
import org.elasticsearch.common.geo.builders.PolygonBuilder;
2222
import org.elasticsearch.common.geo.builders.ShapeBuilder;
23+
import org.elasticsearch.common.geo.Orientation;
2324
import org.elasticsearch.common.logging.Loggers;
2425
import org.elasticsearch.common.xcontent.XContentParser;
2526
import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper;
@@ -245,7 +246,7 @@ private static PolygonBuilder parsePolygon(StreamTokenizer stream, final boolean
245246
return null;
246247
}
247248
PolygonBuilder builder = new PolygonBuilder(parseLinearRing(stream, ignoreZValue, coerce),
248-
ShapeBuilder.Orientation.RIGHT);
249+
Orientation.RIGHT);
249250
while (nextCloserOrComma(stream).equals(COMMA)) {
250251
builder.hole(parseLinearRing(stream, ignoreZValue, coerce));
251252
}

server/src/main/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
package org.elasticsearch.index.mapper;
99

1010
import org.elasticsearch.common.Explicit;
11-
import org.elasticsearch.common.geo.builders.ShapeBuilder;
12-
import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation;
11+
import org.elasticsearch.common.geo.Orientation;
1312
import org.elasticsearch.index.analysis.NamedAnalyzer;
1413

1514
import java.util.Collections;
@@ -29,7 +28,7 @@ public static Parameter<Explicit<Boolean>> coerceParam(Function<FieldMapper, Exp
2928
public static Parameter<Explicit<Orientation>> orientationParam(Function<FieldMapper, Explicit<Orientation>> initializer) {
3029
return new Parameter<>("orientation", true,
3130
() -> new Explicit<>(Orientation.RIGHT, false),
32-
(n, c, o) -> new Explicit<>(ShapeBuilder.Orientation.fromString(o.toString()), true),
31+
(n, c, o) -> new Explicit<>(Orientation.fromString(o.toString()), true),
3332
initializer)
3433
.setSerializer((b, f, v) -> b.field(f, v.value()), v -> v.value().toString());
3534
}

0 commit comments

Comments
 (0)