question: public static List < String > findBestTrailMatch ( List < List < String > > trails , List < String > matchTrail , boolean containFullTrail , boolean exact ) { List < String > best = null ; int partMatches = 0 ; for ( List < String > candidateTrail : trails ) { int candidatePartMatches = 0 ; Iterator < String > candidateIt = candidateTrail . iterator ( ) ; Iterator < String > matchIt = matchTrail . iterator ( ) ; while ( candidateIt . hasNext ( ) && matchIt . hasNext ( ) ) { String candidatePart = candidateIt . next ( ) ; String matchPart = matchIt . next ( ) ; if ( candidatePart . equals ( matchPart ) ) { candidatePartMatches ++ ; } else { break ; } } if ( candidatePartMatches == matchTrail . size ( ) && matchTrail . size ( ) == candidateTrail . size ( ) ) { return candidateTrail ; } else { if ( candidatePartMatches > partMatches ) { partMatches = candidatePartMatches ; best = candidateTrail ; } } } if ( exact ) { return null ; } else { if ( containFullTrail ) { if ( partMatches >= matchTrail . size ( ) ) { return best ; } else { return null ; } } else { return best ; } } }
target:  Finds best trail match. <p> If containFullTrail true, returns null if the best trail match does not fully contain the match trail; if false, this will return the longest-path match found. If exact true, has to match exactly.