Libraryless. Click here for Pure Java version (7915L/44K).
1 | static <A, B> AutoCloseable mapPutStrictlyOrFail(Map<A, B> map, A key, B value) { |
2 | if (!(map != null && key != null && value != null)) null; |
3 | B old = map.get(key); |
4 | if (old == null) { |
5 | map.put(key, value); |
6 | ret -> map.remove(old); |
7 | } |
8 | if (eq(old, value)) null; |
9 | fail("Can't overwrite key " + key + " (old value: " + old + ", new value: " + value); |
10 | } |
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: | 133 / 194 |
Version history: | 4 change(s) |
Referenced in: | [show references] |