Description: Fixup compareTo function in Rule class to be compliant
 with the Java 7 (and Java 6) API. Comparisons where not symmetric
 with the upstream handling in this function:
 .
    r1 > r2 but ! r2 < r1
 .
 Also added extra tests to ensure that comparison works both ways.
Author: James Page <james.page@ubuntu.com>
Forwarded: no
Bug-Debian: http://bugs.debian.org/673765
--- a/src/java/org/dom4j/rule/Rule.java
+++ b/src/java/org/dom4j/rule/Rule.java
@@ -99,16 +99,16 @@
      * @return DOCUMENT ME!
      */
     public int compareTo(Rule that) {
-        int answer = this.importPrecedence - that.importPrecedence;
-
-        if (answer == 0) {
-            answer = (int) Math.round(this.priority - that.priority);
-
-            if (answer == 0) {
-                answer = this.appearenceCount - that.appearenceCount;
-            }
+        int answer = 0;
+        if (this.importPrecedence != that.importPrecedence) {
+            answer = this.importPrecedence < that.importPrecedence ? -1 : 1;
+        }
+        else if (Double.compare(this.priority, that.priority) != 0) {
+            answer = Double.compare(this.priority, that.priority);
+        }
+        else if (this.appearenceCount != that.appearenceCount) {
+            answer = this.appearenceCount < that.appearenceCount ? -1 : 1;
         }
-
         return answer;
     }
 
--- a/src/test/org/dom4j/rule/RuleTest.java
+++ b/src/test/org/dom4j/rule/RuleTest.java
@@ -48,6 +48,18 @@
 
         assertTrue("r1 > r2", value > 0);
 
+        value = r2.compareTo(r1);
+
+        System.out.println("Comparison: " + value);
+
+        assertTrue("r2 < r1", value < 0);
+
+        value = r1.compareTo(r1);
+
+        System.out.println("Comparison: " + value);
+
+        assertTrue("r1 == r1", value == 0);
+
         ArrayList list = new ArrayList();
         list.add(r1);
         list.add(r2);
