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

21
LINES

< > BotCompany Repo | #1019095 - Tree - simple tree class

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

Libraryless. Click here for Pure Java version (2897L/18K).

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   

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

No comments. add comment

Snippet ID: #1019095
Snippet name: Tree - simple tree class
Eternal ID of this version: #1019095/17
Text MD5: c2d62774860367d1d9a4ab06e1227246
Transpilation MD5: f9e993ae4f6c068ba822197382ab33e8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-05 20:57:57
Source code size: 579 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 181 / 629
Version history: 16 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1019095 & http://1019095.tinybrain.de