mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Remove ChronicleMap.putMapped() as a duplicate of computeIfPresent(); Reduce the number of ignored tests
This commit is contained in:
@@ -18,7 +18,6 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.impl.util.CharSequences;
|
||||
import net.openhft.chronicle.map.impl.IterationContextInterface;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -43,25 +42,6 @@ interface AbstractChronicleMap<K, V> extends ChronicleMap<K, V>, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator) {
|
||||
requireNonNull(unaryOperator);
|
||||
try (ExternalMapQueryContext<K, V, ?> c = queryContext(key)) {
|
||||
// putMapped() should find a value, update & put most of the time,
|
||||
// so don't try to check key presence under read lock first,
|
||||
// as in putIfAbsent()/acquireUsing(), start with update lock:
|
||||
c.updateLock().lock();
|
||||
MapEntry<K, V> entry = c.entry();
|
||||
if (entry != null) {
|
||||
V newValue = unaryOperator.update(entry.value().get());
|
||||
c.replaceValue(entry, c.wrapValueAsData(newValue));
|
||||
return newValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void getAll(File toFile) throws IOException {
|
||||
synchronized (this) {
|
||||
|
||||
@@ -100,10 +100,10 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>,
|
||||
/**
|
||||
* Acquire a value for a key, creating if absent.
|
||||
*
|
||||
* <p>If the specified key is absent in the map, {@linkplain ChronicleMapBuilder#defaultValue(Object)
|
||||
* default value} is taken or {@linkplain ChronicleMapBuilder#defaultValueProvider(DefaultValueProvider)
|
||||
* default value provider} is called. Then this object is put to this map for the specified
|
||||
* key.
|
||||
* <p>If the specified key is absent in the map, {@linkplain ChronicleMapBuilder#defaultValue(
|
||||
* Object) default value} is taken or {@linkplain ChronicleMapBuilder#defaultValueProvider(
|
||||
* DefaultValueProvider) default value provider} is called. Then this object is put to this map
|
||||
* for the specified key.
|
||||
*
|
||||
* <p>Then, either if the key was initially absent in the map or already present, the value is
|
||||
* deserialized just as during {@link #getUsing(Object, Object) getUsing(key, usingValue)} call,
|
||||
@@ -140,25 +140,24 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>,
|
||||
net.openhft.chronicle.core.io.Closeable acquireContext(@NotNull K key, @NotNull V usingValue);
|
||||
|
||||
/**
|
||||
* Apply a mapping to the value returned by a key and return a result. A read lock is assumed.
|
||||
* Returns the result of application of the given function to the value to which the given key
|
||||
* is mapped. If there is no mapping for the key, {@code null} is returned from {@code
|
||||
* getMapped()} call without application of the given function. This method is primarily useful
|
||||
* when accessing {@code ChronicleMap} implementation which delegates it's requests to some
|
||||
* remote node (server) and pulls the result through serialization/deserialization path, and
|
||||
* probably network. In this case, when you actually need only a part of the map value's state
|
||||
* (e. g. a single field) it's cheaper to extract it on the server side and transmit lesser
|
||||
* bytes.
|
||||
*
|
||||
* @param key to apply the mapping to
|
||||
* @param function to calculate a result
|
||||
* @param <R> return type.
|
||||
* @return the result of the function, or null if there is no entry for the key.
|
||||
* @param key the key whose associated value is to be queried
|
||||
* @param function a function to transform the value to the actually needed result,
|
||||
* which should be smaller than the map value
|
||||
* @param <R> the result type
|
||||
* @return the result of applying the function to the mapped value, or {@code null} if there
|
||||
* is no mapping for the key
|
||||
*/
|
||||
<R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function);
|
||||
|
||||
/**
|
||||
* Apply a unaryOperator to the value for a key and return a result. A write lock is assumed.
|
||||
* <p> If there is no entry for this key null will be returned
|
||||
*
|
||||
* @param key to apply the mapping to
|
||||
* @param unaryOperator to alter the value and calculate a result
|
||||
* @return the result of the function.
|
||||
*/
|
||||
V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator);
|
||||
|
||||
/**
|
||||
* Exports all the entries to a {@link File} storing them in JSON format, an attempt is
|
||||
* made where possible to use standard java serialisation and keep the data human readable, data
|
||||
|
||||
@@ -263,7 +263,7 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
// TODO optimize to update lock in certain cases
|
||||
try {
|
||||
q.writeLock().lock();
|
||||
acquireUsingBody(q, usingValue);
|
||||
checkAcquiredUsing(acquireUsingBody(q, usingValue), usingValue);
|
||||
return q.acquireHandle();
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
@@ -379,17 +379,14 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
@Override
|
||||
public V acquireUsing(K key, V usingValue) {
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
V returnValue = acquireUsingBody(q, usingValue);
|
||||
return returnValue;
|
||||
return acquireUsingBody(q, usingValue);
|
||||
}
|
||||
}
|
||||
|
||||
private V acquireUsingBody(QueryContextInterface<K, V, R> q, V usingValue) {
|
||||
q.usingReturnValue().initUsingReturnValue(usingValue);
|
||||
methods.acquireUsing(q, q.usingReturnValue());
|
||||
V returnValue = q.usingReturnValue().returnValue();
|
||||
checkAcquiredUsing(returnValue, usingValue);
|
||||
return returnValue;
|
||||
return q.usingReturnValue().returnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
|
||||
@StageRef public VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
@StageRef public AllocatedChunks allocatedChunks;
|
||||
@StageRef KeySearch<?> ks;
|
||||
@StageRef KeySearch<K> ks;
|
||||
|
||||
long countValueSizeOffset() {
|
||||
return keyEnd();
|
||||
|
||||
+2
-1
@@ -172,6 +172,7 @@ public abstract class ReplicatedMapEntryStages<K, V> extends MapEntryStages<K, V
|
||||
@NotNull
|
||||
@Override
|
||||
public Data<K> absentKey() {
|
||||
return key();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return ks.inputKey;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user