001package armyc2.c5isr.renderer.symbolpicker; 002 003import android.util.Log; 004import java.util.ArrayList; 005import java.util.List; 006 007public class Node { 008 009 private final String name; 010 private final String code; 011 private final String symbolSetCode; 012 private final String version; 013 private final ArrayList<Node> children; 014 015 public Node(String name, String version, String symbolSet, String code) { 016 this.name = name; 017 this.version = version; 018 this.symbolSetCode = symbolSet; 019 this.code = code; 020 children = new ArrayList<>(); 021 } 022 023 public void addChild(Node node) { 024 children.add(node); 025 } 026 027 public void addChildren(List<Node> nodes) { 028 children.addAll(nodes); 029 } 030 031 public String getName() { 032 return name; 033 } 034 035 public String getCode() { 036 return code; 037 } 038 039 public String getSymbolSetCode() { 040 return symbolSetCode; 041 } 042 043 public String getVersion() { 044 return version; 045 } 046 047 public ArrayList<Node> getChildren() { 048 return children; 049 } 050 051 public ArrayList<Node> flatten() { 052 ArrayList<Node> result = new ArrayList<>(); 053 for (Node child : children) { 054 result.add(child); 055 result.addAll(child.flatten()); 056 } 057 return result; 058 } 059 060 /** Calculates the size of the tree with this Node as the root. 061 * @return number of Nodes in this tree 062 */ 063 public int getSize() { 064 int size = 1; 065 for (Node n : children) { 066 size += n.getSize(); 067 } 068 return size; 069 } 070 071 /** Prints the entire subtree of this Node to the debug Log. 072 * @param depth Number of tabs to indent this Node in the log. Children will be indented further. 073 */ 074 public void logTree(int depth) { 075 StringBuilder indent = new StringBuilder(); 076 for (int i = 0; i < depth; i++) { 077 indent.append("\t"); 078 } 079 Log.d("Node", indent + name + "\t" + code); 080 for (Node n : children) { 081 n.logTree(depth + 1); 082 } 083 } 084}