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

29
LINES

< > BotCompany Repo | #1029683 // LinkedTreeMap_simple [doesn't implement Map]

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

Libraryless. Click here for Pure Java version (2626L/16K).

sclass LinkedTreeMap_simple<A, B> {
  Map<A, B> map;
  new L<A> list;

  *() { map = new TreeMap; }
  *(Map<A, B> *map) {}

  public B get(Object key) {
    ret map.get(key);
  }
  
  public B put(A key, B value) {
    if (!map.containsKey(key))
      list.add(key);
    return map.put(key, value);
  }
  
  public bool containsKey(O key) {
    ret map.containsKey(key);
  }
  
  public Iterator<A> keyIterator() {
    ret iterator(list);
  }
  
  public Iterator<Map.Entry<A, B>> entryIterator() {
    ret mapI(keyIterator(), a -> new AbstractMap.SimpleImmutableEntry<A, B>(a, map.get(a)));
  }
}

Author comment

Began life as a copy of #1022177

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029683
Snippet name: LinkedTreeMap_simple [doesn't implement Map]
Eternal ID of this version: #1029683/5
Text MD5: 23c37851bf930456d2e44699c9e64faf
Transpilation MD5: a85943670caad56b867558e21d69d9db
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-07 14:17:42
Source code size: 627 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 183 / 447
Version history: 4 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)