Skip to content

Commit

Permalink
Adapt RedisList to API changes in java.util.List and java.util.Deque.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxblum committed Jul 6, 2023
1 parent 011af7c commit 0a96738
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import java.util.stream.StreamSupport;

import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisListCommands;
Expand Down Expand Up @@ -592,4 +593,15 @@ private void cap() {
listOps.trim(0, maxSize - 1);
}
}

@Override
public RedisList<E> reversed() {

DefaultRedisList<E> redisList = new DefaultRedisList<>(getKey(), getOperations(), this.maxSize);

StreamSupport.stream(this.spliterator(), false)
.forEach(redisList::addFirst);

return redisList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.support.collections;

import static org.springframework.data.redis.connection.RedisListCommands.*;
import static org.springframework.data.redis.connection.RedisListCommands.Direction;

import java.time.Duration;
import java.util.Deque;
Expand Down Expand Up @@ -229,4 +229,39 @@ default E moveLastTo(RedisList<E> destination, Direction destinationPosition, Du
* @see <a href="https://redis.io/commands/ltrim">Redis Documentation: LTRIM</a>
*/
RedisList<E> trim(long start, long end);

@Override
default void addFirst(E e) {
List.super.addFirst(e);
}

@Override
default void addLast(E e) {
List.super.addLast(e);
}

@Override
default E getFirst() {
return List.super.getFirst();
}

@Override
default E getLast() {
return List.super.getLast();
}

@Override
default E removeFirst() {
return List.super.removeFirst();
}

@Override
default E removeLast() {
return List.super.removeLast();
}

@Override
default RedisList<E> reversed() {
throw new UnsupportedOperationException("Not Implemented");
}
}

0 comments on commit 0a96738

Please sign in to comment.