/** * Given a list of ModuleDependencies (of the same groupId and artifactId), * picks the {@link ModuleDependency} that satisfies the constraint and has the highest version. * * @param candidates * List that represents specific (non-range) versions. * @return The highest satisfying ModuleDependency or null if none can be found. */ public ModuleDependency findHighestFrom(Collection<ModuleDependency> candidates) { //Create a sorted map of the ModuleDependnecies sorted on version (descending order). SortedMap<ArtifactVersion, ModuleDependency> sorted = new TreeMap<ArtifactVersion, ModuleDependency>(new ReverseComparator()); for (ModuleDependency candidate : candidates) { sorted.put(candidate.parseVersion(), candidate); } //Now find the highest version that satisfies this dependency. for (ModuleDependency e : sorted.values()) { if (contains(e)) return e; } // non found return null; }