efegokdemir commented on code in PR #184:
URL: https://github.com/apache/maven-shared-jar/pull/184#discussion_r4234430479


##########
src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalysis.java:
##########
@@ -80,53 +80,44 @@ public JarIdentification analyze(JarAnalyzer jarAnalyzer) {
 
     private void normalize(JarIdentification taxon) {
         if (StringUtils.isEmpty(taxon.getGroupId())) {
-            taxon.setGroupId(pickSmallest(taxon.getPotentialGroupIds()));
+            taxon.setGroupId(pickUnambiguous(taxon.getPotentialGroupIds()));
         }
 
         if (StringUtils.isEmpty(taxon.getArtifactId())) {
-            taxon.setArtifactId(pickLargest(taxon.getPotentialArtifactIds()));
+            
taxon.setArtifactId(pickUnambiguous(taxon.getPotentialArtifactIds()));
         }
 
         if (StringUtils.isEmpty(taxon.getVersion())) {
-            taxon.setVersion(pickSmallest(taxon.getPotentialVersions()));
+            taxon.setVersion(pickUnambiguous(taxon.getPotentialVersions()));
         }
 
         if (StringUtils.isEmpty(taxon.getName())) {
-            taxon.setName(pickLargest(taxon.getPotentialNames()));
+            taxon.setName(pickUnambiguous(taxon.getPotentialNames()));
         }
 
         if (StringUtils.isEmpty(taxon.getVendor())) {
-            taxon.setVendor(pickLargest(taxon.getPotentialVendors()));
+            taxon.setVendor(pickUnambiguous(taxon.getPotentialVendors()));
         }
     }
 
-    private String pickSmallest(List<String> list) {
-        String smallest = null;
-
-        int size = Integer.MAX_VALUE;
-        for (String val : list) {
-            if (val != null && !val.isEmpty()) {
-                if (val.length() < size) {
-                    smallest = val;
-                    size = val.length();
-                }
+    /**
+     * Returns the value when there is at most one distinct non-empty 
candidate, or {@code null} when candidates

Review Comment:
   Repository-search results were being passed to `addAndSet*` one at a time, 
so the last hash hit could overwrite conflicting candidates and appear 
validated. They are now recorded as potential values; normalization uses a 
single candidate when unambiguous and leaves conflicting values unset. I added 
regressions for one match and conflicting matches. 
`JarIdentificationAnalyzerTest` passes (8 tests), and Checkstyle, Spotless 
(Java 21) and `git diff --check` pass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to