private boolean addCoveringPath ( String newPath ) { int newLen = newPath . length ( ) ; Iterator < String > useCoveringPaths = coveringPaths . iterator ( ) ; boolean isCovered = false ; boolean isCovering = false ; while ( ! isCovered && useCoveringPaths . hasNext ( ) ) { String coveringPath = useCoveringPaths . next ( ) ; int coveringLen = coveringPath . length ( ) ; if ( coveringLen < newLen ) { if ( isCovering ) { continue ; // Can't be covered. } else { if ( newPath . regionMatches ( 0 , coveringPath , 0 , coveringLen ) ) { if ( newPath . charAt ( coveringLen ) == ' ' ) { isCovered = true ; // Covered: "covering/child" vs "covering" break ; // No need to continue: Can't be any additional relationships to find. } else { continue ; // Dissimilar: "coveringX" vs "covering" } } else { continue ; // Dissimilar: "coverXngX" vs "covering" } } } else if ( coveringLen == newLen ) { if ( isCovering ) { continue ; // Can't be covered } else { if ( newPath . regionMatches ( 0 , coveringPath , 0 , coveringLen ) ) { isCovered = true ; // Covered: "covering" vs "covering" break ; // No need to continue: Can't be any additional relationships to find. } else { continue ; // "covering" vs "coverXng" } } } else { // coveringLen > newLen if ( newPath . regionMatches ( 0 , coveringPath , 0 , newLen ) ) { if ( coveringPath . charAt ( newLen ) == ' ' ) { isCovering = true ; useCoveringPaths . remove ( ) ; // Covering: "covering" vs "covering/child" continue ; // Look for other independent children: "covering/child1" and "covering/child2" } else { continue ; // Dissimilar: "covering" vs "coveringX" } } else { continue ; // Dissimilar: "covering" vs "coverXngX" } } } if ( ! isCovered ) { coveringPaths . add ( newPath ) ; } return ! isCovered ; }
Add a path to the covering paths collection .