public static List < String > getAllAncestors ( String eventPath ) { // check if the path is valid. if ( eventPath == null || ! eventPath . startsWith ( Path . SEPARATOR ) ) { return null ; } if ( eventPath . equals ( Path . SEPARATOR ) ) { return Arrays . asList ( Path . SEPARATOR ) ; } List < String > ancestors = new ArrayList < String > ( ) ; while ( eventPath . length ( ) > 0 ) { ancestors . add ( eventPath ) ; eventPath = eventPath . substring ( 0 , eventPath . lastIndexOf ( Path . SEPARATOR ) ) ; } // add the root directory ancestors . add ( Path . SEPARATOR ) ; return ancestors ; }
return all the ancestors of the given path include itself .