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

21
LINES

< > BotCompany Repo | #1019095 // Tree<A> - simple generic tree class (all-in-one class)

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

Libraryless. Click here for Pure Java version (9882L/55K).

sclass Tree<A> extends Var<A> {
  L<Tree<A>> children;
  
  *() {}
  *(A *v) {}
  *(A *v, Iterable<Tree<A>> children) { this.children = cloneList(children); }
  
  toString { new LS out; toString(out, 0); ret lines(out); }
  
  // Note: This doesn't call the children() method
  void toString(LS out, int indent) {
    out.add(spaces(indent) + str(v));
    for (Tree<A> t : unnull(children))
      t.toString(out, indent+2);
  }
  
  A value() { ret get(); }
  
  // if you override, make sure to set field children
  L<Tree<A>> children() { ret children; }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1019095
Snippet name: Tree<A> - simple generic tree class (all-in-one class)
Eternal ID of this version: #1019095/19
Text MD5: c2d62774860367d1d9a4ab06e1227246
Transpilation MD5: 165db8ad3d6e3d02748571d93568c082
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-01 05:54:20
Source code size: 579 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 408 / 1081
Version history: 18 change(s)
Referenced in: [show references]