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.

persistable sclass AutoCreateList<A> extends RandomAccessAbstractList<A> {
  new L<A> list;
  IF1<Int, A> createElement; // optional, takes index and produces element
  
  *(IF1<Int, A> *createElement) {}
  *(IF0<A> createElement) { this(if0ToIF1(createElement)); }
  *(Class<? extends A> elementClass) { this(classToIF0(elementClass)); }
  
  public int size() { ret list.size(); }
  public A get(int i) {
    while (i >= size())
      list.add(createElement?.get(i));
    ret list.get(i);
  }
  
  public A set(int i, A a) {
    ret list.set(i, a);
  };
  
  public bool add(A a) { ret list.add(a); }
}

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: 205 / 385
Version history: 3 change(s)
Referenced in: [show references]