Skip to content

Commit 5116057

Browse files
committed
Polishing.
Reformat code. See #4004 Original pull request: #4006.
1 parent b5c40e7 commit 5116057

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CountQuery.java

+24-14
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
class CountQuery {
4040

41-
private Document source;
41+
private final Document source;
4242

4343
private CountQuery(Document source) {
4444
this.source = source;
@@ -101,7 +101,7 @@ private boolean requiresRewrite(Object valueToInspect) {
101101
}
102102

103103
if (valueToInspect instanceof Collection) {
104-
return requiresRewrite((Collection) valueToInspect);
104+
return requiresRewrite((Collection<?>) valueToInspect);
105105
}
106106

107107
return false;
@@ -157,6 +157,7 @@ private Collection<Object> rewriteCollection(Collection<?> source) {
157157
* @param $and potentially existing {@code $and} condition.
158158
* @return the rewritten query {@link Document}.
159159
*/
160+
@SuppressWarnings("unchecked")
160161
private static Document createGeoWithin(String key, Document source, @Nullable Object $and) {
161162

162163
boolean spheric = source.containsKey("$nearSphere");
@@ -181,7 +182,7 @@ private static Document createGeoWithin(String key, Document source, @Nullable O
181182

182183
if ($and != null) {
183184
if ($and instanceof Collection) {
184-
Collection andElements = (Collection) $and;
185+
Collection<Document> andElements = (Collection<Document>) $and;
185186
criteria = new ArrayList<>(andElements.size() + 2);
186187
criteria.addAll(andElements);
187188
} else {
@@ -195,24 +196,32 @@ private static Document createGeoWithin(String key, Document source, @Nullable O
195196

196197
criteria.add(new Document("$nor", Collections.singletonList(new Document(key, $geoWithinMin))));
197198
criteria.add(new Document(key, $geoWithinMax));
199+
198200
return new Document("$and", criteria);
199201
}
200202

201203
private static Number getMaxDistance(Document source, Object $near, boolean spheric) {
202204

203205
Number maxDistance = Double.MAX_VALUE;
204-
if(source.containsKey("$maxDistance")) { // legacy coordinate pair
205-
maxDistance = (Number) source.get("$maxDistance");
206-
} else if ($near instanceof Document) {
207-
Document nearDoc = (Document)$near;
208-
if(nearDoc.containsKey("$maxDistance")) {
206+
207+
if (source.containsKey("$maxDistance")) { // legacy coordinate pair
208+
return (Number) source.get("$maxDistance");
209+
}
210+
211+
if ($near instanceof Document) {
212+
213+
Document nearDoc = (Document) $near;
214+
215+
if (nearDoc.containsKey("$maxDistance")) {
216+
209217
maxDistance = (Number) nearDoc.get("$maxDistance");
210218
// geojson is in Meters but we need radians x/(6378.1*1000)
211-
if(spheric && nearDoc.containsKey("$geometry")) {
219+
if (spheric && nearDoc.containsKey("$geometry")) {
212220
maxDistance = MetricConversion.metersToRadians(maxDistance.doubleValue());
213221
}
214222
}
215223
}
224+
216225
return maxDistance;
217226
}
218227

@@ -239,13 +248,14 @@ private static Object toCenterCoordinates(Object value) {
239248
return Arrays.asList(((Point) value).getX(), ((Point) value).getY());
240249
}
241250

242-
if (value instanceof Document ) {
251+
if (value instanceof Document) {
243252
Document document = (Document) value;
244-
if(document.containsKey("x")) {
245-
Document point = document;
246-
return Arrays.asList(point.get("x"), point.get("y"));
253+
254+
if (document.containsKey("x")) {
255+
return Arrays.asList(document.get("x"), document.get("y"));
247256
}
248-
else if (document.containsKey("$geometry")) {
257+
258+
if (document.containsKey("$geometry")) {
249259
Document geoJsonPoint = document.get("$geometry", Document.class);
250260
return geoJsonPoint.get("coordinates");
251261
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/MetricConversion.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public static double getDistanceInMeters(Distance distance) {
6767
* Return {@code distance} in radians (on an earth like sphere).
6868
*
6969
* @param distance must not be {@literal null}.
70-
* @return distance in rads.
71-
* @since 3.4
70+
* @return distance in radians.
71+
* @since 3.4.4
7272
*/
7373
public static double toRadians(Distance distance) {
7474
return metersToRadians(getDistanceInMeters(distance));
@@ -78,8 +78,8 @@ public static double toRadians(Distance distance) {
7878
* Return {@code distance} in radians (on an earth like sphere).
7979
*
8080
* @param meters
81-
* @return distance in rads.
82-
* @since 3.4
81+
* @return distance in radians.
82+
* @since 3.4.4
8383
*/
8484
public static double metersToRadians(double meters) {
8585
return BigDecimal.valueOf(meters).divide(METERS_MULTIPLIER, MathContext.DECIMAL64).doubleValue();

0 commit comments

Comments
 (0)