15
15
*/
16
16
package org .springframework .data .redis .repository .query ;
17
17
18
+ import java .util .Collection ;
18
19
import java .util .Iterator ;
19
20
20
21
import org .springframework .dao .InvalidDataAccessApiUsageException ;
30
31
import org .springframework .data .repository .query .parser .Part ;
31
32
import org .springframework .data .repository .query .parser .PartTree ;
32
33
import org .springframework .lang .Nullable ;
34
+ import org .springframework .util .ClassUtils ;
33
35
import org .springframework .util .CollectionUtils ;
34
36
35
37
/**
@@ -80,17 +82,15 @@ protected RedisOperationChain or(RedisOperationChain base, RedisOperationChain c
80
82
}
81
83
82
84
@ Override
83
- protected KeyValueQuery <RedisOperationChain > complete (@ Nullable final RedisOperationChain criteria , Sort sort ) {
85
+ protected KeyValueQuery <RedisOperationChain > complete (@ Nullable RedisOperationChain criteria , Sort sort ) {
84
86
85
87
KeyValueQuery <RedisOperationChain > query = new KeyValueQuery <>(criteria );
86
88
87
- if (criteria != null && !CollectionUtils .isEmpty (criteria .getSismember ())
88
- && !CollectionUtils .isEmpty (criteria .getOrSismember ()))
89
- if (criteria .getSismember ().size () == 1 && criteria .getOrSismember ().size () == 1 ) {
90
-
91
- criteria .getOrSismember ().add (criteria .getSismember ().iterator ().next ());
92
- criteria .getSismember ().clear ();
93
- }
89
+ if (criteria != null && containsExactlyOne (criteria .getSismember ())
90
+ && containsExactlyOne (criteria .getOrSismember ())) {
91
+ criteria .getOrSismember ().addAll (criteria .getSismember ());
92
+ criteria .getSismember ().clear ();
93
+ }
94
94
95
95
if (sort .isSorted ()) {
96
96
query .setSort (sort );
@@ -111,29 +111,33 @@ private NearPath getNearPath(Part part, Iterator<Object> iterator) {
111
111
if (value instanceof Point point ) {
112
112
113
113
if (!iterator .hasNext ()) {
114
- String message = "Expected to find distance value for geo query; Are you missing a parameter" ;
114
+ String message = "Expected to find distance value for geo query; Are you missing a parameter? " ;
115
115
throw new InvalidDataAccessApiUsageException (message );
116
116
}
117
117
118
118
Distance distance ;
119
119
Object distObject = iterator .next ();
120
120
121
- if (distObject instanceof Distance distanceValue ) {
122
- distance = distanceValue ;
123
- } else if (distObject instanceof Number numberValue ) {
124
- distance = new Distance (numberValue .doubleValue (), Metrics .KILOMETERS );
121
+ if (distObject instanceof Distance dist ) {
122
+ distance = dist ;
123
+ } else if (distObject instanceof Number num ) {
124
+ distance = new Distance (num .doubleValue (), Metrics .KILOMETERS );
125
125
} else {
126
126
127
127
String message = String .format ("Expected to find Distance or Numeric value for geo query but was %s" ,
128
- distObject . getClass ( ));
128
+ ClassUtils . getDescriptiveType ( distObject ));
129
129
throw new InvalidDataAccessApiUsageException (message );
130
130
}
131
131
132
132
return new NearPath (path , point , distance );
133
133
}
134
134
135
- String message = String .format ("Expected to find a Circle or Point/Distance for geo query but was %s. " ,
136
- value .getClass ());
135
+ String message = String .format ("Expected to find a Circle or Point/Distance for geo query but was %s" ,
136
+ ClassUtils . getDescriptiveType ( value .getClass () ));
137
137
throw new InvalidDataAccessApiUsageException (message );
138
138
}
139
+
140
+ private static boolean containsExactlyOne (Collection <?> collection ) {
141
+ return !CollectionUtils .isEmpty (collection ) && collection .size () == 1 ;
142
+ }
139
143
}
0 commit comments