protected SockJSSession getSession(RoutingContext rc, long timeout, long heartbeatInterval, String sessionID, Handler<SockJSSocket> sockHandler) { SockJSSession session = sessions.computeIfAbsent(sessionID, s -> new SockJSSession(vertx, sessions, rc, s, timeout, heartbeatInterval, sockHandler)); return session; }
assertEquals(map.get("bar"), "was null"); map.computeIfAbsent("foo", (k) -> "was not there"); assertEquals(map.get("foo"), "something else"); map.computeIfAbsent("baz", (k) -> "was not there"); assertEquals(map.get("baz"), "was not there"); assertEquals(map.get("foo"), "replaced"); map.computeIfAbsent("foo", k -> "was not there"); assertEquals(map.get("foo"), "replaced"); map.computeIfAbsent("baz", k -> "was not there"); assertTrue(map.remove("baz", "was not there"));
@Test public void deleteElementOnComputeFunctionReturningNull() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); // put an initial value map.put("hello", "world"); // retuning null we should remove the entry map.computeIfPresent("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // Same for LocalMap#compute and LocalMap#compute map.compute("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // put a value one more time map.put("hello", "world"); map.merge("hello", "world!!!!!!", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); map.computeIfAbsent("hello", key -> null); assertFalse(map.containsKey("hello")); }
protected SockJSSession getSession(RoutingContext rc, long timeout, long heartbeatInterval, String sessionID, Handler<SockJSSocket> sockHandler) { SockJSSession session = sessions.computeIfAbsent(sessionID, s -> new SockJSSession(vertx, sessions, rc, s, timeout, heartbeatInterval, sockHandler)); return session; }
assertEquals(map.get("bar"), "was null"); map.computeIfAbsent("foo", (k) -> "was not there"); assertEquals(map.get("foo"), "something else"); map.computeIfAbsent("baz", (k) -> "was not there"); assertEquals(map.get("baz"), "was not there"); assertEquals(map.get("foo"), "replaced"); map.computeIfAbsent("foo", k -> "was not there"); assertEquals(map.get("foo"), "replaced"); map.computeIfAbsent("baz", k -> "was not there"); assertTrue(map.remove("baz", "was not there"));
@Test public void deleteElementOnComputeFunctionReturningNull() { LocalMap<String, String> map = sharedData.getLocalMap("foo"); // put an initial value map.put("hello", "world"); // retuning null we should remove the entry map.computeIfPresent("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // Same for LocalMap#compute and LocalMap#compute map.compute("hello", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); // put a value one more time map.put("hello", "world"); map.merge("hello", "world!!!!!!", (key, oldValue) -> null); assertFalse(map.containsKey("hello")); map.computeIfAbsent("hello", key -> null); assertFalse(map.containsKey("hello")); }