Skip to content

Commit f1d8848

Browse files
DATAREDIS-1222 - Polishing.
Replace limit != null checks with limit.isUnlimited() for non nullable parameters and adapt constructor visibility to owning class level. Original Pull Request: #564
1 parent 446e58c commit f1d8848

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class JedisZSetCommands implements RedisZSetCommands {
4141

4242
private final JedisConnection connection;
4343

44-
public JedisZSetCommands(JedisConnection connection) {
44+
JedisZSetCommands(JedisConnection connection) {
4545
this.connection = connection;
4646
}
4747

@@ -254,17 +254,18 @@ public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
254254
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
255255
*/
256256
@Override
257-
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, @Nullable Limit limit) {
257+
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
258258

259259
Assert.notNull(key, "Key must not be null!");
260260
Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!");
261+
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
261262

262263
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
263264
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
264265

265266
try {
266267
if (isPipelined()) {
267-
if (limit != null) {
268+
if (!limit.isUnlimited()) {
268269
pipeline(connection.newJedisResult(connection.getRequiredPipeline().zrangeByScoreWithScores(key, min, max,
269270
limit.getOffset(), limit.getCount()), JedisConverters.tupleSetToTupleSet()));
270271
} else {
@@ -275,7 +276,7 @@ public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, @Nullable Lim
275276
}
276277

277278
if (isQueueing()) {
278-
if (limit != null) {
279+
if (!limit.isUnlimited()) {
279280
transaction(connection.newJedisResult(connection.getRequiredTransaction().zrangeByScoreWithScores(key, min,
280281
max, limit.getOffset(), limit.getCount()), JedisConverters.tupleSetToTupleSet()));
281282
} else {
@@ -286,7 +287,7 @@ public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, @Nullable Lim
286287
return null;
287288
}
288289

289-
if (limit != null) {
290+
if (!limit.isUnlimited()) {
290291
return JedisConverters.toTupleSet(
291292
connection.getJedis().zrangeByScoreWithScores(key, min, max, limit.getOffset(), limit.getCount()));
292293
}
@@ -351,17 +352,18 @@ public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
351352
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
352353
*/
353354
@Override
354-
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, @Nullable Limit limit) {
355+
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
355356

356357
Assert.notNull(key, "Key must not be null!");
357358
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
359+
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
358360

359361
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
360362
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
361363

362364
try {
363365
if (isPipelined()) {
364-
if (limit != null) {
366+
if (!limit.isUnlimited()) {
365367
pipeline(connection.newJedisResult(
366368
connection.getRequiredPipeline().zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount())));
367369
} else {
@@ -371,7 +373,7 @@ public Set<byte[]> zRevRangeByScore(byte[] key, Range range, @Nullable Limit lim
371373
}
372374

373375
if (isQueueing()) {
374-
if (limit != null) {
376+
if (!limit.isUnlimited()) {
375377
transaction(connection.newJedisResult(connection.getRequiredTransaction().zrevrangeByScore(key, max, min,
376378
limit.getOffset(), limit.getCount())));
377379
} else {
@@ -380,7 +382,7 @@ public Set<byte[]> zRevRangeByScore(byte[] key, Range range, @Nullable Limit lim
380382
return null;
381383
}
382384

383-
if (limit != null) {
385+
if (!limit.isUnlimited()) {
384386
return connection.getJedis().zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount());
385387
}
386388
return connection.getJedis().zrevrangeByScore(key, max, min);
@@ -394,17 +396,18 @@ public Set<byte[]> zRevRangeByScore(byte[] key, Range range, @Nullable Limit lim
394396
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
395397
*/
396398
@Override
397-
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, @Nullable Limit limit) {
399+
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
398400

399401
Assert.notNull(key, "Key must not be null!");
400402
Assert.notNull(range, "Range for ZREVRANGEBYSCOREWITHSCORES must not be null!");
403+
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
401404

402405
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
403406
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
404407

405408
try {
406409
if (isPipelined()) {
407-
if (limit != null) {
410+
if (!limit.isUnlimited()) {
408411
pipeline(connection.newJedisResult(connection.getRequiredPipeline().zrevrangeByScoreWithScores(key, max, min,
409412
limit.getOffset(), limit.getCount()), JedisConverters.tupleSetToTupleSet()));
410413
} else {
@@ -415,7 +418,7 @@ public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, @Nullable
415418
}
416419

417420
if (isQueueing()) {
418-
if (limit != null) {
421+
if (!limit.isUnlimited()) {
419422
transaction(connection.newJedisResult(connection.getRequiredTransaction().zrevrangeByScoreWithScores(key, max,
420423
min, limit.getOffset(), limit.getCount()), JedisConverters.tupleSetToTupleSet()));
421424
} else {
@@ -426,7 +429,7 @@ public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, @Nullable
426429
return null;
427430
}
428431

429-
if (limit != null) {
432+
if (!limit.isUnlimited()) {
430433
return JedisConverters.toTupleSet(
431434
connection.getJedis().zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), limit.getCount()));
432435
}
@@ -811,17 +814,18 @@ public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset
811814
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
812815
*/
813816
@Override
814-
public Set<byte[]> zRangeByScore(byte[] key, Range range, @Nullable Limit limit) {
817+
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
815818

816819
Assert.notNull(key, "Key must not be null!");
817820
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
821+
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
818822

819823
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
820824
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
821825

822826
try {
823827
if (isPipelined()) {
824-
if (limit != null) {
828+
if (!limit.isUnlimited()) {
825829
pipeline(connection.newJedisResult(
826830
connection.getRequiredPipeline().zrangeByScore(key, min, max, limit.getOffset(), limit.getCount())));
827831
} else {
@@ -831,7 +835,7 @@ public Set<byte[]> zRangeByScore(byte[] key, Range range, @Nullable Limit limit)
831835
}
832836

833837
if (isQueueing()) {
834-
if (limit != null) {
838+
if (!limit.isUnlimited()) {
835839
transaction(connection.newJedisResult(
836840
connection.getRequiredTransaction().zrangeByScore(key, min, max, limit.getOffset(), limit.getCount())));
837841
} else {
@@ -840,7 +844,7 @@ public Set<byte[]> zRangeByScore(byte[] key, Range range, @Nullable Limit limit)
840844
return null;
841845
}
842846

843-
if (limit != null) {
847+
if (!limit.isUnlimited()) {
844848
return connection.getJedis().zrangeByScore(key, min, max, limit.getOffset(), limit.getCount());
845849
}
846850
return connection.getJedis().zrangeByScore(key, min, max);
@@ -854,17 +858,18 @@ public Set<byte[]> zRangeByScore(byte[] key, Range range, @Nullable Limit limit)
854858
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
855859
*/
856860
@Override
857-
public Set<byte[]> zRangeByLex(byte[] key, Range range, @Nullable Limit limit) {
861+
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
858862

859863
Assert.notNull(key, "Key must not be null!");
860864
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
865+
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
861866

862867
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
863868
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
864869

865870
try {
866871
if (isPipelined()) {
867-
if (limit != null && !limit.isUnlimited()) {
872+
if (!limit.isUnlimited()) {
868873
pipeline(connection.newJedisResult(
869874
connection.getRequiredPipeline().zrangeByLex(key, min, max, limit.getOffset(), limit.getCount())));
870875
} else {
@@ -874,7 +879,7 @@ public Set<byte[]> zRangeByLex(byte[] key, Range range, @Nullable Limit limit) {
874879
}
875880

876881
if (isQueueing()) {
877-
if (limit != null && !limit.isUnlimited()) {
882+
if (!limit.isUnlimited()) {
878883
transaction(connection.newJedisResult(
879884
connection.getRequiredTransaction().zrangeByLex(key, min, max, limit.getOffset(), limit.getCount())));
880885
} else {
@@ -883,7 +888,7 @@ public Set<byte[]> zRangeByLex(byte[] key, Range range, @Nullable Limit limit) {
883888
return null;
884889
}
885890

886-
if (limit != null) {
891+
if (!limit.isUnlimited()) {
887892
return connection.getJedis().zrangeByLex(key, min, max, limit.getOffset(), limit.getCount());
888893
}
889894
return connection.getJedis().zrangeByLex(key, min, max);

0 commit comments

Comments
 (0)