コード例 #1
0
 @Override
 public CompletableFuture<Boolean> remove(K key, V value) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(value, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   return database
       .remove(name, keyCache.getUnchecked(key), serializer.encode(value))
       .thenApply(this::unwrapResult);
 }
コード例 #2
0
 @Override
 public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(newValue, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   byte[] existing = oldValue != null ? serializer.encode(oldValue) : null;
   return database
       .replace(name, keyCache.getUnchecked(key), existing, serializer.encode(newValue))
       .thenApply(this::unwrapResult);
 }
コード例 #3
0
 @Override
 public CompletableFuture<Versioned<V>> get(K key) {
   checkNotNull(key, ERROR_NULL_KEY);
   return database
       .get(name, keyCache.getUnchecked(key))
       .thenApply(
           v ->
               v != null
                   ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime())
                   : null);
 }
コード例 #4
0
 @Override
 public CompletableFuture<Collection<Versioned<V>>> values() {
   return database
       .values(name)
       .thenApply(
           c ->
               c.stream()
                   .map(
                       v ->
                           new Versioned<V>(
                               serializer.decode(v.value()), v.version(), v.creationTime()))
                   .collect(Collectors.toList()));
 }
コード例 #5
0
 @Override
 public CompletableFuture<Versioned<V>> put(K key, V value) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(value, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   return database
       .put(name, keyCache.getUnchecked(key), serializer.encode(value))
       .thenApply(this::unwrapResult)
       .thenApply(
           v ->
               v != null
                   ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime())
                   : null);
 }
コード例 #6
0
 @Override
 public CompletableFuture<Versioned<V>> remove(K key) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkIfUnmodifiable();
   return database
       .remove(name, keyCache.getUnchecked(key))
       .thenApply(this::unwrapResult)
       .thenApply(v -> v != null ? v.<V>map(serializer::decode) : null)
       .whenComplete(
           (r, e) -> {
             if (r != null) {
               notifyListeners(new MapEvent<>(name, MapEvent.Type.REMOVE, key, r));
             }
           });
 }
コード例 #7
0
 @Override
 public CompletableFuture<Versioned<V>> putAndGet(K key, V value) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(value, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   return database
       .putAndGet(name, keyCache.getUnchecked(key), serializer.encode(value))
       .thenApply(this::unwrapResult)
       .thenApply(
           v -> {
             Versioned<byte[]> rawNewValue = v.newValue();
             return new Versioned<>(
                 serializer.decode(rawNewValue.value()),
                 rawNewValue.version(),
                 rawNewValue.creationTime());
           });
 }
コード例 #8
0
 @Override
 public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(value, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   AtomicReference<MapEvent<K, V>> event = new AtomicReference<>();
   return database
       .putIfAbsentAndGet(name, keyCache.getUnchecked(key), serializer.encode(value))
       .thenApply(this::unwrapResult)
       .whenComplete(
           (r, e) -> {
             if (r != null && r.updated()) {
               event.set(
                   new MapEvent<K, V>(
                       name, MapEvent.Type.INSERT, key, r.newValue().<V>map(serializer::decode)));
             }
           })
       .thenApply(v -> v.updated() ? null : v.oldValue().<V>map(serializer::decode))
       .whenComplete((r, e) -> notifyListeners(event.get()));
 }
コード例 #9
0
 @Override
 public CompletableFuture<Optional<Versioned<V>>> replaceAndGet(
     K key, long oldVersion, V newValue) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkNotNull(newValue, ERROR_NULL_VALUE);
   checkIfUnmodifiable();
   return database
       .replaceAndGet(name, keyCache.getUnchecked(key), oldVersion, serializer.encode(newValue))
       .thenApply(this::unwrapResult)
       .thenApply(
           v -> {
             if (v.updated()) {
               Versioned<byte[]> rawNewValue = v.newValue();
               return Optional.of(
                   new Versioned<>(
                       serializer.decode(rawNewValue.value()),
                       rawNewValue.version(),
                       rawNewValue.creationTime()));
             } else {
               return Optional.empty();
             }
           });
 }
コード例 #10
0
 @Override
 public CompletableFuture<Boolean> remove(K key, long version) {
   checkNotNull(key, ERROR_NULL_KEY);
   checkIfUnmodifiable();
   return database.remove(name, keyCache.getUnchecked(key), version).thenApply(this::unwrapResult);
 }
コード例 #11
0
 @Override
 public CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet() {
   return database
       .entrySet(name)
       .thenApply(s -> s.stream().map(this::fromRawEntry).collect(Collectors.toSet()));
 }
コード例 #12
0
 @Override
 public CompletableFuture<Set<K>> keySet() {
   return database
       .keySet(name)
       .thenApply(s -> s.stream().map(this::dK).collect(Collectors.toSet()));
 }
コード例 #13
0
 @Override
 public CompletableFuture<Boolean> isEmpty() {
   return database.isEmpty(name);
 }
コード例 #14
0
 @Override
 public CompletableFuture<Boolean> containsValue(V value) {
   checkNotNull(value, ERROR_NULL_VALUE);
   return database.containsValue(name, serializer.encode(value));
 }
コード例 #15
0
 @Override
 public CompletableFuture<Boolean> containsKey(K key) {
   checkNotNull(key, ERROR_NULL_KEY);
   return database.containsKey(name, keyCache.getUnchecked(key));
 }
コード例 #16
0
 @Override
 public CompletableFuture<Void> clear() {
   checkIfUnmodifiable();
   return database.clear(name).thenApply(this::unwrapResult);
 }
コード例 #17
0
 @Override
 public CompletableFuture<Integer> size() {
   return database.size(name);
 }