Skip to content

Commit

Permalink
Replace Locale.getDefault() with Local.ROOT
Browse files Browse the repository at this point in the history
Following same standard as OpenSearch

Signed-off-by: Vijayan Balasubramanian <[email protected]>
(cherry picked from commit 03ec5c9)
  • Loading branch information
VijayanB committed Feb 2, 2023
1 parent ff990a9 commit b98b5ca
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ public XYShapeIndexableFieldsVisitor(String fieldName) {

@Override
public IndexableField[] visit(Circle circle) {
throw new IllegalArgumentException(
String.format(Locale.getDefault(), "invalid shape type found [ %s ] while indexing shape", CIRCLE)
);
throw new IllegalArgumentException(String.format(Locale.ROOT, "invalid shape type found [ %s ] while indexing shape", CIRCLE));
}

@Override
public IndexableField[] visit(GeometryCollection<?> collection) {
Objects.requireNonNull(collection, String.format(Locale.getDefault(), "%s cannot be null", ShapeType.GEOMETRYCOLLECTION));
Objects.requireNonNull(collection, String.format(Locale.ROOT, "%s cannot be null", ShapeType.GEOMETRYCOLLECTION));
return visitCollection(collection);
}

Expand All @@ -65,32 +63,30 @@ public IndexableField[] visit(Line line) {

@Override
public IndexableField[] visit(LinearRing ring) {
throw new IllegalArgumentException(
String.format(Locale.getDefault(), "invalid shape type found [ %s ] while indexing shape", LINEARRING)
);
throw new IllegalArgumentException(String.format(Locale.ROOT, "invalid shape type found [ %s ] while indexing shape", LINEARRING));
}

@Override
public IndexableField[] visit(MultiLine multiLine) {
Objects.requireNonNull(multiLine, String.format(Locale.getDefault(), "%s cannot be null", ShapeType.MULTILINESTRING));
Objects.requireNonNull(multiLine, String.format(Locale.ROOT, "%s cannot be null", ShapeType.MULTILINESTRING));
return visitCollection(multiLine);
}

@Override
public IndexableField[] visit(MultiPoint multiPoint) {
Objects.requireNonNull(multiPoint, String.format(Locale.getDefault(), "%s cannot be null", ShapeType.MULTIPOINT));
Objects.requireNonNull(multiPoint, String.format(Locale.ROOT, "%s cannot be null", ShapeType.MULTIPOINT));
return visitCollection(multiPoint);
}

@Override
public IndexableField[] visit(MultiPolygon multiPolygon) {
Objects.requireNonNull(multiPolygon, String.format(Locale.getDefault(), "%s cannot be null", ShapeType.MULTIPOLYGON));
Objects.requireNonNull(multiPolygon, String.format(Locale.ROOT, "%s cannot be null", ShapeType.MULTIPOLYGON));
return visitCollection(multiPolygon);
}

@Override
public IndexableField[] visit(Point point) {
Objects.requireNonNull(point, String.format(Locale.getDefault(), "%s cannot be null", ShapeType.POINT));
Objects.requireNonNull(point, String.format(Locale.ROOT, "%s cannot be null", ShapeType.POINT));
XYPoint xyPoint = toXYPoint(point);
return XYShape.createIndexableFields(fieldName, xyPoint.getX(), xyPoint.getY());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class XYShapeSupportVisitor implements GeometryVisitor<Geometry, RuntimeException> {
@Override
public Geometry visit(Circle circle) {
throw new UnsupportedOperationException(String.format(Locale.getDefault(), "%s is not supported", CIRCLE));
throw new UnsupportedOperationException(String.format(Locale.ROOT, "%s is not supported", CIRCLE));
}

@Override
Expand All @@ -45,7 +45,7 @@ public Geometry visit(Line line) {

@Override
public Geometry visit(LinearRing ring) {
throw new UnsupportedOperationException(String.format(Locale.getDefault(), "cannot index %s [ %s ] directly", LINEARRING, ring));
throw new UnsupportedOperationException(String.format(Locale.ROOT, "cannot index %s [ %s ] directly", LINEARRING, ring));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private Query visitCollection(GeometryCollection<Polygon> collection) {
private Query geometryNotSupported(ShapeType shapeType) {
throw new QueryShardException(
context,
String.format(Locale.getDefault(), "Field [%s] found an unsupported shape [%s]", fieldName, shapeType.name())
String.format(Locale.ROOT, "Field [%s] found an unsupported shape [%s]", fieldName, shapeType.name())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ protected Query buildShapeQuery(QueryShardContext context, MappedFieldType field
}
throw new QueryShardException(
context,
String.format(
Locale.getDefault(),
"Field [%s] is of unsupported type [%s] for [%s] query",
fieldName,
fieldType.typeName(),
NAME
)
String.format(Locale.ROOT, "Field [%s] is of unsupported type [%s] for [%s] query", fieldName, fieldType.typeName(), NAME)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void validateIsXYShapeFieldType(String fieldName, QueryShardContext cont
throw new QueryShardException(
context,
String.format(
Locale.getDefault(),
Locale.ROOT,
"Expected %s field type for Field [ %s ] but found %s",
XYShapeFieldMapper.CONTENT_TYPE,
fieldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<XYGeometry> visit(Line line) throws RuntimeException {
public List<XYGeometry> visit(LinearRing linearRing) throws RuntimeException {
throw new QueryShardException(
this.context,
String.format(Locale.getDefault(), "Field [%s] found an unsupported shape LinearRing", this.name)
String.format(Locale.ROOT, "Field [%s] found an unsupported shape LinearRing", this.name)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ public class GeoHexHelper {
public static void checkPrecisionRange(int precision) {
if ((precision < MIN_H3_RES) || (precision > MAX_H3_RES)) {
throw new IllegalArgumentException(
String.format(
Locale.getDefault(),
"Invalid precision of %d . Must be between %d and %d.",
precision,
MIN_H3_RES,
MAX_H3_RES
)
String.format(Locale.ROOT, "Invalid precision of %d . Must be between %d and %d.", precision, MIN_H3_RES, MAX_H3_RES)
);
}
}
Expand All @@ -48,7 +42,7 @@ public static void checkPrecisionRange(int precision) {
*/
public static GeoPoint h3ToGeoPoint(long h3CellID) {
if (h3IsValid(h3CellID) == false) {
throw new IllegalArgumentException(String.format(Locale.getDefault(), "Invalid H3 Cell address: %d", h3CellID));
throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid H3 Cell address: %d", h3CellID));
}
final var position = h3ToLatLng(h3CellID);
return new GeoPoint(position.getLatDeg(), position.getLonDeg());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum FIELDS {

@Override
public String toString() {
return name().toLowerCase(Locale.getDefault());
return name().toLowerCase(Locale.ROOT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum FIELDS {

@Override
public String toString() {
return this.name().toLowerCase(Locale.getDefault());
return this.name().toLowerCase(Locale.ROOT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum FIELDS {

@Override
public String toString() {
return name().toLowerCase(Locale.getDefault());
return name().toLowerCase(Locale.ROOT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static String randomString() {
}

public static String randomLowerCaseString() {
return randomString().toLowerCase(Locale.getDefault());
return randomString().toLowerCase(Locale.ROOT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
Strings.toString(
PutMappingRequest.simpleMapping(
XY_SHAPE_FIELD_NAME,
String.format(Locale.getDefault(), "%s=%s", MAPPING_FIELD_TYPE_KEY, XYShapeQueryBuilder.NAME)
String.format(Locale.ROOT, "%s=%s", MAPPING_FIELD_TYPE_KEY, XYShapeQueryBuilder.NAME)
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testParseErrorOnPrecisionOutOfRange() throws Exception {
MatcherAssert.assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
assertEquals(
String.format(
Locale.getDefault(),
Locale.ROOT,
"Invalid precision of %d . Must be between %d and %d.",
invalidPrecision,
H3.MIN_H3_RES,
Expand All @@ -116,7 +116,7 @@ public void testParseValidBounds() throws Exception {
XContentParser stParser = createParser(
JsonXContent.jsonXContent,
String.format(
Locale.getDefault(),
Locale.ROOT,
"{\"field\":\"my_loc\", \"precision\": 5, \"size\": 500, \"shard_size\": 550,\"bounds\": { \"top\": %s,\"bottom\": %s,\"left\": %s,\"right\": %s}}",
bbox.getMaxY(),
bbox.getMinY(),
Expand All @@ -132,7 +132,7 @@ public void testParseValidBounds() throws Exception {

private String buildAggregation(String fieldName, int precision, int size, int shardSize) {
return String.format(
Locale.getDefault(),
Locale.ROOT,
"{\"field\":\"%s\", \"precision\":%d, \"size\": %d, \"shard_size\": %d}",
fieldName,
precision,
Expand Down

0 comments on commit b98b5ca

Please sign in to comment.