fix javadoc header
[fanfix.git] / src / jexer / event / TCommandEvent.java
index cdb5e2d6a70140232fa006d9fc59d0ac15588f37..e93a941984b48e4a595e131606639d808409cf5f 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Jexer - Java Text User Interface
  *
  * License: LGPLv3 or later
@@ -62,6 +62,45 @@ public final class TCommandEvent extends TInputEvent {
         this.cmd = cmd;
     }
 
+    /**
+     * Comparison check.  All fields must match to return true.
+     *
+     * @param rhs another TCommandEvent or TCommand instance
+     * @return true if all fields are equal
+     */
+    @Override
+    public boolean equals(final Object rhs) {
+        if (!(rhs instanceof TCommandEvent)
+            && !(rhs instanceof TCommand)
+        ) {
+            return false;
+        }
+
+        if (rhs instanceof TCommandEvent) {
+            TCommandEvent that = (TCommandEvent) rhs;
+            return (cmd.equals(that.cmd)
+                && (getTime().equals(that.getTime())));
+        }
+
+        TCommand that = (TCommand) rhs;
+        return (cmd.equals(that));
+    }
+
+    /**
+     * Hashcode uses all fields in equals().
+     *
+     * @return the hash
+     */
+    @Override
+    public int hashCode() {
+        int A = 13;
+        int B = 23;
+        int hash = A;
+        hash = (B * hash) + getTime().hashCode();
+        hash = (B * hash) + cmd.hashCode();
+        return hash;
+    }
+
     /**
      * Make human-readable description of this TCommandEvent.
      *