List of usage examples for org.apache.commons.lang StringUtils indexOfDifference
public static int indexOfDifference(String[] strs)
Compares all Strings in an array and returns the index at which the Strings begin to differ.
From source file:org.overlord.sramp.shell.TabCompleter.java
/** * Merge candidates.//from w ww. java 2s . c o m * * @param completionCandidates * the completion candidates * @param buffer * the buffer * @return the string */ private String mergeCandidates(List<String> completionCandidates, String buffer) { if (completionCandidates.size() > 1) { int indexOfDifference = StringUtils .indexOfDifference(completionCandidates.toArray(new String[completionCandidates.size()])); if (indexOfDifference == -1) { return completionCandidates.get(0); } else { String partToCompare = ""; //$NON-NLS-1$ String commonPart = completionCandidates.get(0).substring(0, indexOfDifference); if (commonPart.startsWith(buffer)) { partToCompare = buffer; } else { partToCompare = buffer.substring(buffer.lastIndexOf(" ") + 1); //$NON-NLS-1$ } if (partToCompare.length() != indexOfDifference) { return commonPart; } } } return ""; //$NON-NLS-1$ }