in src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java [90:132]
public List<String> preParse(final List<String> original) {
final HashMap<String, Integer> existingEntries = new HashMap<>();
final ListIterator<String> iter = original.listIterator();
while (iter.hasNext()) {
final String entry = iter.next().trim();
final MatchResult result;
final Matcher matcher = PATTERN.matcher(entry);
if (matcher.matches()) {
result = matcher.toMatchResult();
final String name = result.group(1);
final String version = result.group(2);
final Integer nv = Integer.valueOf(version);
final Integer existing = existingEntries.get(name);
if (null != existing && nv.intValue() < existing.intValue()) {
iter.remove(); // removes older version from original list.
continue;
}
existingEntries.put(name, nv);
}
}
// we've now removed all entries less than with less than the largest
// version number for each name that were listed after the largest.
// we now must remove those with smaller than the largest version number
// for each name that were found before the largest
while (iter.hasPrevious()) {
final String entry = iter.previous().trim();
MatchResult result = null;
final Matcher matcher = PATTERN.matcher(entry);
if (matcher.matches()) {
result = matcher.toMatchResult();
final String name = result.group(1);
final String version = result.group(2);
final int nv = Integer.parseInt(version);
final Integer existing = existingEntries.get(name);
if (null != existing && nv < existing.intValue()) {
iter.remove(); // removes older version from original list.
}
}
}
return original;
}