private static String normalize ( final List < String > path , boolean absolute ) { assert path != null : "path must be specified" ; // Remove unnecessary references to this dir if ( path . contains ( DIR_THIS ) ) { path . remove ( DIR_THIS ) ; normalize ( path , absolute ) ; } // Remove unnecessary references to the back dir, and its parent final int indexDirBack = path . indexOf ( DIR_BACK ) ; if ( indexDirBack != - 1 ) { if ( indexDirBack > 0 ) { path . remove ( indexDirBack ) ; path . remove ( indexDirBack - 1 ) ; normalize ( path , absolute ) ; } else { throw new IllegalArgumentException ( "Cannot specify to go back \"../\" past the root" ) ; } } // Nothing left to do; reconstruct final StringBuilder sb = new StringBuilder ( ) ; if ( absolute ) { sb . append ( ArchivePath . SEPARATOR ) ; } for ( int i = 0 ; i < path . size ( ) ; i ++ ) { if ( i > 0 ) { sb . append ( ArchivePath . SEPARATOR ) ; } sb . append ( path . get ( i ) ) ; } return sb . toString ( ) ; }
Normalizes the tokenized view of the path