Skip to content

Commit 2e5aed4

Browse files
committed
Polishing.
Add documentation for generics. Fix remove() and element() methods to adhere to their contract. See #2602 Original pull request: #2608
1 parent a05b25a commit 2e5aed4

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

src/main/java/org/springframework/data/redis/support/collections/RedisCollection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* Redis extension for the {@link Collection} contract.
2222
*
23+
* @param <E> the type of elements in this collection.
2324
* @author Costin Leau
2425
*/
2526
public interface RedisCollection<E> extends RedisStore {

src/main/java/org/springframework/data/redis/support/collections/RedisIterator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/**
2323
* Iterator extension for Redis collection removal.
2424
*
25+
* @param <E> the type of elements in this collection.
2526
* @author Costin Leau
2627
*/
2728
abstract class RedisIterator<E> implements Iterator<E> {
@@ -43,6 +44,7 @@ abstract class RedisIterator<E> implements Iterator<E> {
4344
* @return
4445
* @see java.util.Iterator#hasNext()
4546
*/
47+
@Override
4648
public boolean hasNext() {
4749
return delegate.hasNext();
4850
}
@@ -51,6 +53,7 @@ public boolean hasNext() {
5153
* @return
5254
* @see java.util.Iterator#next()
5355
*/
56+
@Override
5457
public E next() {
5558
item = delegate.next();
5659
return item;
@@ -59,6 +62,7 @@ public E next() {
5962
/**
6063
* @see java.util.Iterator#remove()
6164
*/
65+
@Override
6266
public void remove() {
6367
delegate.remove();
6468
removeFromRedisStorage(item);

src/main/java/org/springframework/data/redis/support/collections/RedisList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.support.collections;
1717

18-
import static org.springframework.data.redis.connection.RedisListCommands.Direction;
18+
import static org.springframework.data.redis.connection.RedisListCommands.*;
1919

2020
import java.time.Duration;
2121
import java.util.Deque;
@@ -34,6 +34,7 @@
3434
* Redis extension for the {@link List} contract. Supports {@link List}, {@link Queue} and {@link Deque} contracts as
3535
* well as their equivalent blocking siblings {@link BlockingDeque} and {@link BlockingDeque}.
3636
*
37+
* @param <E> the type of elements in this collection.
3738
* @author Costin Leau
3839
* @author Mark Paluch
3940
* @author John Blum

src/main/java/org/springframework/data/redis/support/collections/RedisSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* Redis extension for the {@link Set} contract. Supports {@link Set} specific operations backed by Redis operations.
2626
*
27+
* @param <E> the type of elements in this collection.
2728
* @author Costin Leau
2829
* @author Christoph Strobl
2930
* @author Mark Paluch

src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* <p>
3737
* Since using a {@link Comparator} does not apply, a ZSet implements the {@link SortedSet} methods where applicable.
3838
*
39+
* @param <E> the type of elements in this collection.
3940
* @author Costin Leau
4041
* @author Mark Paluch
4142
* @author Christoph Strobl

src/main/java/org/springframework/data/redis/support/collections/ReversedRedisListView.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.support.collections;
1717

18-
import java.util.Arrays;
19-
import java.util.Collection;
20-
import java.util.Collections;
21-
import java.util.Comparator;
22-
import java.util.Date;
23-
import java.util.Iterator;
24-
import java.util.List;
25-
import java.util.ListIterator;
26-
import java.util.NoSuchElementException;
27-
import java.util.Objects;
28-
import java.util.Spliterator;
29-
import java.util.Spliterators;
18+
import java.util.*;
3019
import java.util.concurrent.TimeUnit;
3120
import java.util.function.Consumer;
3221
import java.util.function.IntFunction;
@@ -44,9 +33,9 @@
4433
* Implementation and view of an existing {@link RedisList} where the elements in the list (deque) are returned in
4534
* reverse order.
4635
*
36+
* @param <E> the type of elements in this collection.
4737
* @author John Blum
4838
* @author Mark Paluch
49-
* @param <E> {@link Class type} of the {@link Object elements} contained in the underlying, wrapped {@link RedisList}.
5039
* @since 3.2
5140
*/
5241
class ReversedRedisListView<E> implements RedisList<E> {
@@ -176,7 +165,7 @@ public boolean add(E element) {
176165
public boolean addAll(Collection<? extends E> collection) {
177166

178167
return !org.springframework.util.CollectionUtils.isEmpty(collection)
179-
&& this.base.addAll(0, Arrays.asList(reverse((E[]) collection.toArray())));
168+
&& this.base.addAll(0, Arrays.asList(reverse((E[]) collection.toArray())));
180169
}
181170

182171
@Override
@@ -430,7 +419,13 @@ public List<E> subList(int fromIndex, int toIndex) {
430419

431420
@Override
432421
public E element() {
433-
return peekLast();
422+
423+
E value = peek();
424+
if (value == null) {
425+
throw new NoSuchElementException();
426+
}
427+
428+
return value;
434429
}
435430

436431
@Override
@@ -603,7 +598,13 @@ public int remainingCapacity() {
603598

604599
@Override
605600
public E remove() {
606-
return pollLast();
601+
602+
E value = poll();
603+
if (value == null) {
604+
throw new NoSuchElementException();
605+
}
606+
607+
return value;
607608
}
608609

609610
@Override

0 commit comments

Comments
 (0)