@@ -130,37 +130,37 @@ private static Optional<Query> queryFor(Criteria.OperationKey key, Object value,
130
130
ObjectBuilder <? extends QueryVariant > queryBuilder = null ;
131
131
132
132
switch (key ) {
133
- case WITHIN :
133
+ case WITHIN -> {
134
134
Assert .isTrue (value instanceof Object [], "Value of a geo distance filter should be an array of two values." );
135
135
queryBuilder = withinQuery (fieldName , (Object []) value );
136
- break ;
137
- case BBOX :
136
+ }
137
+ case BBOX -> {
138
138
Assert .isTrue (value instanceof Object [],
139
139
"Value of a boundedBy filter should be an array of one or two values." );
140
140
queryBuilder = boundingBoxQuery (fieldName , (Object []) value );
141
- break ;
142
- case GEO_INTERSECTS :
141
+ }
142
+ case GEO_INTERSECTS -> {
143
143
Assert .isTrue (value instanceof GeoJson <?>, "value of a GEO_INTERSECTS filter must be a GeoJson object" );
144
144
queryBuilder = geoJsonQuery (fieldName , (GeoJson <?>) value , "intersects" );
145
- break ;
146
- case GEO_IS_DISJOINT :
145
+ }
146
+ case GEO_IS_DISJOINT -> {
147
147
Assert .isTrue (value instanceof GeoJson <?>, "value of a GEO_IS_DISJOINT filter must be a GeoJson object" );
148
148
queryBuilder = geoJsonQuery (fieldName , (GeoJson <?>) value , "disjoint" );
149
- break ;
150
- case GEO_WITHIN :
149
+ }
150
+ case GEO_WITHIN -> {
151
151
Assert .isTrue (value instanceof GeoJson <?>, "value of a GEO_WITHIN filter must be a GeoJson object" );
152
152
queryBuilder = geoJsonQuery (fieldName , (GeoJson <?>) value , "within" );
153
- break ;
154
- case GEO_CONTAINS :
153
+ }
154
+ case GEO_CONTAINS -> {
155
155
Assert .isTrue (value instanceof GeoJson <?>, "value of a GEO_CONTAINS filter must be a GeoJson object" );
156
156
queryBuilder = geoJsonQuery (fieldName , (GeoJson <?>) value , "contains" );
157
- break ;
157
+ }
158
158
}
159
159
160
160
return Optional .ofNullable (queryBuilder != null ? queryBuilder .build ()._toQuery () : null );
161
161
}
162
162
163
- private static ObjectBuilder <GeoDistanceQuery > withinQuery (String fieldName , Object [] values ) {
163
+ private static ObjectBuilder <GeoDistanceQuery > withinQuery (String fieldName , Object ... values ) {
164
164
165
165
Assert .noNullElements (values , "Geo distance filter takes 2 not null elements array as parameter." );
166
166
Assert .isTrue (values .length == 2 , "Geo distance filter takes a 2-elements array as parameter." );
@@ -176,8 +176,7 @@ private static ObjectBuilder<GeoDistanceQuery> withinQuery(String fieldName, Obj
176
176
.distance (dist ) //
177
177
.distanceType (GeoDistanceType .Plane ) //
178
178
.location (location -> {
179
- if (values [0 ] instanceof GeoPoint ) {
180
- GeoPoint loc = (GeoPoint ) values [0 ];
179
+ if (values [0 ]instanceof GeoPoint loc ) {
181
180
location .latlon (latlon -> latlon .lat (loc .getLat ()).lon (loc .getLon ()));
182
181
} else if (values [0 ] instanceof Point ) {
183
182
GeoPoint loc = GeoPoint .fromPoint ((Point ) values [0 ]);
@@ -195,7 +194,7 @@ private static ObjectBuilder<GeoDistanceQuery> withinQuery(String fieldName, Obj
195
194
});
196
195
}
197
196
198
- private static ObjectBuilder <GeoBoundingBoxQuery > boundingBoxQuery (String fieldName , Object [] values ) {
197
+ private static ObjectBuilder <GeoBoundingBoxQuery > boundingBoxQuery (String fieldName , Object ... values ) {
199
198
200
199
Assert .noNullElements (values , "Geo boundedBy filter takes a not null element array as parameter." );
201
200
@@ -240,13 +239,12 @@ private static void oneParameterBBox(GeoBoundingBoxQuery.Builder queryBuilder, O
240
239
)))));
241
240
}
242
241
243
- private static void twoParameterBBox (GeoBoundingBoxQuery .Builder queryBuilder , Object [] values ) {
242
+ private static void twoParameterBBox (GeoBoundingBoxQuery .Builder queryBuilder , Object ... values ) {
244
243
245
244
Assert .isTrue (allElementsAreOfType (values , GeoPoint .class ) || allElementsAreOfType (values , String .class ),
246
245
" both elements of boundedBy filter must be type of GeoPoint or text(format lat,lon or geohash)" );
247
246
248
- if (values [0 ] instanceof GeoPoint ) {
249
- GeoPoint topLeft = (GeoPoint ) values [0 ];
247
+ if (values [0 ]instanceof GeoPoint topLeft ) {
250
248
GeoPoint bottomRight = (GeoPoint ) values [1 ];
251
249
queryBuilder .boundingBox (bb -> bb //
252
250
.tlbr (tlbr -> tlbr //
@@ -329,12 +327,8 @@ private static String extractDistanceString(Distance distance) {
329
327
StringBuilder sb = new StringBuilder ();
330
328
sb .append ((int ) distance .getValue ());
331
329
switch ((Metrics ) distance .getMetric ()) {
332
- case KILOMETERS :
333
- sb .append ("km" );
334
- break ;
335
- case MILES :
336
- sb .append ("mi" );
337
- break ;
330
+ case KILOMETERS -> sb .append ("km" );
331
+ case MILES -> sb .append ("mi" );
338
332
}
339
333
340
334
return sb .toString ();
0 commit comments