@@ -113,18 +113,18 @@ public C remove(C value) {
113113
114114 private void remove (Node node ) {
115115 final Node parent = node .parent ;
116+
116117 // If node does not represent a word and has no children
117118 if (!node .isWord && node .loKid ==null && node .kid ==null && node .hiKid ==null ) {
118- // Remove node from parent
119- if (parent !=null && parent .loKid ==node ) {
120- parent .loKid = null ;
121- } else if (parent !=null && parent .hiKid ==node ) {
122- parent .hiKid = null ;
123- } else if (parent !=null && parent .kid ==node ) {
124- parent .kid = null ;
125- }
126-
127119 if (parent != null ) {
120+ // Remove node from parent
121+ if (parent .loKid ==node ) {
122+ parent .loKid = null ;
123+ } else if (parent .hiKid ==node ) {
124+ parent .hiKid = null ;
125+ } else if (parent .kid ==node ) {
126+ parent .kid = null ;
127+ }
128128 // Go up the tree and prune
129129 remove (parent );
130130 } else {
@@ -153,6 +153,7 @@ public boolean contains(C value) {
153153
154154 // Find the node
155155 final Node node = search (root , value , 0 );
156+
156157 // If node isn't null and it represents a "word" then the tree contains the value
157158 return (node !=null && node .isWord );
158159 }
@@ -285,6 +286,22 @@ protected Node(Node parent, char character, boolean isWord) {
285286 this .character = character ;
286287 this .isWord = isWord ;
287288 }
289+
290+ /**
291+ * {@inheritDoc}
292+ */
293+ @ Override
294+ public String toString () {
295+ final StringBuilder builder = new StringBuilder ();
296+ builder .append ("char=" ).append (this .character ).append ('\n' );
297+ if (this .loKid != null )
298+ builder .append ('\t' ).append ("lo=" ).append (this .loKid .character ).append ('\n' );
299+ if (this .kid != null )
300+ builder .append ('\t' ).append ("eq=" ).append (this .kid .character ).append ('\n' );
301+ if (this .hiKid != null )
302+ builder .append ('\t' ).append ("hi=" ).append (this .hiKid .character ).append ('\n' );
303+ return builder .toString ();
304+ }
288305 }
289306
290307 @ SuppressWarnings ("unchecked" )
@@ -354,7 +371,7 @@ protected TreeIterator(TernarySearchTree<C> tree) {
354371 }
355372
356373 private void getNodesWhichRepresentsWords (TernarySearchTree .Node node , String string , java .util .Map <TernarySearchTree .Node ,String > nodesMap ) {
357- StringBuilder builder = new StringBuilder (string );
374+ final StringBuilder builder = new StringBuilder (string );
358375 builder .append (node .character );
359376 if (node .isWord )
360377 nodesMap .put (node ,builder .toString ());
@@ -387,7 +404,8 @@ public boolean hasNext() {
387404 */
388405 @ Override
389406 public C next () {
390- if (iterator ==null ) return null ;
407+ if (iterator ==null )
408+ return null ;
391409
392410 java .util .Map .Entry <TernarySearchTree .Node ,String > entry = iterator .next ();
393411 lastNode = entry .getKey ();
@@ -399,7 +417,8 @@ public C next() {
399417 */
400418 @ Override
401419 public void remove () {
402- if (iterator ==null || tree ==null ) return ;
420+ if (iterator ==null || tree ==null )
421+ return ;
403422
404423 iterator .remove ();
405424 this .tree .remove (lastNode );
0 commit comments