diff --git a/lucene/core/src/java/org/apache/lucene/geo/SimpleWKTShapeParser.java b/lucene/core/src/java/org/apache/lucene/geo/SimpleWKTShapeParser.java index 8f5fca2fdbb6..791ed2953cb1 100644 --- a/lucene/core/src/java/org/apache/lucene/geo/SimpleWKTShapeParser.java +++ b/lucene/core/src/java/org/apache/lucene/geo/SimpleWKTShapeParser.java @@ -53,7 +53,7 @@ public static Object parse(String wkt) throws IOException, ParseException { public static Object parseExpectedType(String wkt, final ShapeType shapeType) throws IOException, ParseException { try (StringReader reader = new StringReader(wkt)) { - // setup the tokenizer; configured to read words w/o numbers + // set up the tokenizer; configured to read words w/o numbers StreamTokenizer tokenizer = new StreamTokenizer(reader); tokenizer.resetSyntax(); tokenizer.wordChars('a', 'z'); @@ -110,7 +110,7 @@ private static double[] parsePoint(StreamTokenizer stream) throws IOException, P return null; } double[] pt = new double[] {nextNumber(stream), nextNumber(stream)}; - if (isNumberNext(stream) == true) { + if (isNumberNext(stream)) { nextNumber(stream); } nextCloser(stream); @@ -195,7 +195,7 @@ private static Line[] parseMultiLine(StreamTokenizer stream) throws IOException, while (nextCloserOrComma(stream).equals(COMMA)) { lines.add(parseLine(stream)); } - return lines.toArray(new Line[lines.size()]); + return lines.toArray(new Line[0]); } /** parses the hole of a polygon */ @@ -226,7 +226,7 @@ private static Polygon parsePolygon(StreamTokenizer stream) throws IOException, return new Polygon( lats.stream().mapToDouble(i -> i).toArray(), lons.stream().mapToDouble(i -> i).toArray(), - holes.toArray(new Polygon[holes.size()])); + holes.toArray(new Polygon[0])); } return new Polygon( lats.stream().mapToDouble(i -> i).toArray(), lons.stream().mapToDouble(i -> i).toArray()); @@ -244,7 +244,7 @@ private static Polygon[] parseMultiPolygon(StreamTokenizer stream) while (nextCloserOrComma(stream).equals(COMMA)) { polygons.add(parsePolygon(stream)); } - return polygons.toArray(new Polygon[polygons.size()]); + return polygons.toArray(new Polygon[0]); } /** parses an ENVELOPE */ @@ -274,7 +274,7 @@ private static Object[] parseGeometryCollection(StreamTokenizer stream) while (nextCloserOrComma(stream).equals(COMMA)) { geometries.add(parseGeometry(stream, null)); } - return geometries.toArray(new Object[geometries.size()]); + return geometries.toArray(new Object[0]); } /** next word in the stream */ @@ -355,7 +355,7 @@ private static String nextCloser(StreamTokenizer stream) throws IOException, Par /** expects a comma as next token */ private static String nextComma(StreamTokenizer stream) throws IOException, ParseException { - if (nextWord(stream).equals(COMMA) == true) { + if (nextWord(stream).equals(COMMA)) { return COMMA; } throw new ParseException( @@ -404,7 +404,7 @@ public enum ShapeType { ENVELOPE("envelope"); // not part of the actual WKB spec private final String shapeName; - private static Map shapeTypeMap = new HashMap<>(); + private static final Map shapeTypeMap = new HashMap<>(); private static final String BBOX = "BBOX"; static { @@ -429,10 +429,9 @@ public String wktName() { public static ShapeType forName(String shapename) { String typename = shapename.toLowerCase(Locale.ROOT); - for (ShapeType type : values()) { - if (type.shapeName.equals(typename)) { - return type; - } + ShapeType type = shapeTypeMap.get(typename); + if (type != null) { + return type; } throw new IllegalArgumentException("unknown geo_shape [" + shapename + "]"); }