From 006e76d24c1d6ea465fef2a5958133b712a7ca3d Mon Sep 17 00:00:00 2001
From: Starla Insigna <hatkirby@fourisland.com>
Date: Tue, 17 Feb 2009 15:35:18 -0500
Subject: Engine: Abstracted Comparsion

---
 .../precondition/VariableNumberPrecondition.java   |  9 +--
 .../precondition/VariableVariablePrecondition.java | 12 ++--
 src/com/fourisland/fourpuzzle/util/Comparison.java | 77 ++++++++++++++++++++--
 3 files changed, 78 insertions(+), 20 deletions(-)

diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java
index ab8d977..c3016e0 100755
--- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java
+++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java
@@ -33,13 +33,8 @@ public class VariableNumberPrecondition implements Precondition {
         {
             int n1 = Game.getSaveFile().getVariables().get(variableID);
             int n2 = number;
-            
-            switch (comparison)
-            {
-                case Less: return (n1 < n2);
-                case Greater: return (n1 > n2);
-                case Equal: return (n1 == n2);
-            }
+
+            return comparison.compare(n1, n2);
         }
         
         return false;
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java
index 91a31ba..da16d09 100755
--- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java
+++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java
@@ -31,14 +31,12 @@ public class VariableVariablePrecondition implements Precondition {
     {
         if (Game.getSaveFile().getVariables().containsKey(variableID))
         {
-            int n1 = Game.getSaveFile().getVariables().get(variableID);
-            int n2 = Game.getSaveFile().getVariables().get(variableID2);
-            
-            switch (comparison)
+            if (Game.getSaveFile().getVariables().containsKey(variableID2))
             {
-                case Less: return (n1 < n2);
-                case Greater: return (n1 > n2);
-                case Equal: return (n1 == n2);
+                int n1 = Game.getSaveFile().getVariables().get(variableID);
+                int n2 = Game.getSaveFile().getVariables().get(variableID2);
+
+                return comparison.compare(n1, n2);
             }
         }
         
diff --git a/src/com/fourisland/fourpuzzle/util/Comparison.java b/src/com/fourisland/fourpuzzle/util/Comparison.java
index 9e5ef54..79bcb28 100755
--- a/src/com/fourisland/fourpuzzle/util/Comparison.java
+++ b/src/com/fourisland/fourpuzzle/util/Comparison.java
@@ -1,20 +1,85 @@
-package com.fourisland.fourpuzzle.util;
-
 /*
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
 
-
+package com.fourisland.fourpuzzle.util;
 
 /**
  *
  * @author hatkirby
  */
 public enum Comparison {
-    
-    Less,
-    Greater,
+    /**
+     * A comparision that returns true if param a is less than param b.
+     */
+    Less
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a < b);
+        }
+    },
+    /**
+     * A comparision that returns true if param a is greater than param b.
+     */
+    Greater
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a > b);
+        }
+    },
+    /**
+     * A comparision that returns true if param a is equal to param b.
+     */
     Equal
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a == b);
+        }
+    },
+    /**
+     * A comparision that returns true if param a is greater than or equal to
+     * param b.
+     */
+    Above
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a >= b);
+        }
+    },
+    /**
+     * A comparision that returns true if param a is less than or equal to
+     * param b.
+     */
+    Below
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a <= b);
+        }
+    },
+    /**
+     * A comparison that returns true if param a is not equal to param b.
+     */
+    Inequal
+    {
+        public boolean compare(int a, int b)
+        {
+            return (a != b);
+        }
+    };
+    
+    /**
+     * Compares both parameters
+     * 
+     * @param a The first number to compare
+     * @param b The second number to compare
+     * @return true if <code>a COMPARE b</code> is true, otherwise false
+     */
+    public abstract boolean compare(int a, int b);
 
 }
-- 
cgit 1.4.1