renamed to putWith() to putMapped()

This commit is contained in:
Rob Austin
2014-12-10 15:33:25 +00:00
parent 7d1f3106d9
commit 8d347e4f28
9 changed files with 55 additions and 55 deletions
@@ -197,17 +197,17 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
* @param <R> return type.
* @return the result of the function, or null if there is no entry for the key.
*/
<R> R mapForKey(K key, @NotNull Function<? super V, R> function);
<R> R getMapped(K key, @NotNull Function<? super V, R> function);
/**
* Apply a mutator to the value for a key and return a result. A write lock is assumed. <p> If
* 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 mutator to alter the value and calculate a result
* @param unaryOperator to alter the value and calculate a result
* @return the result of the function.
*/
V putWith(K key, @NotNull Mutator<V> mutator);
V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator);
/**
* exports all the entries to a {@link java.io.File} storing them in JSON format, an attempt is
@@ -123,7 +123,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
PUT_ALL_WITHOUT_ACC,
HASH_CODE,
MAP_FOR_KEY,
UPDATE_FOR_KEY
PUT_MAPPED
}
@@ -482,7 +482,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
}
@Nullable
public <R> R mapForKey(@Nullable K key, @NotNull Function<? super V, R> function) {
public <R> R getMapped(@Nullable K key, @NotNull Function<? super V, R> function) {
if (key == null)
throw keyNotNullNPE();
return fetchObject(MAP_FOR_KEY, key, function);
@@ -491,10 +491,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
@Nullable
@Override
public V putWith(@Nullable K key, @NotNull Mutator<V> mutator) {
public V putMapped(@Nullable K key, @NotNull UnaryOperator<V> unaryOperator) {
if (key == null)
throw keyNotNullNPE();
return fetchObject(UPDATE_FOR_KEY, key, mutator);
return fetchObject(PUT_MAPPED, key, unaryOperator);
}
@@ -1417,8 +1417,8 @@ class StatelessServerConnector<K, V> {
case MAP_FOR_KEY:
return mapForKey(reader, writer, sizeLocation);
case UPDATE_FOR_KEY:
return updateForKey(reader, writer, sizeLocation);
case PUT_MAPPED:
return putMapped(reader, writer, sizeLocation);
default:
throw new IllegalStateException("unsupported event=" + event);
@@ -1430,7 +1430,7 @@ class StatelessServerConnector<K, V> {
final K key = keyReaderWithSize.read(reader, null);
final Function<V, ?> function = (Function<V, ?>) reader.readObject();
try {
Object result = map.mapForKey(key, function);
Object result = map.getMapped(key, function);
writer.writeObject(result);
} catch (Throwable e) {
LOG.info("", e);
@@ -1442,11 +1442,11 @@ class StatelessServerConnector<K, V> {
}
@Nullable
public Work updateForKey(@NotNull ByteBufferBytes reader, @NotNull Bytes writer, long sizeLocation) {
public Work putMapped(@NotNull ByteBufferBytes reader, @NotNull Bytes writer, long sizeLocation) {
final K key = keyReaderWithSize.read(reader, null);
final Mutator<V> mutator = (Mutator<V>) reader.readObject();
final UnaryOperator<V> unaryOperator = (UnaryOperator<V>) reader.readObject();
try {
Object result = map.putWith(key, mutator);
Object result = map.putMapped(key, unaryOperator);
writer.writeObject(result);
} catch (Throwable e) {
LOG.info("", e);
@@ -11,7 +11,7 @@ import java.io.Serializable;
*/
public interface Mutator<T> extends Serializable {
public interface UnaryOperator<T> extends Serializable {
/**
* Applies this mutator to the given mutable argument.
*
@@ -551,7 +551,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
@Override
public <R> R mapForKey(K key, @NotNull Function<? super V, R> function) {
public <R> R getMapped(K key, @NotNull Function<? super V, R> function) {
try (ReadContext<K, V> entry = lookupUsing(key, null,
false, false, LockType.READ_LOCK)) {
return entry.present() ? function.apply(entry.value()) : null;
@@ -559,7 +559,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
@Override
public V putWith(K key, @NotNull Mutator<V> mutator) {
public V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator) {
final V using = (vClass.equals(CharSequence.class)) ? (V) new StringBuilder() : null;
@@ -576,7 +576,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (entry.value() == null)
return null;
V result = mutator.update(entry.value());
V result = unaryOperator.update(entry.value());
if (entry.value() instanceof StringBuilder) {
((StringBuilder) using).setLength(0);
((StringBuilder) using).append((CharSequence) result);