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

1  
sclass LinkedTreeMap_simple<A, B> {
2  
  Map<A, B> map;
3  
  new L<A> list;
4  
5  
  *() { map = new TreeMap; }
6  
  *(Map<A, B> *map) {}
7  
8  
  public B get(Object key) {
9  
    ret map.get(key);
10  
  }
11  
  
12  
  public B put(A key, B value) {
13  
    if (!map.containsKey(key))
14  
      list.add(key);
15  
    return map.put(key, value);
16  
  }
17  
  
18  
  public bool containsKey(O key) {
19  
    ret map.containsKey(key);
20  
  }
21  
  
22  
  public Iterator<A> keyIterator() {
23  
    ret iterator(list);
24  
  }
25  
  
26  
  public Iterator<Map.Entry<A, B>> entryIterator() {
27  
    ret mapI(keyIterator(), a -> new AbstractMap.SimpleImmutableEntry<A, B>(a, map.get(a)));
28  
  }
29  
}

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: 182 / 445
Version history: 4 change(s)
Referenced in: [show references]