JAL-3518 more test coverage for structure commands
[jalview.git] / src / jalview / structure / StructureCommand.java
index f7875ab..0a7000b 100644 (file)
@@ -72,4 +72,55 @@ public class StructureCommand implements StructureCommandI
     return sb.toString();
   }
 
+  @Override
+  public int hashCode()
+  {
+    int h = command.hashCode();
+    if (parameters != null)
+    {
+      for (String p : parameters)
+      {
+        h = h * 37 + p.hashCode();
+      }
+    }
+    return h;
+  }
+
+  /**
+   * Answers true if {@code obj} is a {@code StructureCommand} with the same
+   * command and parameters as this one, else false
+   */
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (obj == null || !(obj instanceof StructureCommand))
+    {
+      return false;
+    }
+    StructureCommand sc = (StructureCommand) obj;
+
+    if (!command.equals(sc.command))
+    {
+      return false;
+    }
+    if (parameters == null || sc.parameters == null)
+    {
+      return (parameters == null) && (sc.parameters == null);
+    }
+
+    int j = parameters.size();
+    if (j != sc.parameters.size())
+    {
+      return false;
+    }
+    for (int i = 0; i < j; i++)
+    {
+      if (!parameters.get(i).equals(sc.parameters.get(i)))
+      {
+        return false;
+      }
+    }
+    return true;
+  }
+
 }