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

12
LINES

< > BotCompany Repo | #1032016 // syncMapGetOrPut

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

Libraryless. Click here for Pure Java version (2991L/17K).

static <A, B> B syncMapGetOrPut(Map<A, B> map, A key, B value) {
  if (map == null || key == null) ret value;
  synchronized(collectionMutex(map)) {
    B existingValue = map.get(key);
    if (existingValue != null)
      ret existingValue;
    else {
      map.put(key, value);
      ret value;
    }
  }
}

Author comment

Began life as a copy of #1031558

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032016
Snippet name: syncMapGetOrPut
Eternal ID of this version: #1032016/1
Text MD5: a95e3651b5be7d8cc549ddaf88d8d379
Transpilation MD5: d6d5e5c0533b64cb3e5bd01e21579e8f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-11 02:18:22
Source code size: 318 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 94 / 130
Referenced in: [show references]