
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, 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
* @return
* @deprecated use {@link #rxGet} instead
*/
@Deprecated()
public Observable getObservable(K k) {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
get(k, resultHandler.toHandler());
return resultHandler;
}
/**
* Get a value from the map, asynchronously.
* @param k the key
* @return
*/
public Single rxGet(K k) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxPut} instead
*/
@Deprecated()
public Observable putObservable(K k, V v) {
io.vertx.rx.java.ObservableFuture completionHandler = io.vertx.rx.java.RxHelper.observableFuture();
put(k, v, completionHandler.toHandler());
return completionHandler;
}
/**
* Put a value in the map, asynchronously.
* @param k the key
* @param v the value
* @return
*/
public Single rxPut(K k, V v) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxPut} instead
*/
@Deprecated()
public Observable putObservable(K k, V v, long ttl) {
io.vertx.rx.java.ObservableFuture completionHandler = io.vertx.rx.java.RxHelper.observableFuture();
put(k, v, ttl, completionHandler.toHandler());
return 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
* @return
*/
public Single rxPut(K k, V v, long ttl) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxPutIfAbsent} instead
*/
@Deprecated()
public Observable putIfAbsentObservable(K k, V v) {
io.vertx.rx.java.ObservableFuture completionHandler = io.vertx.rx.java.RxHelper.observableFuture();
putIfAbsent(k, v, completionHandler.toHandler());
return completionHandler;
}
/**
* 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 Single rxPutIfAbsent(K k, V v) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxPutIfAbsent} instead
*/
@Deprecated()
public Observable putIfAbsentObservable(K k, V v, long ttl) {
io.vertx.rx.java.ObservableFuture completionHandler = io.vertx.rx.java.RxHelper.observableFuture();
putIfAbsent(k, v, ttl, completionHandler.toHandler());
return completionHandler;
}
/**
* 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 Single rxPutIfAbsent(K k, V v, long ttl) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxRemove} instead
*/
@Deprecated()
public Observable removeObservable(K k) {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
remove(k, resultHandler.toHandler());
return resultHandler;
}
/**
* Remove a value from the map, asynchronously.
* @param k the key
* @return
*/
public Single rxRemove(K k) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxRemoveIfPresent} instead
*/
@Deprecated()
public Observable removeIfPresentObservable(K k, V v) {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
removeIfPresent(k, v, resultHandler.toHandler());
return resultHandler;
}
/**
* Remove a value from the map, only if entry already exists with same value.
* @param k the key
* @param v the value
* @return
*/
public Single rxRemoveIfPresent(K k, V v) {
return Single.create(new io.vertx.rx.java.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, 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
* @return
* @deprecated use {@link #rxReplace} instead
*/
@Deprecated()
public Observable replaceObservable(K k, V v) {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
replace(k, v, resultHandler.toHandler());
return resultHandler;
}
/**
* Replace the entry only if it is currently mapped to some value
* @param k the key
* @param v the new value
* @return
*/
public Single rxReplace(K k, V v) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
replace(k, v, 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, 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
* @return
* @deprecated use {@link #rxReplaceIfPresent} instead
*/
@Deprecated()
public Observable replaceIfPresentObservable(K k, V oldValue, V newValue) {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
replaceIfPresent(k, oldValue, newValue, resultHandler.toHandler());
return 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
* @return
*/
public Single rxReplaceIfPresent(K k, V oldValue, V newValue) {
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
replaceIfPresent(k, oldValue, newValue, fut);
}));
}
/**
* Clear all entries in the map
* @param resultHandler called on completion
*/
public void clear(Handler> resultHandler) {
delegate.clear(resultHandler);
}
/**
* Clear all entries in the map
* @return
* @deprecated use {@link #rxClear} instead
*/
@Deprecated()
public Observable clearObservable() {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
clear(resultHandler.toHandler());
return resultHandler;
}
/**
* Clear all entries in the map
* @return
*/
public Single rxClear() {
return Single.create(new io.vertx.rx.java.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(Handler> resultHandler) {
delegate.size(resultHandler);
}
/**
* Provide the number of entries in the map
* @return
* @deprecated use {@link #rxSize} instead
*/
@Deprecated()
public Observable sizeObservable() {
io.vertx.rx.java.ObservableFuture resultHandler = io.vertx.rx.java.RxHelper.observableFuture();
size(resultHandler.toHandler());
return resultHandler;
}
/**
* Provide the number of entries in the map
* @return
*/
public Single rxSize() {
return Single.create(new io.vertx.rx.java.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