JAL-3048 jalview.utils.dialogrunner.DialogRunner allows sequences of runnable methods...
[jalview.git] / src / jalview / util / dialogrunner / Response.java
diff --git a/src/jalview/util/dialogrunner/Response.java b/src/jalview/util/dialogrunner/Response.java
new file mode 100644 (file)
index 0000000..15df8f8
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util.dialogrunner;
+
+public class Response
+{
+  int type = 0; // int = 0, String = 1, Object = 2;
+
+  int intresp;
+
+  String stringresp;
+
+  Object objresp;
+
+  public Response(int response)
+  {
+    type = 0;
+    intresp = response;
+  }
+
+  public Response(String response)
+  {
+    type = 1;
+    stringresp = response;
+  }
+
+  public Response(Object response)
+  {
+    if (response instanceof String)
+    {
+      type = 1;
+      stringresp = (String) response;
+      return;
+    }
+    if (response instanceof Integer)
+    {
+      type = 0;
+      intresp = ((Integer) response).intValue();
+      return;
+    }
+    objresp = response;
+    type = 2;
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (obj == null || !(obj instanceof Response))
+    {
+      return false;
+    }
+    ;
+    if (((Response) obj).type == type)
+    {
+      switch (type)
+      {
+      case 0:
+        return ((((Response) obj).intresp) == intresp);
+      case 1:
+        return (((Response) obj).stringresp.equals(stringresp));
+      case 2:
+        return (((Response) obj).objresp).equals(objresp);
+      }
+    }
+    return false;
+  }
+
+  @Override
+  public int hashCode()
+  {
+    switch (type)
+    {
+    case 0:
+      return Integer.valueOf(intresp).hashCode();
+    case 1:
+      return stringresp.hashCode();
+    case 2:
+      return objresp.hashCode();
+    }
+    return super.hashCode();
+  }
+
+  @Override
+  public String toString()
+  {
+    switch (type)
+    {
+    case 0:
+      return "DialogRunner int: " + intresp;
+    case 1:
+      return "DialogRunner str: '" + stringresp + "'";
+    case 2:
+      return "DialogRunner obj: " + objresp.toString();
+    }
+    return "Unconfigured response.";
+  }
+}
\ No newline at end of file