// Textbook fragment 07.01 /** * An interface for a tree where nodes can have an arbitrary number of children. */ public interface Tree { /** Returns the number of nodes in the tree. */ public int size(); /** Returns whether the tree is empty. */ public boolean isEmpty(); /** Returns an iterator of the elements stored in the tree. */ public Iterator iterator(); /** Returns an iterable collection of the the nodes. */ public Iterable> positions(); /** Replaces the element stored at a given node. */ public E replace(Position v, E e) throws InvalidPositionException; /** Returns the root of the tree. */ public Position root() throws EmptyTreeException; /** Returns the parent of a given node. */ public Position parent(Position v) throws InvalidPositionException, BoundaryViolationException; /** Returns an iterable collection of the children of a given node. */ public Iterable> children(Position v) throws InvalidPositionException; /** Returns whether a given node is internal. */ public boolean isInternal(Position v) throws InvalidPositionException; /** Returns whether a given node is external. */ public boolean isExternal(Position v) throws InvalidPositionException; /** Returns whether a given node is the root of the tree. */ public boolean isRoot(Position v) throws InvalidPositionException; }