diff --git a/polyglot-common/src/main/java/org/sonatype/maven/polyglot/PolyglotModelManager.java b/polyglot-common/src/main/java/org/sonatype/maven/polyglot/PolyglotModelManager.java index 582a5988..65eda3fa 100644 --- a/polyglot-common/src/main/java/org/sonatype/maven/polyglot/PolyglotModelManager.java +++ b/polyglot-common/src/main/java/org/sonatype/maven/polyglot/PolyglotModelManager.java @@ -9,7 +9,6 @@ import java.io.File; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -42,17 +41,12 @@ public void addMapping(final Mapping mapping) { mappings.add(mapping); } + private static final Comparator DESCENDING_PRIORITY = Comparator.comparingDouble(Mapping::getPriority).reversed(); + public List getSortedMappings() { - List sortedMappings = new ArrayList(mappings); - - Collections.sort(sortedMappings, Collections.reverseOrder(new Comparator() { - @Override - public int compare(Mapping o1, Mapping o2) { - return Float.compare(o1.getPriority(), o2.getPriority()); - } - })); - - return sortedMappings; + List sortedMappings = new ArrayList<>(mappings); + sortedMappings.sort(DESCENDING_PRIORITY); + return sortedMappings; } public ModelReader getReaderFor(final Map options) { @@ -84,36 +78,27 @@ public ModelWriter getWriterFor(final Map options) { throw new RuntimeException("Unable to determine model output format; options=" + options); } - public File findPom(final File dir) { + public File findPom(final File dir) { assert dir != null; - File pomFile = null; - float currentPriority = Float.MIN_VALUE; - for (Mapping mapping : mappings) { + for (Mapping mapping : getSortedMappings()) { File file = mapping.locatePom(dir); - if (file != null && (pomFile == null || mapping.getPriority() > currentPriority)) { - pomFile = file; - currentPriority = mapping.getPriority(); + if (file != null) { + return file; } } - - return pomFile; + return null; } public String determineFlavourFromPom(final File dir) { assert dir != null; - - String flavour = null; - float mappingPriority = Float.MIN_VALUE; - for (Mapping mapping : mappings) { + for (Mapping mapping : getSortedMappings()) { File file = mapping.locatePom(dir); - if (file != null && (flavour == null || mappingPriority < mapping.getPriority())) { - flavour = mapping.getFlavour(); - mappingPriority = mapping.getPriority(); + if (file != null) { + return mapping.getFlavour(); } } - - return flavour; + return null; } public String getFlavourFor(final Map options) {