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

39
LINES

< > BotCompany Repo | #1035860 // ConcatOnDemandList

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

Libraryless. Click here for Pure Java version (9230L/51K).

1  
// still efficient when used to build a list recursively
2  
persistable sclass ConcatOnDemandList<A> extends RandomAccessAbstractList<A> {
3  
  new LL<A> parts;
4  
  L<A> completeList;
5  
  
6  
  *(L<A>... parts) { fOr (part : parts) addPart(part); }
7  
  
8  
  void addPart(L<A> part) { parts.add(part); }
9  
  
10  
  public int size() { ret completeList().size(); }
11  
  public A get(int i) { ret completeList().get(i); }
12  
  
13  
  L<A> completeList() {
14  
    if (parts != null) {
15  
      new L<A> out;
16  
      for (part : parts)
17  
        collect(part, out);
18  
      parts = null;
19  
      completeList = out;
20  
    }
21  
    ret completeList;
22  
  }
23  
  
24  
  void collect(L<A> part, L<A> out) {
25  
    if (part == null) ret;
26  
    if (part cast ConcatOnDemandList)
27  
      part.collectInto(out);
28  
    else
29  
      out.addAll(part);
30  
  }
31  
  
32  
  void collectInto(L<A> out) {
33  
    if (parts != null)
34  
      for (part : parts)
35  
        collect(part, out);
36  
    else
37  
      out.addAll(completeList);
38  
  }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035860
Snippet name: ConcatOnDemandList
Eternal ID of this version: #1035860/9
Text MD5: dc8d62b783030d610843868cf7119196
Transpilation MD5: 7de169259f23bd7d88c308bbb4c5fd91
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-03 07:01:04
Source code size: 962 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 137 / 231
Version history: 8 change(s)
Referenced in: [show references]