Libraryless. Click here for Pure Java version (7915L/44K).
static <A, B> AutoCloseable mapPutStrictlyOrFail(Map<A, B> map, A key, B value) { if (!(map != null && key != null && value != null)) null; B old = map.get(key); if (old == null) { map.put(key, value); ret -> map.remove(old); } if (eq(old, value)) null; fail("Can't overwrite key " + key + " (old value: " + old + ", new value: " + value); }
Began life as a copy of #1035359
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035360 |
Snippet name: | mapPutStrictlyOrFail - fail if value cannot be put strictly (i.e. not overwriting anything) |
Eternal ID of this version: | #1035360/5 |
Text MD5: | 6497a87a2c87fc6cff38f5f04bb6d200 |
Transpilation MD5: | 72c7cf1558ee9e7e380378f1b4cd00e6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-02 01:42:05 |
Source code size: | 370 bytes / 10 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 132 / 192 |
Version history: | 4 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1035362 - tempMapPutStrictlyOrFail - fail if value cannot be put strictly (i.e. not overwriting anything) |