You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/09/16 09:09:46 UTC

[isis] branch master updated: ISIS-2426: tooling: reasonable sorting for ProjectNode

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 305edfb  ISIS-2426: tooling: reasonable sorting for ProjectNode
305edfb is described below

commit 305edfbd353656c91d2c82d777c77d9209d39278
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Sep 16 11:09:26 2020 +0200

    ISIS-2426: tooling: reasonable sorting for ProjectNode
---
 commons/pom.xml                                    |  2 +-
 .../isis/tooling/projectmodel/ProjectNode.java     | 40 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/commons/pom.xml b/commons/pom.xml
index a6431ce..dcd6934 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -26,7 +26,7 @@
 
 	<name>Apache Isis Commons</name>
 	<description>
-        Isis library, defining utilities required by the entire Apache Isis ecosystem.
+        Isis library, defining utilities (potentially) required by the entire Apache Isis ecosystem.
     </description>
 
 	<properties>
diff --git a/tooling/projectmodel/src/main/java/org/apache/isis/tooling/projectmodel/ProjectNode.java b/tooling/projectmodel/src/main/java/org/apache/isis/tooling/projectmodel/ProjectNode.java
index f972adc..ed35481 100644
--- a/tooling/projectmodel/src/main/java/org/apache/isis/tooling/projectmodel/ProjectNode.java
+++ b/tooling/projectmodel/src/main/java/org/apache/isis/tooling/projectmodel/ProjectNode.java
@@ -23,11 +23,12 @@ import java.util.TreeSet;
 
 import lombok.Builder;
 import lombok.Data;
+import lombok.NonNull;
 import lombok.ToString;
 import lombok.val;
 
 @Data @Builder
-public class ProjectNode {
+public class ProjectNode implements Comparable<ProjectNode> {
 
     @ToString.Exclude private final ProjectNode parent;
     @ToString.Exclude private final TreeSet<ProjectNode> children = new TreeSet<ProjectNode>(
@@ -39,12 +40,47 @@ public class ProjectNode {
     private final String description;
     private final File projectDirectory;
     
-    public void depthFirst(ProjectVisitor projectVisitor) {
+    public void depthFirst(final @NonNull ProjectVisitor projectVisitor) {
         projectVisitor.accept(this);
         for(val child : getChildren()){
             child.depthFirst(projectVisitor);
         }
     }
+
+    public boolean contains(final @NonNull ProjectNode other) {
+        for(val child : getChildren()){
+            if(child.containsOrEquals(other)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public boolean containsOrEquals(final @NonNull ProjectNode other) {
+        if(this.getArtifactKey().equals(other.getArtifactKey())) {
+            return true;
+        }
+        for(val child : getChildren()){
+            if(child.containsOrEquals(other)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    // -- COMPARATOR
+    
+    @Override
+    public int compareTo(ProjectNode other) {
+        if(this.contains(other)) {
+            return -1;
+        }
+        if(other.contains(this)) {
+            return 1;
+        }
+        return this.getArtifactKey().compareTo(other.getArtifactKey());
+    }
+    
    
     
 }