Feature - added addLast() and addFirst() methods to RDeque, RDequeRx and RDequeReactive objects #3797

pull/3826/head
Nikita Koksharov 3 years ago
parent fac453759e
commit 9a7eb2ea14

@ -59,6 +59,32 @@ public class RedissonDeque<V> extends RedissonQueue<V> implements RDeque<V> {
return get(addLastIfExistsAsync(elements));
}
@Override
public int addFirst(V... elements) {
return get(addFirstAsync(elements));
}
@Override
public int addLast(V... elements) {
return get(addLastAsync(elements));
}
@Override
public RFuture<Integer> addFirstAsync(V... elements) {
List<Object> args = new ArrayList<>(elements.length + 1);
args.add(getRawName());
encode(args, Arrays.asList(elements));
return commandExecutor.writeAsync(getRawName(), codec, RedisCommands.LPUSH, args.toArray());
}
@Override
public RFuture<Integer> addLastAsync(V... elements) {
List<Object> args = new ArrayList<>(elements.length + 1);
args.add(getRawName());
encode(args, Arrays.asList(elements));
return commandExecutor.writeAsync(getRawName(), codec, RedisCommands.RPUSH, args.toArray());
}
@Override
public RFuture<Integer> addFirstIfExistsAsync(V... elements) {
List<Object> args = new ArrayList<>(elements.length + 1);

@ -61,6 +61,26 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
throw new UnsupportedOperationException("use add or put method");
}
@Override
public int addFirst(V... elements) {
throw new UnsupportedOperationException("use add or put method");
}
@Override
public int addLast(V... elements) {
throw new UnsupportedOperationException("use add or put method");
}
@Override
public RFuture<Integer> addFirstAsync(V... elements) {
throw new UnsupportedOperationException("use add or put method");
}
@Override
public RFuture<Integer> addLastAsync(V... elements) {
throw new UnsupportedOperationException("use add or put method");
}
@Override
public RFuture<Integer> addFirstIfExistsAsync(V... elements) {
throw new UnsupportedOperationException("use add or put method");

@ -37,6 +37,14 @@ public interface RDeque<V> extends Deque<V>, RQueue<V>, RDequeAsync<V> {
*/
int addFirstIfExists(V... elements);
/**
* Adds elements at the head of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
int addFirst(V... elements);
/**
* Adds element at the tail of existing deque.
*
@ -45,6 +53,14 @@ public interface RDeque<V> extends Deque<V>, RQueue<V>, RDequeAsync<V> {
*/
int addLastIfExists(V... elements);
/**
* Adds elements at the tail of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
int addLast(V... elements);
/**
* Retrieves and removes the tail elements of this queue.
* Elements amount limited by <code>limit</code> param.

@ -36,6 +36,14 @@ public interface RDequeAsync<V> extends RQueueAsync<V> {
*/
RFuture<Integer> addFirstIfExistsAsync(V... elements);
/**
* Adds elements at the head of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
RFuture<Integer> addFirstAsync(V... elements);
/**
* Adds element at the tail of existing deque.
*
@ -44,6 +52,14 @@ public interface RDequeAsync<V> extends RQueueAsync<V> {
*/
RFuture<Integer> addLastIfExistsAsync(V... elements);
/**
* Adds elements at the tail of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
RFuture<Integer> addLastAsync(V... elements);
/**
* Removes last occurrence of element <code>o</code>
*

@ -44,6 +44,22 @@ public interface RDequeReactive<V> extends RQueueReactive<V> {
*/
Mono<Integer> addLastIfExists(V... elements);
/**
* Adds elements at the head of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
Mono<Integer> addFirst(V... elements);
/**
* Adds elements at the tail of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
Mono<Integer> addLast(V... elements);
Flux<V> descendingIterator();
/**

@ -46,6 +46,22 @@ public interface RDequeRx<V> extends RQueueRx<V> {
*/
Single<Integer> addLastIfExists(V... elements);
/**
* Adds elements at the head of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
Single<Integer> addFirst(V... elements);
/**
* Adds elements at the tail of deque.
*
* @param elements - elements to add
* @return length of the deque
*/
Single<Integer> addLast(V... elements);
Flowable<V> descendingIterator();
/**

@ -140,6 +140,16 @@ public class RedissonDequeTest extends BaseTest {
assertThat(queue).containsExactly(3, 2, 1);
}
@Test
public void testAddFirstLastMulti() {
RDeque<Integer> queue = redisson.getDeque("deque");
queue.addAll(Arrays.asList(1, 2, 3, 4));
queue.addFirst(0, 1, 0);
queue.addLast(10, 20, 10);
assertThat(queue).containsExactly(0, 1, 0, 1, 2, 3, 4, 10, 20, 10);
}
@Test
public void testAddFirst() {
RDeque<Integer> queue = redisson.getDeque("deque");

Loading…
Cancel
Save