// Textbook fragment 07.10 public static String parentheticRepresentation(Tree T, Position v) { String s = v.element().toString(); // main visit action if (T.isInternal(v)) { Boolean firstTime = true; for (Position w : T.children(v)) if (firstTime) { s += " ( " + parentheticRepresentation(T, w); // the first child firstTime = false; } else s += ", " + parentheticRepresentation(T, w); // subsequent child s += " )"; // close parenthesis } return s; }