From 7b87ae21c7c57724b75e7ca716eabca16d226542 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Sat, 2 May 2015 02:27:44 +0100 Subject: [PATCH] fixed generics bug --- .../map/MapWireHandlerProcessor.java | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/MapWireHandlerProcessor.java b/src/main/java/net/openhft/chronicle/map/MapWireHandlerProcessor.java index 1b1d15b16..04db31fca 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireHandlerProcessor.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireHandlerProcessor.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.io.StreamCorruptedException; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -50,29 +49,21 @@ import static net.openhft.chronicle.wire.Wires.acquireStringBuilder; /** * @author Rob Austin. */ -public class MapWireHandlerProcessor implements - MapWireHandler, K, V>, - Consumer { +public class MapWireHandlerProcessor implements + MapWireHandler, Consumer { private CharSequence csp; - private BiConsumer vToWire; - private Function wireToK; - private Function wireToV; + private BiConsumer vToWire; + private Function wireToK; + private Function wireToV; + @Override - public void process(@NotNull final Wire in, - @NotNull final Wire out, - @NotNull final ConcurrentMap map, - @NotNull final CharSequence csp, - @NotNull final BiConsumer vToWire, - @NotNull final Function kFromWire, - @NotNull final Function vFromWire) throws StreamCorruptedException { - - - this.vToWire = vToWire; - this.wireToK = kFromWire; - this.wireToV = vFromWire; + public void process(Wire in, Wire out, Map map, CharSequence csp, BiConsumer vToWire, Function kFromWire, Function vFromWire) throws StreamCorruptedException { + this.vToWire = (BiConsumer) vToWire; + this.wireToK = (Function) kFromWire; + this.wireToV = (Function) vFromWire; try { this.inWire = in; @@ -170,7 +161,7 @@ public class MapWireHandlerProcessor implements } }; - private ConcurrentMap map; + private Map map; public MapWireHandlerProcessor(@NotNull final Map cidToCsp) throws IOException { this.cidToCsp = cidToCsp; @@ -242,9 +233,9 @@ public class MapWireHandlerProcessor implements valueIn.marshallable(wire -> { final Params[] params = putIfAbsent.params(); - final K key = wireToK.apply(wire.read(params[0])); - final V value = wireToV.apply(wire.read(params[1])); - final V v = map.putIfAbsent(key, value); + final Object key = wireToK.apply(wire.read(params[0])); + final Object value = wireToV.apply(wire.read(params[1])); + final Object v = map.putIfAbsent(key, value); vToWire.accept(outWire.write(reply), v); }); @@ -333,7 +324,7 @@ public class MapWireHandlerProcessor implements } if (get.contentEquals(eventName)) { - final K key = wireToK.apply(valueIn); + final Object key = wireToK.apply(valueIn); vToWire.accept(outWire.write(reply), map.get(key)); return; @@ -344,8 +335,8 @@ public class MapWireHandlerProcessor implements valueIn.marshallable(wire -> { final Params[] params = getAndPut.params(); - final K key = wireToK.apply(wire.read(params[0])); - final V value = wireToV.apply(wire.read(params[1])); + final Object key = wireToK.apply(wire.read(params[0])); + final Object value = wireToV.apply(wire.read(params[1])); vToWire.accept(outWire.write(reply), map.put(key, value)); @@ -357,7 +348,7 @@ public class MapWireHandlerProcessor implements if (remove.contentEquals(eventName)) { outWire.write(reply); - final K key = wireToK.apply(valueIn); + final Object key = wireToK.apply(valueIn); vToWire.accept(outWire.write(reply), map.remove(key)); return; } @@ -366,8 +357,8 @@ public class MapWireHandlerProcessor implements if (replace.contentEquals(eventName)) { valueIn.marshallable(wire -> { final Params[] params = replace.params(); - final K key = wireToK.apply(wire.read(params[0])); - final V value = wireToV.apply(wire.read(params[1])); + final Object key = wireToK.apply(wire.read(params[0])); + final Object value = wireToV.apply(wire.read(params[1])); vToWire.accept(outWire.write(reply), map.replace(key, value)); @@ -381,9 +372,9 @@ public class MapWireHandlerProcessor implements if (replaceWithOldAndNewValue.contentEquals(eventName)) { valueIn.marshallable(wire -> { final Params[] params = replaceWithOldAndNewValue.params(); - final K key = wireToK.apply(wire.read(params[0])); - final V oldValue = wireToV.apply(wire.read(params[1])); - final V newValue = wireToV.apply(wire.read(params[2])); + final Object key = wireToK.apply(wire.read(params[0])); + final Object oldValue = wireToV.apply(wire.read(params[1])); + final Object newValue = wireToV.apply(wire.read(params[2])); outWire.write(reply).bool(map.replace(key, oldValue, newValue)); }); @@ -393,8 +384,8 @@ public class MapWireHandlerProcessor implements if (putIfAbsent.contentEquals(eventName)) { valueIn.marshallable(wire -> { final Params[] params = putIfAbsent.params(); - final K key = wireToK.apply(wire.read(params[0])); - final V value = wireToV.apply(wire.read(params[1])); + final Object key = wireToK.apply(wire.read(params[0])); + final Object value = wireToV.apply(wire.read(params[1])); vToWire.accept(outWire.write(reply), map.putIfAbsent(key, value));