Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

7
LINES

< > BotCompany Repo | #1035359 // mapPutStrictlyOrFail - fail if value cannot be put strictly (i.e. not overwriting anything)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7912L/44K).

static <A, B> void mapPutStrictlyOrFail(Map<A, B> map, A key, B value) {
  if (!(map != null && key != null && value != null)) ret;
  B old = map.get(key);
  if (old == null) { map.put(key, value); ret; }
  if (eq(old, value)) ret;
  fail("Can't overwrite key " + key + " (old value: " + old + ", new value: " + value);
}

Author comment

Began life as a copy of #1012146

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035359
Snippet name: mapPutStrictlyOrFail - fail if value cannot be put strictly (i.e. not overwriting anything)
Eternal ID of this version: #1035359/1
Text MD5: 43b5ecc498e3c70e4fb85c44e7d43de3
Transpilation MD5: 97a10ac489059ec9235756181286acf5
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:30:55
Source code size: 327 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 46 / 67
Referenced in: [show references]