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

21
LINES

< > BotCompany Repo | #1031199 // AutoCreateList - create elements on get()

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

Transpiled version (2778L) is out of date.

1  
persistable sclass AutoCreateList<A> extends RandomAccessAbstractList<A> {
2  
  new L<A> list;
3  
  IF1<Int, A> createElement; // optional, takes index and produces element
4  
  
5  
  *(IF1<Int, A> *createElement) {}
6  
  *(IF0<A> createElement) { this(if0ToIF1(createElement)); }
7  
  *(Class<? extends A> elementClass) { this(classToIF0(elementClass)); }
8  
  
9  
  public int size() { ret list.size(); }
10  
  public A get(int i) {
11  
    while (i >= size())
12  
      list.add(createElement?.get(i));
13  
    ret list.get(i);
14  
  }
15  
  
16  
  public A set(int i, A a) {
17  
    ret list.set(i, a);
18  
  };
19  
  
20  
  public bool add(A a) { ret list.add(a); }
21  
}

Author comment

Began life as a copy of #1031197

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031199
Snippet name: AutoCreateList - create elements on get()
Eternal ID of this version: #1031199/4
Text MD5: db70952f6df36e89789aa50f997a15de
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-18 00:15:16
Source code size: 624 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 207 / 387
Version history: 3 change(s)
Referenced in: [show references]