List<Resource> result;
if ("latest".equals(rangeStr)) {
Version highest = versionMap.lastKey();
result = Create.list(new Resource[] { versionMap.get(highest) });
} else {
VersionRange range = rangeStr != null ? new VersionRange(rangeStr) : null;
// optimisation: skip versions definitely less than the range
if (range != null && range.getLow() != null)
versionMap = versionMap.tailMap(range.getLow());
result = new ArrayList<Resource>(versionMap.size());
for (Version version : versionMap.keySet()) {
if (range == null || range.includes(version))
result.add(versionMap.get(version));
// optimisation: skip versions definitely higher than the range
if (range != null && range.isRange() && version.compareTo(range.getHigh()) >= 0)
break;
}
}
return result;
}