mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
CE-23 added map.putAll()
This commit is contained in:
@@ -97,7 +97,7 @@ class ClientWiredStatelessChronicleEntrySet<K, V> extends MapStatelessClient<K,
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return proxyReturnBoolean(remove, o);
|
||||
return proxyReturnBooleanArgs(remove, o);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -153,14 +153,14 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
if (key == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
return value != null && proxyReturnBoolean(removeWithValue, (K) key, (V) value);
|
||||
return value != null && proxyReturnBooleanArgs(removeWithValue, (K) key, (V) value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public boolean replace(K key, V oldValue, V newValue) {
|
||||
if (key == null || oldValue == null || newValue == null)
|
||||
throw new NullPointerException();
|
||||
return proxyReturnBoolean(replaceWithOldAndNewValue, key, oldValue, newValue);
|
||||
return proxyReturnBooleanArgs(replaceWithOldAndNewValue, key, oldValue, newValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@@ -217,11 +217,11 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return proxyReturnBoolean(isEmpty);
|
||||
return proxyReturnBoolean(isEmpty, null);
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return proxyReturnBooleanK(containsKey, (K) key);
|
||||
return proxyReturnBoolean(containsKey, out -> writeField(out, (K) key));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -230,9 +230,18 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return proxyReturnBooleanV(containsValue, (V) value);
|
||||
return proxyReturnBoolean(containsValue, out -> writeField(out, (V) value));
|
||||
}
|
||||
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> map) {
|
||||
|
||||
proxyReturnVoid(putAll, v ->
|
||||
map.entrySet().forEach(e -> v.sequence(toParameters(put, e.getKey(), e.getValue())))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public long longSize() {
|
||||
return proxyReturnLong(longSize);
|
||||
}
|
||||
@@ -243,7 +252,7 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
}
|
||||
|
||||
public V get(Object key) {
|
||||
return (V) proxyReturnObject(vClass, get, (K) key);
|
||||
return proxyReturnObject(vClass, get, (K) key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -266,7 +275,7 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
public V remove(Object key) {
|
||||
if (key == null)
|
||||
throw keyNotNullNPE();
|
||||
return (V) proxyReturnObject(vClass, removeReturnsNull ? removeWithoutAcc : remove, key);
|
||||
return proxyReturnObject(vClass, removeReturnsNull ? removeWithoutAcc : remove, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -275,11 +284,6 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
|
||||
}
|
||||
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> map) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public V put(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
@@ -344,19 +348,6 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
}
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
/**
|
||||
* @param callback each entry is passed to the callback
|
||||
*//*
|
||||
void entrySet(@NotNull MapEntryCallback<K, V> callback) {
|
||||
throw new UnsupportedOperationException();
|
||||
}*/
|
||||
private K readK(WireKey argName, Wire wireIn, K usingValue) {
|
||||
return (K) readObject(argName, wireIn, usingValue, kClass);
|
||||
}
|
||||
|
||||
|
||||
private int readInt(long tid, long startTime) {
|
||||
assert !hub.outBytesLock().isHeldByCurrentThread();
|
||||
|
||||
@@ -375,23 +366,10 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private boolean proxyReturnBooleanV(@NotNull final EventId eventId, V value) {
|
||||
private boolean proxyReturnBoolean(@NotNull final EventId eventId,
|
||||
@Nullable final Consumer<ValueOut> consumer) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
return readBoolean(sendEvent(startTime, eventId, out -> writeField(out, value)),
|
||||
startTime);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private boolean proxyReturnBooleanK(@NotNull final EventId eventId, K key) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
return readBoolean(sendEvent(startTime, eventId, out -> writeField(out, key)), startTime);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private boolean proxyReturnBoolean(@NotNull final EventId eventId) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
return readBoolean(sendEvent(startTime, eventId, VOID_PARAMETERS), startTime);
|
||||
return readBoolean(sendEvent(startTime, eventId, consumer), startTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -401,20 +379,6 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
return readInt(sendEvent(startTime, eventId, VOID_PARAMETERS), startTime);
|
||||
}
|
||||
|
||||
/*
|
||||
private long proxySend(EventId methodName, long startTime) {
|
||||
long tid;
|
||||
hub.outBytesLock().lock();
|
||||
try {
|
||||
tid = writeHeader(startTime);
|
||||
hub.outWire().writeDocument(false, wireOut -> wireOut.writeEventName(methodName));
|
||||
hub.writeSocket(hub.outWire());
|
||||
} finally {
|
||||
hub.outBytesLock().unlock();
|
||||
}
|
||||
return tid;
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean eventReturnsNull(@NotNull EventId methodName) {
|
||||
|
||||
@@ -353,13 +353,6 @@ public class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers>
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (putAll.contentEquals(eventName)) {
|
||||
putAll(tid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (longSize.contentEquals(eventName)) {
|
||||
write(b -> outWire.write(reply).int64(b.longSize()));
|
||||
return;
|
||||
@@ -395,14 +388,10 @@ public class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers>
|
||||
valueIn.marshallable(wire -> {
|
||||
|
||||
final Params[] params = getAndPut.params();
|
||||
final byte[] key1 = wire.read(params[0]).bytes();
|
||||
|
||||
final byte[] value1 = wire.read(params[1]).bytes();
|
||||
|
||||
MapWireHandler.this.writeValue(b -> {
|
||||
final byte[] result = b.put(key1, value1);
|
||||
return result;
|
||||
});
|
||||
MapWireHandler.this.writeValue(b -> b.put(
|
||||
wire.read(params[0]).bytes(),
|
||||
wire.read(params[1]).bytes()));
|
||||
|
||||
});
|
||||
|
||||
@@ -419,6 +408,28 @@ public class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers>
|
||||
return;
|
||||
}
|
||||
|
||||
if (putAll.contentEquals(eventName)) {
|
||||
|
||||
final Map data = new HashMap();
|
||||
|
||||
writeVoid(b -> {
|
||||
|
||||
while (valueIn.hasNext()) {
|
||||
|
||||
valueIn.sequence(v -> valueIn.marshallable(wire -> data.put(
|
||||
wire.read(getAndPut.params()[0]).bytes(),
|
||||
wire.read(getAndPut.params()[1]).bytes())));
|
||||
}
|
||||
|
||||
b.delegate.putAll(data);
|
||||
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (replace.contentEquals(eventName)) {
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user