From 2df0426d83a54e4ddea14d9aa8283989297937b3 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 9 Dec 2014 12:07:15 +0000 Subject: [PATCH] HCOLL-234 as agreeded changed method name to "putWithMapping()" --- .../openhft/chronicle/map/ChronicleMap.java | 4 +-- .../chronicle/map/StatelessChronicleMap.java | 2 +- .../openhft/chronicle/map/TcpReplicator.java | 2 +- .../chronicle/map/VanillaChronicleMap.java | 5 ++-- .../chronicle/map/CHMUseCasesTest.java | 26 +++++++------------ .../chronicle/map/ReplicationCheckingMap.java | 4 +-- .../jrs166/map/StatelessChronicleMapTest.java | 4 +-- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index c7e3764fd..6cb467c72 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -204,12 +204,12 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * Apply a mutator to the value for a key and return a result. A write lock is assumed.

If * there is no entry for this key it will be created and the value empty. * + * @param return type. * @param key to apply the mapping to * @param mutator to alter the value and calculate a result - * @param return type. * @return the result of the function. */ - R updateForKey(K key, @NotNull Mutator mutator); + R putWithMapping(K key, @NotNull Mutator mutator); /** * 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 59064e1e6..d84e90ac9 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -490,7 +490,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @Nullable @Override - public R updateForKey(@Nullable K key, @NotNull Mutator mutator) { + public R putWithMapping(@Nullable K key, @NotNull Mutator mutator) { if (key == null) throw keyNotNullNPE(); return fetchObject(UPDATE_FOR_KEY, key, mutator); diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 958d42ee1..4f1be0981 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1442,7 +1442,7 @@ class StatelessServerConnector { final K key = keyReaderWithSize.read(reader, null); final Mutator mutator = (Mutator) reader.readObject(); try { - Object result = map.updateForKey(key, mutator); + Object result = map.putWithMapping(key, mutator); writer.writeObject(result); } catch (Throwable e) { LOG.info("", e); diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 8b0ae7ccc..227682409 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -559,7 +559,7 @@ class VanillaChronicleMap, } @Override - public R updateForKey(K key, @NotNull Mutator mutator) { + public R putWithMapping(K key, @NotNull Mutator mutator) { if (!(CharSequence.class.isAssignableFrom(vClass))) { @@ -573,7 +573,8 @@ class VanillaChronicleMap, if (!entry.wasPresent()) return null; - return mutator.update(entry.value()); + R result = mutator.update(entry.value()); + ((MutableLockedEntry) entry).value(result); } } diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index a682b1fdd..0b7a6205c 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -75,16 +75,13 @@ public class CHMUseCasesTest { map.put("Hello", "World"); try { - map.updateForKey("Hello", new Mutator() { + map.putWithMapping("Hello", new Mutator() { @Override public String update(String s) { return "New " + s; } }); - - //I disagree with the fail - you should be able to put into a string - Rob -// fail("Operation not supported as value is not mutable"); } catch (Exception ignored) { ignored.printStackTrace(); } @@ -132,7 +129,7 @@ public class CHMUseCasesTest { } })); - assertEquals("New World !!", map.updateForKey(new StringBuilder("Hello"), new + assertEquals("New World !!", map.putWithMapping(new StringBuilder("Hello"), new Mutator() { @Override public CharSequence update(CharSequence s) { @@ -143,7 +140,7 @@ public class CHMUseCasesTest { assertEquals("New World !!", map.get("Hello").toString()); - assertEquals(null, map.updateForKey(new StringBuilder("no-key"), new + assertEquals(null, map.putWithMapping(new StringBuilder("no-key"), new Mutator() { @Override public CharSequence update(CharSequence s) { @@ -292,13 +289,12 @@ public class CHMUseCasesTest { })); try { - map.updateForKey(1, new Mutator() { + map.putWithMapping(1, new Mutator() { @Override public Integer update(Integer s) { return s + 1; } }); - fail("Update of Integer not supported"); } catch (Exception todoMoreSpecificException) { } @@ -307,7 +303,6 @@ public class CHMUseCasesTest { } @Test - @Ignore("HCOLL-226 implement disableOversizedEntries()") public void testLongLongMap() throws ExecutionException, InterruptedException { try (ChronicleMap map = ChronicleMapBuilder .of(Long.class, Long.class) @@ -337,13 +332,12 @@ public class CHMUseCasesTest { })); try { - map.updateForKey(1L, new Mutator() { + map.putWithMapping(1L, new Mutator() { @Override public Long update(Long s) { return s + 1; } }); - fail("Update of Long not supported"); } catch (Exception todoMoreSpecificException) { } @@ -382,13 +376,13 @@ public class CHMUseCasesTest { })); try { - map.updateForKey(1.0, new Mutator() { + map.putWithMapping(1.0, new Mutator() { @Override public Double update(Double s) { return s + 1; } }); - fail("Update of Double not supported"); + } catch (Exception todoMoreSpecificException) { } @@ -426,7 +420,7 @@ public class CHMUseCasesTest { } })); - assertTrue(Arrays.equals(new byte[]{12, 10}, map.updateForKey(key1, new Mutator() { + assertTrue(Arrays.equals(new byte[]{12, 10}, map.putWithMapping(key1, new Mutator() { @Override public byte[] update(byte[] s) { s[0]++; @@ -473,7 +467,7 @@ public class CHMUseCasesTest { assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); assertEquals(null, map.mapForKey(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.updateForKey(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWithMapping(key1, new Mutator() { @Override public ByteBuffer update(ByteBuffer s) { s.put(0, (byte) (s.get(0) + 1)); @@ -568,7 +562,7 @@ public class CHMUseCasesTest { assertBBEquals(ByteBuffer.wrap(new byte[]{11, 11}), map.mapForKey(key1, function)); assertEquals(null, map.mapForKey(key2, function)); - assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.updateForKey(key1, new Mutator() { + assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10}), map.putWithMapping(key1, new Mutator() { @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 e70843d33..125d851ed 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -223,8 +223,8 @@ public class ReplicationCheckingMap implements ChronicleMap { } @Override - public R updateForKey(K key, @NotNull Mutator mutator) { - return map1.updateForKey(key, mutator); + public R putWithMapping(K key, @NotNull Mutator mutator) { + return map1.putWithMapping(key, mutator); } @Override 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 1c487acf1..9e126666a 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 @@ -175,8 +175,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase { } @Override - public R updateForKey(K key, @NotNull Mutator mutator) { - return d.updateForKey(key, mutator); + public R putWithMapping(K key, @NotNull Mutator mutator) { + return d.putWithMapping(key, mutator); } @Override