public String getFinalReason ( Path path ) { StringBuilder sb = new StringBuilder ( path + " cannot be modified; " ) ; StringBuilder finalPath = new StringBuilder ( "/" ) ; // Step through the nodes based on the given path. If any intermediate // nodes are marked as final, we can just return true. Node currentNode = root ; for ( Term t : path . getTerms ( ) ) { finalPath . append ( t . toString ( ) ) ; Node nextNode = currentNode . getChild ( t ) ; if ( nextNode == null ) { return null ; } else if ( nextNode . isFinal ( ) ) { sb . append ( finalPath . toString ( ) + " is marked as final" ) ; return sb . toString ( ) ; } finalPath . append ( "/" ) ; currentNode = nextNode ; } // Strip off the last slash. It is not needed. finalPath . deleteCharAt ( finalPath . length ( ) - 1 ) ; // Either the path itself is final or a descendant. if ( currentNode . isFinal ( ) ) { sb . append ( finalPath . toString ( ) + " is marked as final" ) ; } else if ( currentNode . hasChild ( ) ) { sb . append ( finalPath . toString ( ) + currentNode . getFinalDescendantPath ( ) + " is marked as final" ) ; return sb . toString ( ) ; } else { return null ; } return null ; }
Return a String with a message indicating why the given path is final .