Пример #1
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("{").append(getData().toString()).append(",[");
   int i = 0;
   for (Node<T> e : getChildren()) {
     if (i > 0) {
       sb.append(",");
     }
     sb.append(e.getData().toString());
     i++;
   }
   sb.append("]").append("}");
   return sb.toString();
 }
Пример #2
0
 /**
  * Walks the Tree in pre-order style. This is a recursive method, and is called from the toList()
  * method with the root element as the first argument. It appends to the second argument, which is
  * passed by reference * as it recurses down the tree.
  *
  * @param element the starting element.
  * @param list the output of the walk.
  */
 private void walk(Node<T> element, List<Node<T>> list) {
   list.add(element);
   for (Node<T> data : element.getChildren()) {
     walk(data, list);
   }
 }