Added some more JUnit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / model / impl / SessionInfo.java
index ac6464762fd9da1e9115018077cf6b74ca1cebcc..5d074b1783be29e0b2df039a8417fc2c0414925e 100644 (file)
@@ -158,21 +158,45 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
     public void addDomain(IDomainInfo domainInfo) {
         fDomains.add(domainInfo);
     }
-    
+
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode()
+     * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#formatString()
      */
     @Override
-    public int hashCode() {
-        int result = 17;
-        result = 37 * result + super.hashCode();
-        result = 37 * result + fSessionPath.hashCode();
-        result = 37 * result + fState.hashCode();
+    @SuppressWarnings("nls")
+    public String formatString() {
+        StringBuffer output = new StringBuffer();
+        // Tracing session mysession: [active]
+        output.append("Tracing session ");
+        output.append(getName());
+        output.append(": [");
+        output.append(getSessionState().getInName());
+        output.append("]\n");
+        
+        //    Trace path: /home/user/lttng-traces/mysession-20120129-084256
+        output.append("    Trace path: ");
+        output.append(getSessionPath());
+        output.append("\n");
+        
         for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
             IDomainInfo domain = (IDomainInfo) iterator.next();
-            result = 37 * result + domain.hashCode();
+            output.append(domain.formatString());
         }
+        return output.toString();
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((fDomains == null) ? 0 : fDomains.hashCode());
+        result = prime * result + ((fSessionPath == null) ? 0 : fSessionPath.hashCode());
+        result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1));
         return result;
     }
 
@@ -181,34 +205,37 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
      * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
      */
     @Override
-    public boolean equals(Object other) {
-        if (!(other instanceof SessionInfo)) {
-            return false;
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
         }
-        SessionInfo otherInfo = (SessionInfo) other;
-        if (!super.equals(otherInfo)) {
+        if (!super.equals(obj)) {
             return false;
         }
-
-        if (!fSessionPath.equals(otherInfo.fSessionPath)) {
+        if (getClass() != obj.getClass()) {
             return false;
         }
-        
-        if (fState.ordinal() != otherInfo.fState.ordinal()) {
-            return false;
-        }
-        
-        if (fDomains.size() != otherInfo.fDomains.size()) {
+        SessionInfo other = (SessionInfo) obj;
+        if (fDomains == null) {
+            if (other.fDomains != null) {
+                return false;
+            }
+        } else if (!fDomains.equals(other.fDomains)) {
             return false;
         }
-        for (int i = 0; i < fDomains.size(); i++) {
-            if (!fDomains.get(i).equals(otherInfo.fDomains.get(i))) {
+        if (fSessionPath == null) {
+            if (other.fSessionPath != null) {
                 return false;
             }
+        } else if (!fSessionPath.equals(other.fSessionPath)) {
+            return false;
+        }
+        if (fState != other.fState) {
+            return false;
         }
         return true;
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString()
@@ -223,8 +250,8 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
             output.append(fState);
             output.append(",Domains=");
             for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
-                IDomainInfo channel = (IDomainInfo) iterator.next();
-                output.append(channel.toString());
+                IDomainInfo domain = (IDomainInfo) iterator.next();
+                output.append(domain.toString());
             }
             output.append(")]");
             return output.toString();
This page took 0.025544 seconds and 5 git commands to generate.