Polishing.

Add documentation for generics. Fix remove() and element() methods to adhere to their contract.

See #2602
Original pull request: #2608
This commit is contained in:
Mark Paluch
2023-07-13 10:04:21 +02:00
parent a05b25abe5
commit 2e5aed4104
6 changed files with 26 additions and 17 deletions

View File

@@ -20,6 +20,7 @@ import java.util.Collection;
/**
* Redis extension for the {@link Collection} contract.
*
* @param <E> the type of elements in this collection.
* @author Costin Leau
*/
public interface RedisCollection<E> extends RedisStore {

View File

@@ -22,6 +22,7 @@ import org.springframework.lang.Nullable;
/**
* Iterator extension for Redis collection removal.
*
* @param <E> the type of elements in this collection.
* @author Costin Leau
*/
abstract class RedisIterator<E> implements Iterator<E> {
@@ -43,6 +44,7 @@ abstract class RedisIterator<E> implements Iterator<E> {
* @return
* @see java.util.Iterator#hasNext()
*/
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@@ -51,6 +53,7 @@ abstract class RedisIterator<E> implements Iterator<E> {
* @return
* @see java.util.Iterator#next()
*/
@Override
public E next() {
item = delegate.next();
return item;
@@ -59,6 +62,7 @@ abstract class RedisIterator<E> implements Iterator<E> {
/**
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
delegate.remove();
removeFromRedisStorage(item);

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.support.collections;
import static org.springframework.data.redis.connection.RedisListCommands.Direction;
import static org.springframework.data.redis.connection.RedisListCommands.*;
import java.time.Duration;
import java.util.Deque;
@@ -34,6 +34,7 @@ import org.springframework.util.Assert;
* Redis extension for the {@link List} contract. Supports {@link List}, {@link Queue} and {@link Deque} contracts as
* well as their equivalent blocking siblings {@link BlockingDeque} and {@link BlockingDeque}.
*
* @param <E> the type of elements in this collection.
* @author Costin Leau
* @author Mark Paluch
* @author John Blum

View File

@@ -24,6 +24,7 @@ import org.springframework.data.redis.core.RedisOperations;
/**
* Redis extension for the {@link Set} contract. Supports {@link Set} specific operations backed by Redis operations.
*
* @param <E> the type of elements in this collection.
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch

View File

@@ -36,6 +36,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
* <p>
* Since using a {@link Comparator} does not apply, a ZSet implements the {@link SortedSet} methods where applicable.
*
* @param <E> the type of elements in this collection.
* @author Costin Leau
* @author Mark Paluch
* @author Christoph Strobl

View File

@@ -15,18 +15,7 @@
*/
package org.springframework.data.redis.support.collections;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.IntFunction;
@@ -44,9 +33,9 @@ import org.springframework.lang.Nullable;
* Implementation and view of an existing {@link RedisList} where the elements in the list (deque) are returned in
* reverse order.
*
* @param <E> the type of elements in this collection.
* @author John Blum
* @author Mark Paluch
* @param <E> {@link Class type} of the {@link Object elements} contained in the underlying, wrapped {@link RedisList}.
* @since 3.2
*/
class ReversedRedisListView<E> implements RedisList<E> {
@@ -176,7 +165,7 @@ class ReversedRedisListView<E> implements RedisList<E> {
public boolean addAll(Collection<? extends E> collection) {
return !org.springframework.util.CollectionUtils.isEmpty(collection)
&& this.base.addAll(0, Arrays.asList(reverse((E[]) collection.toArray())));
&& this.base.addAll(0, Arrays.asList(reverse((E[]) collection.toArray())));
}
@Override
@@ -430,7 +419,13 @@ class ReversedRedisListView<E> implements RedisList<E> {
@Override
public E element() {
return peekLast();
E value = peek();
if (value == null) {
throw new NoSuchElementException();
}
return value;
}
@Override
@@ -603,7 +598,13 @@ class ReversedRedisListView<E> implements RedisList<E> {
@Override
public E remove() {
return pollLast();
E value = poll();
if (value == null) {
throw new NoSuchElementException();
}
return value;
}
@Override