io.vertx.rxjava.core.shareddata.AsyncMap Maven / Gradle / Ivy
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.vertx.rxjava.core.shareddata;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
 * An asynchronous map.
 * 
 * {@link io.vertx.rxjava.core.shareddata.AsyncMap} does not allow null to be used as a key or value.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.core.shareddata.AsyncMap original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.core.shareddata.AsyncMap.class)
public class AsyncMap {
  @Override
  public String toString() {
    return delegate.toString();
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    AsyncMap that = (AsyncMap) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new AsyncMap((io.vertx.core.shareddata.AsyncMap) obj),
    AsyncMap::getDelegate
  );
  private final io.vertx.core.shareddata.AsyncMap delegate;
  public final TypeArg __typeArg_0;
  public final TypeArg __typeArg_1;
  
  public AsyncMap(io.vertx.core.shareddata.AsyncMap delegate) {
    this.delegate = delegate;
    this.__typeArg_0 = TypeArg.unknown();    this.__typeArg_1 = TypeArg.unknown();  }
  public AsyncMap(Object delegate, TypeArg typeArg_0, TypeArg typeArg_1) {
    this.delegate = (io.vertx.core.shareddata.AsyncMap)delegate;
    this.__typeArg_0 = typeArg_0;
    this.__typeArg_1 = typeArg_1;
  }
  public io.vertx.core.shareddata.AsyncMap getDelegate() {
    return delegate;
  }
  /**
   * Get a value from the map, asynchronously.
   * @param k the key
   * @param resultHandler - this will be called some time later with the async result.
   */
  public void get(K k, io.vertx.core.Handler> resultHandler) { 
    delegate.get(__typeArg_0.unwrap(k), new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Get a value from the map, asynchronously.
   * @param k the key
   */
  public void get(K k) {
    get(k, ar -> { });
  }
    /**
   * Get a value from the map, asynchronously.
   * @param k the key
   * @return 
   */
  public rx.Single rxGet(K k) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      get(k, fut);
    }));
  }
  /**
   * Put a value in the map, asynchronously.
   * @param k the key
   * @param v the value
   * @param completionHandler - this will be called some time later to signify the value has been put
   */
  public void put(K k, V v, io.vertx.core.Handler> completionHandler) { 
    delegate.put(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), completionHandler);
  }
  /**
   * Put a value in the map, asynchronously.
   * @param k the key
   * @param v the value
   */
  public void put(K k, V v) {
    put(k, v, ar -> { });
  }
    /**
   * Put a value in the map, asynchronously.
   * @param k the key
   * @param v the value
   * @return 
   */
  public rx.Single rxPut(K k, V v) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      put(k, v, fut);
    }));
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.AsyncMap#put} but specifying a time to live for the entry. Entry will expire and get evicted after the
   * ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   * @param completionHandler the handler
   */
  public void put(K k, V v, long ttl, io.vertx.core.Handler> completionHandler) { 
    delegate.put(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), ttl, completionHandler);
  }
  /**
   * Like {@link io.vertx.rxjava.core.shareddata.AsyncMap#put} but specifying a time to live for the entry. Entry will expire and get evicted after the
   * ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   */
  public void put(K k, V v, long ttl) {
    put(k, v, ttl, ar -> { });
  }
    /**
   * Like {@link io.vertx.rxjava.core.shareddata.AsyncMap#put} but specifying a time to live for the entry. Entry will expire and get evicted after the
   * ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   * @return 
   */
  public rx.Single rxPut(K k, V v, long ttl) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      put(k, v, ttl, fut);
    }));
  }
  /**
   * Put the entry only if there is no entry with the key already present. If key already present then the existing
   * value will be returned to the handler, otherwise null.
   * @param k the key
   * @param v the value
   * @param completionHandler the handler
   */
  public void putIfAbsent(K k, V v, io.vertx.core.Handler> completionHandler) { 
    delegate.putIfAbsent(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          completionHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Put the entry only if there is no entry with the key already present. If key already present then the existing
   * value will be returned to the handler, otherwise null.
   * @param k the key
   * @param v the value
   */
  public void putIfAbsent(K k, V v) {
    putIfAbsent(k, v, ar -> { });
  }
    /**
   * Put the entry only if there is no entry with the key already present. If key already present then the existing
   * value will be returned to the handler, otherwise null.
   * @param k the key
   * @param v the value
   * @return 
   */
  public rx.Single rxPutIfAbsent(K k, V v) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      putIfAbsent(k, v, fut);
    }));
  }
  /**
   * Link {@link io.vertx.rxjava.core.shareddata.AsyncMap#putIfAbsent} but specifying a time to live for the entry. Entry will expire and get evicted
   * after the ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   * @param completionHandler the handler
   */
  public void putIfAbsent(K k, V v, long ttl, io.vertx.core.Handler> completionHandler) { 
    delegate.putIfAbsent(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), ttl, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          completionHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Link {@link io.vertx.rxjava.core.shareddata.AsyncMap#putIfAbsent} but specifying a time to live for the entry. Entry will expire and get evicted
   * after the ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   */
  public void putIfAbsent(K k, V v, long ttl) {
    putIfAbsent(k, v, ttl, ar -> { });
  }
    /**
   * Link {@link io.vertx.rxjava.core.shareddata.AsyncMap#putIfAbsent} but specifying a time to live for the entry. Entry will expire and get evicted
   * after the ttl.
   * @param k the key
   * @param v the value
   * @param ttl The time to live (in ms) for the entry
   * @return 
   */
  public rx.Single rxPutIfAbsent(K k, V v, long ttl) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      putIfAbsent(k, v, ttl, fut);
    }));
  }
  /**
   * Remove a value from the map, asynchronously.
   * @param k the key
   * @param resultHandler - this will be called some time later to signify the value has been removed
   */
  public void remove(K k, io.vertx.core.Handler> resultHandler) { 
    delegate.remove(__typeArg_0.unwrap(k), new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Remove a value from the map, asynchronously.
   * @param k the key
   */
  public void remove(K k) {
    remove(k, ar -> { });
  }
    /**
   * Remove a value from the map, asynchronously.
   * @param k the key
   * @return 
   */
  public rx.Single rxRemove(K k) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      remove(k, fut);
    }));
  }
  /**
   * Remove a value from the map, only if entry already exists with same value.
   * @param k the key
   * @param v the value
   * @param resultHandler - this will be called some time later to signify the value has been removed
   */
  public void removeIfPresent(K k, V v, io.vertx.core.Handler> resultHandler) { 
    delegate.removeIfPresent(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), resultHandler);
  }
  /**
   * Remove a value from the map, only if entry already exists with same value.
   * @param k the key
   * @param v the value
   */
  public void removeIfPresent(K k, V v) {
    removeIfPresent(k, v, ar -> { });
  }
    /**
   * Remove a value from the map, only if entry already exists with same value.
   * @param k the key
   * @param v the value
   * @return 
   */
  public rx.Single rxRemoveIfPresent(K k, V v) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      removeIfPresent(k, v, fut);
    }));
  }
  /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   * @param resultHandler the result handler will be passed the previous value
   */
  public void replace(K k, V v, io.vertx.core.Handler> resultHandler) { 
    delegate.replace(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   */
  public void replace(K k, V v) {
    replace(k, v, ar -> { });
  }
    /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   * @return 
   */
  public rx.Single rxReplace(K k, V v) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      replace(k, v, fut);
    }));
  }
  /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   * @param ttl The time to live (in ms) for the entry
   * @param resultHandler the result handler will be passed the previous value
   */
  public void replace(K k, V v, long ttl, io.vertx.core.Handler> resultHandler) { 
    delegate.replace(__typeArg_0.unwrap(k), __typeArg_1.unwrap(v), ttl, new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          resultHandler.handle(io.vertx.core.Future.succeededFuture((V)__typeArg_1.wrap(ar.result())));
        } else {
          resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
  }
  /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   * @param ttl The time to live (in ms) for the entry
   */
  public void replace(K k, V v, long ttl) {
    replace(k, v, ttl, ar -> { });
  }
    /**
   * Replace the entry only if it is currently mapped to some value
   * @param k the key
   * @param v the new value
   * @param ttl The time to live (in ms) for the entry
   * @return 
   */
  public rx.Single rxReplace(K k, V v, long ttl) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      replace(k, v, ttl, fut);
    }));
  }
  /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   * @param resultHandler the result handler
   */
  public void replaceIfPresent(K k, V oldValue, V newValue, io.vertx.core.Handler> resultHandler) { 
    delegate.replaceIfPresent(__typeArg_0.unwrap(k), __typeArg_1.unwrap(oldValue), __typeArg_1.unwrap(newValue), resultHandler);
  }
  /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   */
  public void replaceIfPresent(K k, V oldValue, V newValue) {
    replaceIfPresent(k, oldValue, newValue, ar -> { });
  }
    /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   * @return 
   */
  public rx.Single rxReplaceIfPresent(K k, V oldValue, V newValue) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      replaceIfPresent(k, oldValue, newValue, fut);
    }));
  }
  /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   * @param ttl The time to live (in ms) for the entry
   * @param resultHandler the result handler
   */
  public void replaceIfPresent(K k, V oldValue, V newValue, long ttl, io.vertx.core.Handler> resultHandler) { 
    delegate.replaceIfPresent(__typeArg_0.unwrap(k), __typeArg_1.unwrap(oldValue), __typeArg_1.unwrap(newValue), ttl, resultHandler);
  }
  /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   * @param ttl The time to live (in ms) for the entry
   */
  public void replaceIfPresent(K k, V oldValue, V newValue, long ttl) {
    replaceIfPresent(k, oldValue, newValue, ttl, ar -> { });
  }
    /**
   * Replace the entry only if it is currently mapped to a specific value
   * @param k the key
   * @param oldValue the existing value
   * @param newValue the new value
   * @param ttl The time to live (in ms) for the entry
   * @return 
   */
  public rx.Single rxReplaceIfPresent(K k, V oldValue, V newValue, long ttl) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      replaceIfPresent(k, oldValue, newValue, ttl, fut);
    }));
  }
  /**
   * Clear all entries in the map
   * @param resultHandler called on completion
   */
  public void clear(io.vertx.core.Handler> resultHandler) { 
    delegate.clear(resultHandler);
  }
  /**
   * Clear all entries in the map
   */
  public void clear() {
    clear(ar -> { });
  }
    /**
   * Clear all entries in the map
   * @return 
   */
  public rx.Single rxClear() { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      clear(fut);
    }));
  }
  /**
   * Provide the number of entries in the map
   * @param resultHandler handler which will receive the number of entries
   */
  public void size(io.vertx.core.Handler> resultHandler) { 
    delegate.size(resultHandler);
  }
  /**
   * Provide the number of entries in the map
   */
  public void size() {
    size(ar -> { });
  }
    /**
   * Provide the number of entries in the map
   * @return 
   */
  public rx.Single rxSize() { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      size(fut);
    }));
  }
  public static  AsyncMap newInstance(io.vertx.core.shareddata.AsyncMap arg) {
    return arg != null ? new AsyncMap(arg) : null;
  }
  public static  AsyncMap newInstance(io.vertx.core.shareddata.AsyncMap arg, TypeArg __typeArg_K, TypeArg __typeArg_V) {
    return arg != null ? new AsyncMap(arg, __typeArg_K, __typeArg_V) : null;
  }
}
                                                                               © 2015 - 2025 Weber Informatics LLC | Privacy Policy