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

25
LINES

< > BotCompany Repo | #1031860 // FixedMapClass - IMapImplementationPolicy using only one class (e.g. HashMap)

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

Libraryless. Click here for Pure Java version (3154L/18K).

1  
srecord FixedMapClass(Class<? extends Map> clazz) implements IMapImplementationPolicy {
2  
  bool sync = true, nullOnEmpty = false;
3  
  
4  
  public <A, B> Map<A, B> makeSingletonMap(A key, B value) {
5  
    ret put(null, key, value);
6  
  }
7  
  
8  
  public <A, B> Map<A, B> put(Map<A, B> map, A key, B value) {
9  
    if (map == null) map = newInstance(clazz);
10  
    if (sync)
11  
      syncPut(map, key, value);
12  
    else
13  
      map.put(key, value);
14  
    ret map;
15  
  }
16  
  
17  
  public <A, B> Map<A, B> remove(Map<A, B> map, O key) {
18  
    if (map == null) null;
19  
    if (sync)
20  
      syncRemove(map, (A) key);
21  
    else
22  
      map.remove(key);
23  
    ret nullOnEmpty && empty(map) ? null : map;
24  
  }
25  
}

Author comment

Began life as a copy of #1031859

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031860
Snippet name: FixedMapClass - IMapImplementationPolicy using only one class (e.g. HashMap)
Eternal ID of this version: #1031860/11
Text MD5: eccdb26db84f9690d30634757ec5d668
Transpilation MD5: c60ddcfa5112575d7468bfbdaf6124a4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-16 07:02:08
Source code size: 682 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 168 / 324
Version history: 10 change(s)
Referenced in: [show references]