@@ -106,126 +106,101 @@ abstract public class LettuceConverters extends Converters {
106
106
public static final byte [] NEGATIVE_INFINITY_BYTES ;
107
107
108
108
static {
109
- DATE_TO_LONG = new Converter <Date , Long >() {
110
- public Long convert (Date source ) {
111
- return source != null ? source .getTime () : null ;
112
- }
113
- };
114
- BYTES_LIST_TO_BYTES_SET = new Converter <List <byte []>, Set <byte []>>() {
115
- public Set <byte []> convert (List <byte []> results ) {
116
- return results != null ? new LinkedHashSet <>(results ) : null ;
117
- }
118
- };
119
- BYTES_TO_STRING = new Converter <byte [], String >() {
120
109
121
- @ Override
122
- public String convert (byte [] source ) {
123
- if (source == null || Arrays .equals (source , new byte [0 ])) {
124
- return null ;
125
- }
126
- return new String (source );
110
+ DATE_TO_LONG = source -> source != null ? source .getTime () : null ;
111
+
112
+ BYTES_LIST_TO_BYTES_SET = results -> results != null ? new LinkedHashSet <>(results ) : null ;
113
+
114
+ BYTES_TO_STRING = source -> {
115
+ if (source == null || Arrays .equals (source , new byte [0 ])) {
116
+ return null ;
127
117
}
118
+ return new String (source );
128
119
};
129
- STRING_TO_BYTES = new Converter <String , byte []>() {
130
120
131
- @ Override
132
- public byte [] convert (String source ) {
133
- if (source == null ) {
134
- return null ;
135
- }
136
- return source .getBytes ();
121
+ STRING_TO_BYTES = source -> {
122
+ if (source == null ) {
123
+ return null ;
137
124
}
125
+ return source .getBytes ();
138
126
};
139
- BYTES_SET_TO_BYTES_LIST = new Converter <Set <byte []>, List <byte []>>() {
140
- public List <byte []> convert (Set <byte []> results ) {
141
- return results != null ? new ArrayList <>(results ) : null ;
127
+
128
+ BYTES_SET_TO_BYTES_LIST = results -> results != null ? new ArrayList <>(results ) : null ;
129
+
130
+ BYTES_COLLECTION_TO_BYTES_LIST = results -> {
131
+
132
+ if (results instanceof List ) {
133
+ return (List <byte []>) results ;
142
134
}
135
+ return results != null ? new ArrayList <>(results ) : null ;
143
136
};
144
- BYTES_COLLECTION_TO_BYTES_LIST = new Converter <Collection <byte []>, List <byte []>>() {
145
- public List <byte []> convert (Collection <byte []> results ) {
146
- if (results instanceof List ) {
147
- return (List <byte []>) results ;
148
- }
149
- return results != null ? new ArrayList <>(results ) : null ;
137
+
138
+ KEY_VALUE_TO_BYTES_LIST = source -> {
139
+
140
+ if (source == null ) {
141
+ return null ;
150
142
}
143
+ List <byte []> list = new ArrayList <>(2 );
144
+ list .add (source .getKey ());
145
+ list .add (source .getValue ());
146
+
147
+ return list ;
151
148
};
152
- KEY_VALUE_TO_BYTES_LIST = new Converter <KeyValue <byte [], byte []>, List <byte []>>() {
153
- public List <byte []> convert (KeyValue <byte [], byte []> source ) {
154
- if (source == null ) {
155
- return null ;
156
- }
157
- List <byte []> list = new ArrayList <>(2 );
158
- list .add (source .getKey ());
159
- list .add (source .getValue ());
160
- return list ;
149
+ BYTES_LIST_TO_MAP = source -> {
150
+
151
+ if (CollectionUtils .isEmpty (source )) {
152
+ return Collections .emptyMap ();
161
153
}
162
- };
163
- BYTES_LIST_TO_MAP = new Converter <List <byte []>, Map <byte [], byte []>>() {
164
154
165
- @ Override
166
- public Map <byte [], byte []> convert (final List <byte []> source ) {
155
+ Map <byte [], byte []> target = new LinkedHashMap <>();
167
156
168
- if (CollectionUtils .isEmpty (source )) {
169
- return Collections .emptyMap ();
170
- }
157
+ Iterator <byte []> kv = source .iterator ();
158
+ while (kv .hasNext ()) {
159
+ target .put (kv .next (), kv .hasNext () ? kv .next () : null );
160
+ }
171
161
172
- Map <byte [], byte []> target = new LinkedHashMap <>();
162
+ return target ;
163
+ };
173
164
174
- Iterator <byte []> kv = source .iterator ();
175
- while (kv .hasNext ()) {
176
- target .put (kv .next (), kv .hasNext () ? kv .next () : null );
177
- }
165
+ SCORED_VALUES_TO_TUPLE_SET = source -> {
178
166
179
- return target ;
167
+ if (source == null ) {
168
+ return null ;
180
169
}
181
- };
182
- SCORED_VALUES_TO_TUPLE_SET = new Converter <List <ScoredValue <byte []>>, Set <Tuple >>() {
183
- public Set <Tuple > convert (List <ScoredValue <byte []>> source ) {
184
- if (source == null ) {
185
- return null ;
186
- }
187
- Set <Tuple > tuples = new LinkedHashSet <>(source .size ());
188
- for (ScoredValue <byte []> value : source ) {
189
- tuples .add (LettuceConverters .toTuple (value ));
190
- }
191
- return tuples ;
170
+ Set <Tuple > tuples = new LinkedHashSet <>(source .size ());
171
+ for (ScoredValue <byte []> value : source ) {
172
+ tuples .add (LettuceConverters .toTuple (value ));
192
173
}
174
+ return tuples ;
193
175
};
194
176
195
- SCORED_VALUES_TO_TUPLE_LIST = new Converter <List <ScoredValue <byte []>>, List <Tuple >>() {
196
- public List <Tuple > convert (List <ScoredValue <byte []>> source ) {
197
- if (source == null ) {
198
- return null ;
199
- }
200
- List <Tuple > tuples = new ArrayList <>(source .size ());
201
- for (ScoredValue <byte []> value : source ) {
202
- tuples .add (LettuceConverters .toTuple (value ));
203
- }
204
- return tuples ;
177
+ SCORED_VALUES_TO_TUPLE_LIST = source -> {
178
+
179
+ if (source == null ) {
180
+ return null ;
205
181
}
206
- };
207
- SCORED_VALUE_TO_TUPLE = new Converter <ScoredValue <byte []>, Tuple >() {
208
- public Tuple convert (ScoredValue <byte []> source ) {
209
- return source != null ? new DefaultTuple (source .getValue (), Double .valueOf (source .getScore ())) : null ;
182
+ List <Tuple > tuples = new ArrayList <>(source .size ());
183
+ for (ScoredValue <byte []> value : source ) {
184
+ tuples .add (LettuceConverters .toTuple (value ));
210
185
}
186
+ return tuples ;
211
187
};
212
- BYTES_LIST_TO_TUPLE_LIST_CONVERTER = new Converter <List <byte []>, List <Tuple >>() {
213
188
214
- @ Override
215
- public List < Tuple > convert ( List < byte []> source ) {
189
+ SCORED_VALUE_TO_TUPLE = source -> source != null
190
+ ? new DefaultTuple ( source . getValue (), Double . valueOf ( source . getScore ())) : null ;
216
191
217
- if (CollectionUtils .isEmpty (source )) {
218
- return Collections .emptyList ();
219
- }
192
+ BYTES_LIST_TO_TUPLE_LIST_CONVERTER = source -> {
220
193
221
- List <Tuple > tuples = new ArrayList <>();
222
- Iterator <byte []> it = source .iterator ();
223
- while (it .hasNext ()) {
224
- tuples .add (
225
- new DefaultTuple (it .next (), it .hasNext () ? Double .valueOf (LettuceConverters .toString (it .next ())) : null ));
226
- }
227
- return tuples ;
194
+ if (CollectionUtils .isEmpty (source )) {
195
+ return Collections .emptyList ();
196
+ }
197
+
198
+ List <Tuple > tuples = new ArrayList <>();
199
+ Iterator <byte []> it = source .iterator ();
200
+ while (it .hasNext ()) {
201
+ tuples .add (new DefaultTuple (it .next (), it .hasNext () ? Double .valueOf (toString (it .next ())) : null ));
228
202
}
203
+ return tuples ;
229
204
};
230
205
231
206
PARTITIONS_TO_CLUSTER_NODES = new Converter <Partitions , List <RedisClusterNode >>() {
@@ -301,45 +276,24 @@ private Set<Flag> parseFlags(Set<NodeFlag> source) {
301
276
POSITIVE_INFINITY_BYTES = toBytes ("+inf" );
302
277
NEGATIVE_INFINITY_BYTES = toBytes ("-inf" );
303
278
304
- BYTES_LIST_TO_TIME_CONVERTER = new Converter < List < byte []>, Long >() {
279
+ BYTES_LIST_TO_TIME_CONVERTER = source -> {
305
280
306
- @ Override
307
- public Long convert (List <byte []> source ) {
281
+ Assert .notEmpty (source , "Received invalid result from server. Expected 2 items in collection." );
282
+ Assert .isTrue (source .size () == 2 ,
283
+ "Received invalid nr of arguments from redis server. Expected 2 received " + source .size ());
308
284
309
- Assert .notEmpty (source , "Received invalid result from server. Expected 2 items in collection." );
310
- Assert .isTrue (source .size () == 2 ,
311
- "Received invalid nr of arguments from redis server. Expected 2 received " + source .size ());
312
-
313
- return toTimeMillis (LettuceConverters .toString (source .get (0 )), LettuceConverters .toString (source .get (1 )));
314
- }
285
+ return toTimeMillis (toString (source .get (0 )), toString (source .get (1 )));
315
286
};
316
287
317
- GEO_COORDINATE_TO_POINT_CONVERTER = new Converter <io .lettuce .core .GeoCoordinates , Point >() {
318
- @ Override
319
- public Point convert (io .lettuce .core .GeoCoordinates geoCoordinate ) {
320
- return geoCoordinate != null ? new Point (geoCoordinate .getX ().doubleValue (), geoCoordinate .getY ().doubleValue ())
321
- : null ;
322
- }
323
- };
288
+ GEO_COORDINATE_TO_POINT_CONVERTER = geoCoordinate -> geoCoordinate != null
289
+ ? new Point (geoCoordinate .getX ().doubleValue (), geoCoordinate .getY ().doubleValue ()) : null ;
324
290
GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER = new ListConverter <>(GEO_COORDINATE_TO_POINT_CONVERTER );
325
291
326
- KEY_VALUE_UNWRAPPER = new Converter <KeyValue <Object , Object >, Object >() {
327
-
328
- @ Override
329
- public Object convert (KeyValue <Object , Object > source ) {
330
- return source .getValueOrElse (null );
331
- }
332
- };
292
+ KEY_VALUE_UNWRAPPER = source -> source .getValueOrElse (null );
333
293
334
294
KEY_VALUE_LIST_UNWRAPPER = new ListConverter <>(KEY_VALUE_UNWRAPPER );
335
295
336
- TRANSACTION_RESULT_UNWRAPPER = new Converter <TransactionResult , List <Object >>() {
337
-
338
- @ Override
339
- public List <Object > convert (TransactionResult transactionResult ) {
340
- return transactionResult .stream ().collect (Collectors .toList ());
341
- }
342
- };
296
+ TRANSACTION_RESULT_UNWRAPPER = transactionResult -> transactionResult .stream ().collect (Collectors .toList ());
343
297
}
344
298
345
299
public static List <Tuple > toTuple (List <byte []> list ) {
@@ -355,16 +309,14 @@ public static Point geoCoordinatesToPoint(GeoCoordinates geoCoordinates) {
355
309
}
356
310
357
311
public static Converter <String , List <RedisClientInfo >> stringToRedisClientListConverter () {
358
- return new Converter <String , List <RedisClientInfo >>() {
359
312
360
- @ Override
361
- public List <RedisClientInfo > convert (String source ) {
362
- if (!StringUtils .hasText (source )) {
363
- return Collections .emptyList ();
364
- }
313
+ return source -> {
365
314
366
- return STRING_TO_LIST_OF_CLIENT_INFO .convert (source .split ("\\ r?\\ n" ));
315
+ if (!StringUtils .hasText (source )) {
316
+ return Collections .emptyList ();
367
317
}
318
+
319
+ return STRING_TO_LIST_OF_CLIENT_INFO .convert (source .split ("\\ r?\\ n" ));
368
320
};
369
321
}
370
322
@@ -445,6 +397,7 @@ public static String toString(byte[] source) {
445
397
}
446
398
447
399
public static ScriptOutputType toScriptOutputType (ReturnType returnType ) {
400
+
448
401
switch (returnType ) {
449
402
case BOOLEAN :
450
403
return ScriptOutputType .BOOLEAN ;
@@ -479,6 +432,7 @@ public static Converter<List<byte[]>, Map<byte[], byte[]>> bytesListToMapConvert
479
432
}
480
433
481
434
public static SortArgs toSortArgs (SortParameters params ) {
435
+
482
436
SortArgs args = new SortArgs ();
483
437
if (params == null ) {
484
438
return args ;
@@ -650,6 +604,7 @@ public static List<RedisServer> toListOfRedisServer(List<Map<String, String>> so
650
604
* @since 1.5
651
605
*/
652
606
public static RedisURI sentinelConfigurationToRedisURI (RedisSentinelConfiguration sentinelConfiguration ) {
607
+
653
608
Assert .notNull (sentinelConfiguration , "RedisSentinelConfiguration is required" );
654
609
655
610
Set <RedisNode > sentinels = sentinelConfiguration .getSentinels ();
@@ -884,22 +839,19 @@ public static Properties toProperties(List<String> input) {
884
839
* @since 1.8
885
840
*/
886
841
public static Converter <Set <byte []>, GeoResults <GeoLocation <byte []>>> bytesSetToGeoResultsConverter () {
887
- return new Converter <Set <byte []>, GeoResults <GeoLocation <byte []>>>() {
888
842
889
- @ Override
890
- public GeoResults <GeoLocation <byte []>> convert (Set <byte []> source ) {
843
+ return source -> {
891
844
892
- if (CollectionUtils .isEmpty (source )) {
893
- return new GeoResults <>(Collections .<GeoResult <GeoLocation <byte []>>> emptyList ());
894
- }
845
+ if (CollectionUtils .isEmpty (source )) {
846
+ return new GeoResults <>(Collections .<GeoResult <GeoLocation <byte []>>> emptyList ());
847
+ }
895
848
896
- List <GeoResult <GeoLocation <byte []>>> results = new ArrayList <>(source .size ());
897
- Iterator <byte []> it = source .iterator ();
898
- while (it .hasNext ()) {
899
- results .add (new GeoResult <>(new GeoLocation <>(it .next (), null ), new Distance (0D )));
900
- }
901
- return new GeoResults <>(results );
849
+ List <GeoResult <GeoLocation <byte []>>> results = new ArrayList <>(source .size ());
850
+ Iterator <byte []> it = source .iterator ();
851
+ while (it .hasNext ()) {
852
+ results .add (new GeoResult <>(new GeoLocation <>(it .next (), null ), new Distance (0D )));
902
853
}
854
+ return new GeoResults <>(results );
903
855
};
904
856
}
905
857
0 commit comments