public static QPath getCommonAncestorPath ( QPath firstPath , QPath secondPath ) throws PathNotFoundException { if ( ! firstPath . getEntries ( ) [ 0 ] . equals ( secondPath . getEntries ( ) [ 0 ] ) ) { throw new PathNotFoundException ( "For the given ways there is no common ancestor." ) ; } List < QPathEntry > caEntries = new ArrayList < QPathEntry > ( ) ; for ( int i = 0 ; i < firstPath . getEntries ( ) . length ; i ++ ) { if ( firstPath . getEntries ( ) [ i ] . equals ( secondPath . getEntries ( ) [ i ] ) ) { caEntries . add ( firstPath . getEntries ( ) [ i ] ) ; } else { break ; } } return new QPath ( caEntries . toArray ( new QPathEntry [ caEntries . size ( ) ] ) ) ; }
Get common ancestor path .