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

23
LINES

< > BotCompany Repo | #1008857 // LazyValueTreeMap

JavaX fragment (include)

1  
sclass LazyValueTreeMap<A, B> extends TreeMap<A, B> {
2  
  static O placeholder = new O; // fool type system
3  
  O valueMaker;
4  
  
5  
  *(Collection<A> keys, O *valueMaker) {
6  
    for (A key : unnull(keys)) put(key, (B) placeholder);
7  
  }
8  
  
9  
  public B get(O key) {
10  
    B value = super.get(key);
11  
    if (value == placeholder)
12  
      put((A) key, value = (B) callF(valueMaker, key));
13  
    ret value;
14  
  }
15  
  
16  
  int numPlaceholders() {
17  
    ret countOccurrences_id(values(), placeholder);
18  
  }
19  
  
20  
  // revert to identity hashcode
21  
  public bool equals(O o) { ret this == o; }
22  
  public int hashCode() { ret systemHashCode(this); }
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008857
Snippet name: LazyValueTreeMap
Eternal ID of this version: #1008857/9
Text MD5: ccd726f33cf327886fce159b106a2cff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-14 14:01:58
Source code size: 633 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 545 / 1555
Version history: 8 change(s)
Referenced in: [show references]