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

13
LINES

< > BotCompany Repo | #1005172 // StrictHashMap - non-overwrite HashMap (doesn't allow modification, only adding)

JavaX fragment (include)

sclass StrictHashMap<A, B> extends HashMap<A, B> {
  bool detailedExceptions;
  
  public B put(A key, B value) {
    B v = get(key);
    if (v != null && neq(v, value))
      if (detailedExceptions)
        fail("Strict map conflict: " + structure(key) + ", " + structure(get(key)) + ", " + structure(value));
      else
        fail("Trying to change strict map.");
    ret super.put(key, value);
  }
}

Author comment

Began life as a copy of #1003482

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005172
Snippet name: StrictHashMap - non-overwrite HashMap (doesn't allow modification, only adding)
Eternal ID of this version: #1005172/1
Text MD5: adb59c89aa4e525616717313ea92eb2d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-18 19:33:51
Source code size: 416 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 578 / 1129
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)