public class SoundBranch extends CollectableNode { /* * A list of children to draw */ public CollectableNode children; /* * Construct a branch with children and * next as null **/ public SoundBranch(){ super(); // Call superclass constructor children = null; } /** * Method to return a string with informaiton * about this branch */ public String toString() { String childString = "No children", nextString="No next"; if (children != null) {childString = children.toString();} if (next != null) {nextString = next.toString();} return "SoundBranch (with child: "+childString+" and next: "+ nextString+")"; } /** * Method to add nodes to children **/ public void addChild(CollectableNode child){ if (children != null) {children.add(child);} else {children = child;} } /** * Collect all the sound from our children, * then collect from next. * @param pen Turtle to draw with **/ public Sound collect(){ Sound childSound; if (children != null) {childSound = children.collect();} else {childSound = new Sound(1);} // Collect from my next if (this.getNext() != null) {childSound=childSound.append(this.getNext().collect());} return childSound; } /** * Collect all the sound from our children, * then collect from next. * If there's processing, do to Next, not to Children * @param pen Turtle to draw with **/ public Sound collectAfter(){ Sound childSound; if (children != null) {childSound = children.collectAfter();} else {childSound = new Sound(1);} // Collect from my next if (this.getNext() != null) {childSound=childSound.append(this.getNext().collectAfter());} return childSound; } }