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

8
LINES

< > BotCompany Repo | #1035147 // tempPut - put into map with undo as AutoCloseable

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

Libraryless. Click here for Pure Java version (36L/1K).

1  
static <A, B> AutoCloseable tempPut(Map<A, B> map, A key, B value) {
2  
  if (map != null) {
3  
    bool wasContained = map.containsKey(key);
4  
    B old = map.put(key, value);
5  
    ret -> { if (wasContained) map.put(key, old); else map.remove(key); };
6  
  }
7  
  null;
8  
}

Author comment

Began life as a copy of #1034293

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035147
Snippet name: tempPut - put into map with undo as AutoCloseable
Eternal ID of this version: #1035147/3
Text MD5: 8bb240d9af0ad61e95c67e206597f8e6
Transpilation MD5: 405caf430094d20fce13c3cc7437f098
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-01 20:46:59
Source code size: 266 bytes / 8 lines
Pitched / IR pitched: No / No
Views / Downloads: 150 / 205
Version history: 2 change(s)
Referenced in: [show references]