From 2ba163a32ff2492eedd7fb2b8f8f075908fefbe8 Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 25 May 2018 10:22:32 +0300 Subject: [PATCH] refactoring --- .../java/org/redisson/api/RBitSetAsync.java | 1 - .../org/redisson/api/RBitSetReactive.java | 106 ++++++++++++++++++ .../reactive/RedissonSetCacheReactive.java | 7 +- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/redisson/src/main/java/org/redisson/api/RBitSetAsync.java b/redisson/src/main/java/org/redisson/api/RBitSetAsync.java index 6af40ffd6..ff4d592b5 100644 --- a/redisson/src/main/java/org/redisson/api/RBitSetAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBitSetAsync.java @@ -32,7 +32,6 @@ public interface RBitSetAsync extends RExpirableAsync { * Returns zero if there are no any set bit. * * @return "logical size" = index of highest set bit plus one - * @return void */ RFuture lengthAsync(); diff --git a/redisson/src/main/java/org/redisson/api/RBitSetReactive.java b/redisson/src/main/java/org/redisson/api/RBitSetReactive.java index b056df5a4..eac201faa 100644 --- a/redisson/src/main/java/org/redisson/api/RBitSetReactive.java +++ b/redisson/src/main/java/org/redisson/api/RBitSetReactive.java @@ -20,6 +20,7 @@ import java.util.BitSet; import org.reactivestreams.Publisher; /** + * Vector of bits that grows as needed. * * @author Nikita Koksharov * @@ -30,36 +31,141 @@ public interface RBitSetReactive extends RExpirableReactive { Publisher toByteArray(); + /** + * Returns "logical size" = index of highest set bit plus one. + * Returns zero if there are no any set bit. + * + * @return "logical size" = index of highest set bit plus one + */ Publisher length(); + /** + * Set all bits to value from fromIndex (inclusive) to toIndex (exclusive) + * + * @param fromIndex inclusive + * @param toIndex exclusive + * @param value true = 1, false = 0 + * @return void + * + */ Publisher set(long fromIndex, long toIndex, boolean value); + /** + * Set all bits to zero from fromIndex (inclusive) to toIndex (exclusive) + * + * @param fromIndex inclusive + * @param toIndex exclusive + * @return void + * + */ Publisher clear(long fromIndex, long toIndex); + /** + * Copy bits state of source BitSet object to this object + * + * @param bs - BitSet source + * @return void + */ Publisher set(BitSet bs); + /** + * Executes NOT operation over all bits + * + * @return void + */ Publisher not(); + /** + * Set all bits to one from fromIndex (inclusive) to toIndex (exclusive) + * + * @param fromIndex inclusive + * @param toIndex exclusive + * @return void + */ Publisher set(long fromIndex, long toIndex); + /** + * Returns number of set bits. + * + * @return number of set bits. + */ Publisher size(); + /** + * Returns true if bit set to one and false overwise. + * + * @param bitIndex - index of bit + * @return true if bit set to one and false overwise. + */ Publisher get(long bitIndex); + /** + * Set bit to one at specified bitIndex + * + * @param bitIndex - index of bit + * @return true - if previous value was true, + * false - if previous value was false + */ Publisher set(long bitIndex); + /** + * Set bit to value at specified bitIndex + * + * @param bitIndex - index of bit + * @param value true = 1, false = 0 + * @return true - if previous value was true, + * false - if previous value was false + */ Publisher set(long bitIndex, boolean value); + /** + * Returns the number of bits set to one. + * + * @return number of bits + */ Publisher cardinality(); + /** + * Set bit to zero at specified bitIndex + * + * @param bitIndex - index of bit + * @return true - if previous value was true, + * false - if previous value was false + */ Publisher clear(long bitIndex); + /** + * Set all bits to zero + * + * @return void + */ Publisher clear(); + /** + * Executes OR operation over this object and specified bitsets. + * Stores result into this object. + * + * @param bitSetNames - name of stored bitsets + * @return void + */ Publisher or(String... bitSetNames); + /** + * Executes AND operation over this object and specified bitsets. + * Stores result into this object. + * + * @param bitSetNames - name of stored bitsets + * @return void + */ Publisher and(String... bitSetNames); + /** + * Executes XOR operation over this object and specified bitsets. + * Stores result into this object. + * + * @param bitSetNames - name of stored bitsets + * @return void + */ Publisher xor(String... bitSetNames); } diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonSetCacheReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonSetCacheReactive.java index ff4ad7e93..5eb9d2e39 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonSetCacheReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonSetCacheReactive.java @@ -84,7 +84,12 @@ public class RedissonSetCacheReactive extends RedissonExpirableReactive imple @Override public Publisher size() { - return commandExecutor.readReactive(getName(), codec, RedisCommands.ZCARD_INT, getName()); + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.sizeAsync(); + } + }); } @Override