]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Fix SVN issues
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
index 505a71060c706267930fb35099342b49512a2b07..7a90133d6418a01434be38fe3ef7a3cafcd128d2 100644 (file)
@@ -1,5 +1,7 @@
 package org.argeo.slc.core.test.tree;\r
 \r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
 import java.util.Date;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -10,6 +12,9 @@ import java.util.Vector;
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
 import org.argeo.slc.SlcException;\r
+import org.argeo.slc.core.attachment.Attachment;\r
+import org.argeo.slc.core.attachment.AttachmentsEnabled;\r
+import org.argeo.slc.core.attachment.SimpleAttachment;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.structure.StructureAware;\r
 import org.argeo.slc.structure.StructureElement;\r
@@ -25,7 +30,9 @@ import org.argeo.slc.test.TestRunAware;
  * structure.\r
  */\r
 public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
-               Comparable<TreeTestResult> {\r
+               Comparable<TreeTestResult>, AttachmentsEnabled, Serializable {\r
+       private static final long serialVersionUID = 1L;\r
+\r
        private Log log = LogFactory.getLog(TreeTestResult.class);\r
 \r
        private List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
@@ -43,6 +50,7 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
 \r
        private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
        private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
+       private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();\r
 \r
        private Map<String, String> attributes = new TreeMap<String, String>();\r
 \r
@@ -193,16 +201,44 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
        public int compareTo(TreeTestResult ttr2) {\r
                TreeTestResult ttr1 = this;\r
                if (ttr1.getCloseDate() != null && ttr2.getCloseDate() != null) {\r
-                       return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate());\r
+                       if (ttr1.getCloseDate().equals(ttr2.getCloseDate()))\r
+                               return compareUuid(ttr1, ttr2);\r
+                       else\r
+                               return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate());\r
                } else if (ttr1.getCloseDate() != null && ttr2.getCloseDate() == null) {\r
                        return 1;\r
                } else if (ttr1.getCloseDate() == null && ttr2.getCloseDate() != null) {\r
                        return -1;\r
                } else {\r
+                       return compareUuid(ttr1, ttr2);\r
+               }\r
+       }\r
+\r
+       protected int compareUuid(TestResult ttr1, TestResult ttr2) {\r
+               if (ttr1.getUuid() == null || ttr2.getUuid() == null)\r
+                       throw new SlcException(\r
+                                       "Cannot compare tree test result with null uuid");\r
+               else {\r
+                       if (ttr1.getUuid().equals(ttr2.getUuid()))\r
+                               return 0;\r
                        return ttr1.getUuid().compareTo(ttr2.getUuid());\r
                }\r
        }\r
 \r
+       public boolean equals(Object obj) {\r
+               if (obj instanceof TestResult)\r
+                       return compareUuid(this, ((TestResult) obj)) == 0;\r
+               else\r
+                       return false;\r
+       }\r
+\r
+       public int hashCode() {\r
+               if (uuid != null)\r
+                       return uuid.hashCode();\r
+               else\r
+                       return super.hashCode();\r
+       }\r
+\r
        public Map<String, String> getAttributes() {\r
                return attributes;\r
        }\r
@@ -215,4 +251,23 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                this.warnIfAlreadyClosed = warnIfAlreadyClosed;\r
        }\r
 \r
+       public List<SimpleAttachment> getAttachments() {\r
+               return attachments;\r
+       }\r
+\r
+       public void setAttachments(List<SimpleAttachment> attachments) {\r
+               this.attachments = attachments;\r
+       }\r
+\r
+       public void addAttachment(Attachment attachment) {\r
+               attachments.add((SimpleAttachment) attachment);\r
+               synchronized (listeners) {\r
+                       for (TestResultListener<TreeTestResult> listener : listeners) {\r
+                               if (listener instanceof TreeTestResultListener)\r
+                                       ((TreeTestResultListener) listener).addAttachment(this,\r
+                                                       attachment);\r
+                       }\r
+               }\r
+       }\r
+\r
 }\r