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).

srecord FixedMapClass(Class<? extends Map> clazz) implements IMapImplementationPolicy {
  bool sync = true, nullOnEmpty = false;
  
  public <A, B> Map<A, B> makeSingletonMap(A key, B value) {
    ret put(null, key, value);
  }
  
  public <A, B> Map<A, B> put(Map<A, B> map, A key, B value) {
    if (map == null) map = newInstance(clazz);
    if (sync)
      syncPut(map, key, value);
    else
      map.put(key, value);
    ret map;
  }
  
  public <A, B> Map<A, B> remove(Map<A, B> map, O key) {
    if (map == null) null;
    if (sync)
      syncRemove(map, (A) key);
    else
      map.remove(key);
    ret nullOnEmpty && empty(map) ? null : map;
  }
}

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: 166 / 322
Version history: 10 change(s)
Referenced in: [show references]