diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 115c598dc..8482ae791 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -197,17 +197,17 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * @param return type. * @return the result of the function, or null if there is no entry for the key. */ - R mapForKey(K key, @NotNull Function function); + R getMapped(K key, @NotNull Function function); /** - * Apply a mutator to the value for a key and return a result. A write lock is assumed.

If + * Apply a unaryOperator to the value for a key and return a result. A write lock is assumed.

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 mutator); + V putMapped(K key, @NotNull UnaryOperator unaryOperator); /** * exports all the entries to a {@link java.io.File} storing them in JSON format, an attempt is diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index e592fb2a9..727195d2a 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -123,7 +123,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon PUT_ALL_WITHOUT_ACC, HASH_CODE, MAP_FOR_KEY, - UPDATE_FOR_KEY + PUT_MAPPED } @@ -482,7 +482,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon } @Nullable - public R mapForKey(@Nullable K key, @NotNull Function function) { + public R getMapped(@Nullable K key, @NotNull Function function) { if (key == null) throw keyNotNullNPE(); return fetchObject(MAP_FOR_KEY, key, function); @@ -491,10 +491,10 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @Nullable @Override - public V putWith(@Nullable K key, @NotNull Mutator mutator) { + public V putMapped(@Nullable K key, @NotNull UnaryOperator unaryOperator) { if (key == null) throw keyNotNullNPE(); - return fetchObject(UPDATE_FOR_KEY, key, mutator); + return fetchObject(PUT_MAPPED, key, unaryOperator); } diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index c4c82d6db..dbb480ba7 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1417,8 +1417,8 @@ class StatelessServerConnector { 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 { final K key = keyReaderWithSize.read(reader, null); final Function function = (Function) 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 { } @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 mutator = (Mutator) reader.readObject(); + final UnaryOperator unaryOperator = (UnaryOperator) reader.readObject(); try { - Object result = map.putWith(key, mutator); + Object result = map.putMapped(key, unaryOperator); writer.writeObject(result); } catch (Throwable e) { LOG.info("", e); diff --git a/src/main/java/net/openhft/chronicle/map/Mutator.java b/src/main/java/net/openhft/chronicle/map/UnaryOperator.java similarity index 88% rename from src/main/java/net/openhft/chronicle/map/Mutator.java rename to src/main/java/net/openhft/chronicle/map/UnaryOperator.java index 5d527604b..888eb4489 100755 --- a/src/main/java/net/openhft/chronicle/map/Mutator.java +++ b/src/main/java/net/openhft/chronicle/map/UnaryOperator.java @@ -11,7 +11,7 @@ import java.io.Serializable; */ -public interface Mutator extends Serializable { +public interface UnaryOperator extends Serializable { /** * Applies this mutator to the given mutable argument. * diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index c55448db0..2864f578f 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -551,7 +551,7 @@ class VanillaChronicleMap, } @Override - public R mapForKey(K key, @NotNull Function function) { + public R getMapped(K key, @NotNull Function function) { try (ReadContext entry = lookupUsing(key, null, false, false, LockType.READ_LOCK)) { return entry.present() ? function.apply(entry.value()) : null; @@ -559,7 +559,7 @@ class VanillaChronicleMap, } @Override - public V putWith(K key, @NotNull Mutator mutator) { + public V putMapped(K key, @NotNull UnaryOperator unaryOperator) { final V using = (vClass.equals(CharSequence.class)) ? (V) new StringBuilder() : null; @@ -576,7 +576,7 @@ class VanillaChronicleMap, 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); diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 838fa9d99..616357008 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -38,13 +38,13 @@ public class CHMUseCasesTest { map.put("Hello", "World"); assertEquals("World", map.get("Hello")); - assertEquals("New World", map.mapForKey("Hello", new Function() { + assertEquals("New World", map.getMapped("Hello", new Function() { @Override public String apply(String s) { return "New " + s; } })); - assertEquals(null, map.mapForKey("No key", new Function() { + assertEquals(null, map.getMapped("No key", new Function() { @Override public String apply(String s) { return "New " + s; @@ -73,7 +73,7 @@ public class CHMUseCasesTest { map.put("Hello", "World"); - map.putWith("Hello", new Mutator() { + map.putMapped("Hello", new UnaryOperator() { @Override public String update(String s) { return "New " + s; @@ -109,14 +109,14 @@ public class CHMUseCasesTest { assertNull(map.getUsing(key, value)); - assertEquals("New World", map.mapForKey("Hello", new + assertEquals("New World", map.getMapped("Hello", new Function() { @Override public CharSequence apply(CharSequence s) { return "New " + s; } })); - assertEquals(null, map.mapForKey("No key", new + assertEquals(null, map.getMapped("No key", new Function() { @Override public CharSequence apply(CharSequence s) { @@ -124,8 +124,8 @@ public class CHMUseCasesTest { } })); - assertEquals("New World !!", map.putWith("Hello", new - Mutator() { + assertEquals("New World !!", map.putMapped("Hello", new + UnaryOperator() { @Override public CharSequence update(CharSequence s) { ((StringBuilder) s).append(" !!"); @@ -135,8 +135,8 @@ public class CHMUseCasesTest { assertEquals("New World !!", map.get("Hello").toString()); - assertEquals(null, map.putWith("no-key", new - Mutator() { + assertEquals(null, map.putMapped("no-key", new + UnaryOperator() { @Override public CharSequence update(CharSequence s) { ((StringBuilder) s).append("!!"); @@ -268,13 +268,13 @@ public class CHMUseCasesTest { assertEquals(null, map.get(3)); assertEquals(null, map.get(4)); - assertEquals((Integer) 110, map.mapForKey(1, new Function() { + assertEquals((Integer) 110, map.getMapped(1, new Function() { @Override public Integer apply(Integer s) { return 10 * s; } })); - assertEquals(null, map.mapForKey(-1, new Function() { + assertEquals(null, map.getMapped(-1, new Function() { @Override public Integer apply(Integer s) { return 10 * s; @@ -282,7 +282,7 @@ public class CHMUseCasesTest { })); try { - map.putWith(1, new Mutator() { + map.putMapped(1, new UnaryOperator() { @Override public Integer update(Integer s) { return s + 1; @@ -311,13 +311,13 @@ public class CHMUseCasesTest { assertEquals(null, map.get(3L)); assertEquals(null, map.get(4L)); - assertEquals((Long) 110L, map.mapForKey(1L, new Function() { + assertEquals((Long) 110L, map.getMapped(1L, new Function() { @Override public Long apply(Long s) { return 10 * s; } })); - assertEquals(null, map.mapForKey(-1L, new Function() { + assertEquals(null, map.getMapped(-1L, new Function() { @Override public Long apply(Long s) { return 10 * s; @@ -325,7 +325,7 @@ public class CHMUseCasesTest { })); try { - map.putWith(1L, new Mutator() { + map.putMapped(1L, new UnaryOperator() { @Override public Long update(Long s) { return s + 1; @@ -354,13 +354,13 @@ public class CHMUseCasesTest { assertEquals(null, map.get(3.0)); assertEquals(null, map.get(4.0)); - assertEquals((Double) 110.0, map.mapForKey(1.0, new Function() { + assertEquals((Double) 110.0, map.getMapped(1.0, new Function() { @Override public Double apply(Double s) { return 10 * s; } })); - assertEquals(null, map.mapForKey(-1.0, new Function() { + assertEquals(null, map.getMapped(-1.0, new Function() { @Override public Double apply(Double s) { return 10 * s; @@ -368,7 +368,7 @@ public class CHMUseCasesTest { })); try { - map.putWith(1.0, new Mutator() { + map.putMapped(1.0, new UnaryOperator() { @Override public Double update(Double s) { return s + 1; @@ -401,20 +401,20 @@ public class CHMUseCasesTest { map.put(key1, value1); - assertTrue(Arrays.equals(new byte[]{11, 11}, map.mapForKey(key1, new Function() { + assertTrue(Arrays.equals(new byte[]{11, 11}, map.getMapped(key1, new Function() { @Override public byte[] apply(byte[] s) { return Arrays.copyOf(s, 2); } }))); - assertEquals(null, map.mapForKey(key2, new Function() { + assertEquals(null, map.getMapped(key2, new Function() { @Override public byte[] apply(byte[] s) { return Arrays.copyOf(s, 2); } })); - assertTrue(Arrays.equals(new byte[]{12, 10}, map.putWith(key1, new Mutator() { + assertTrue(Arrays.equals(new byte[]{12, 10}, map.putMapped(key1, new UnaryOperator() { @Override public byte[] update(byte[] s) { s[0]++; @@ -458,10 +458,10 @@ public class CHMUseCasesTest { }; map.put(key1, value1); - assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); - assertEquals(null, map.mapForKey(key2, function)); + assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.getMapped(key1, function)); + assertEquals(null, map.getMapped(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putMapped(key1, new UnaryOperator() { @Override public ByteBuffer update(ByteBuffer s) { s.put(0, (byte) (s.get(0) + 1)); @@ -568,10 +568,10 @@ public class CHMUseCasesTest { return slice; } }; - assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); - assertEquals(null, map.mapForKey(key2, function)); + assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.getMapped(key1, function)); + assertEquals(null, map.getMapped(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWith(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putMapped(key1, new UnaryOperator() { @Override public ByteBuffer update(ByteBuffer s) { s.put(0, (byte) (s.get(0) + 1)); diff --git a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java index 757a728c5..41c314780 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -218,13 +218,13 @@ public class ReplicationCheckingMap implements ChronicleMap { } @Override - public R mapForKey(K key, @NotNull Function function) { - return map1.mapForKey(key, function); + public R getMapped(K key, @NotNull Function function) { + return map1.getMapped(key, function); } @Override - public V putWith(K key, @NotNull Mutator mutator) { - return map1.putWith(key, mutator); + public V putMapped(K key, @NotNull UnaryOperator unaryOperator) { + return map1.putMapped(key, unaryOperator); } @Override diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java index c25fcfa6c..a169e7060 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java @@ -111,7 +111,7 @@ public class StatelessClientTest { .class, StringBuilder.class) .putReturnsNull(true) .statelessClient(new InetSocketAddress("localhost", port)).create()) { - String actual = statelessMap.mapForKey(10, ToString.INSTANCE); + String actual = statelessMap.getMapped(10, ToString.INSTANCE); assertEquals("Hello World", actual); } @@ -131,7 +131,7 @@ public class StatelessClientTest { try (ChronicleMap statelessMap = ChronicleMapBuilder.of(Integer .class, StringBuilder.class) .statelessClient(new InetSocketAddress("localhost", port)).create()) { - String actual = statelessMap.mapForKey(11, ToString.INSTANCE); + String actual = statelessMap.getMapped(11, ToString.INSTANCE); assertEquals(null, actual); } diff --git a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java index 5d7a9551c..e4ddc060f 100755 --- a/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jrs166/map/StatelessChronicleMapTest.java @@ -170,13 +170,13 @@ public class StatelessChronicleMapTest extends JSR166TestCase { } @Override - public R mapForKey(K key, @NotNull Function function) { - return d.mapForKey(key, function); + public R getMapped(K key, @NotNull Function function) { + return d.getMapped(key, function); } @Override - public V putWith(K key, @NotNull Mutator mutator) { - return d.putWith(key, mutator); + public V putMapped(K key, @NotNull UnaryOperator unaryOperator) { + return d.putMapped(key, unaryOperator); } @Override