static AutoCloseable tempPut(Map map, A key, B value) { if (map != null) { bool wasContained = map.containsKey(key); B old = map.put(key, value); ret -> { if (wasContained) map.put(key, old); else map.remove(key); }; } null; }