eppleton commented on code in PR #9834:
URL: https://github.com/apache/netbeans/pull/9834#discussion_r4726219664


##########
ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootKeys.java:
##########
@@ -86,12 +93,18 @@ Collection<PrjInfo> getKeys() {
         var projects = Arrays.asList(listProjects());
         projects.sort(OpenProjectList.projectByPath());
 
-        var dirs = new ArrayList<PrjInfo>(projects.size());
-        final java.util.Map<Project,ProjectsRootKeys.PrjInfo> snapshot = new 
HashMap<>();
-        var nested = new LinkedList<FileObject>();
+        Comparator<PrjInfo> byProjectDisplayName = (i1, i2) -> {

Review Comment:
   The children are collected in a `TreeSet` with this comparator, and a 
`TreeSet` treats `compare(...) == 0` as "same element": the second project with 
an equal display name is silently not added. That is easy to hit at the top 
level, e.g. two checkouts of the same repository, or two Maven projects that 
are both called `demo` or `parent`. The project is still open and in 
`snapshot`, but it disappears from the Projects window. Before 5c58a521b the 
list was sorted with `List.sort(projectByDisplayName())`, so equal names 
stayed. A tiebreak on the project directory (e.g. falling back to 
`projectByPath()`) would keep the sets distinct.
   
   The test only uses distinct names (`Last parent` / `First parent`, ...), so 
it doesn't cover this.



##########
ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootKeys.java:
##########
@@ -86,12 +93,18 @@ Collection<PrjInfo> getKeys() {
         var projects = Arrays.asList(listProjects());
         projects.sort(OpenProjectList.projectByPath());
 
-        var dirs = new ArrayList<PrjInfo>(projects.size());
-        final java.util.Map<Project,ProjectsRootKeys.PrjInfo> snapshot = new 
HashMap<>();
-        var nested = new LinkedList<FileObject>();
+        Comparator<PrjInfo> byProjectDisplayName = (i1, i2) -> {
+            String n1 = 
ProjectUtils.getInformation(i1.project()).getDisplayName();
+            String n2 = 
ProjectUtils.getInformation(i2.project()).getDisplayName();
+            return n1.compareTo(n2);

Review Comment:
   Two differences to the `ProjectByDisplayNameComparator` that was removed in 
5c58a521b:
   
   - it compared with `Collator.getInstance()`. `String.compareTo` sorts all 
upper-case names before lower-case ones (`Zeta` before `alpha`) and orders 
accented characters by code point, so the order in #9813 would still look wrong 
for mixed-case names.
   - it handled a `null` display name (with a warning); here `n1.compareTo(n2)` 
throws an NPE for a misbehaving `ProjectInformation`.
   
   It also memoized the display names. Here `getDisplayName()` is called on 
every comparison, which for Maven projects is not completely free.



##########
ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootKeys.java:
##########
@@ -24,10 +24,17 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.LinkedHashMap;

Review Comment:
   Minor: `LinkedHashMap`, `SortedMap` and `TreeMap` are imported but not used.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to