question: public static String cleanPath ( String path ) { if ( path == null ) { return null ; } String pathToUse = replace ( path , WINDOWS_FOLDER_SEPARATOR , FOLDER_SEPARATOR ) ; int prefixIndex = pathToUse . indexOf ( ":" ) ; String prefix = "" ; if ( prefixIndex != - 1 ) { prefix = pathToUse . substring ( 0 , prefixIndex + 1 ) ; pathToUse = pathToUse . substring ( prefixIndex + 1 ) ; } if ( pathToUse . startsWith ( FOLDER_SEPARATOR ) ) { prefix = prefix + FOLDER_SEPARATOR ; pathToUse = pathToUse . substring ( 1 ) ; } String [ ] pathArray = delimitedListToStringArray ( pathToUse , FOLDER_SEPARATOR ) ; List < String > pathElements = new LinkedList < > ( ) ; int tops = 0 ; for ( int i = pathArray . length - 1 ; i >= 0 ; i -- ) { String element = pathArray [ i ] ; if ( CURRENT_PATH . equals ( element ) ) { } else if ( TOP_PATH . equals ( element ) ) { tops ++ ; } else { if ( tops > 0 ) { tops -- ; } else { pathElements . add ( 0 , element ) ; } } } for ( int i = 0 ; i < tops ; i ++ ) { pathElements . add ( 0 , TOP_PATH ) ; } return prefix + collectionToDelimitedString ( pathElements , FOLDER_SEPARATOR ) ; }
target:  Normalize the path by suppressing sequences like "path/.." and inner simple dots. <p>The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.