[sikuli] 169/385: added/fixed Comparable

Gilles Filippini pini at moszumanska.debian.org
Sun Jun 29 19:26:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

pini pushed a commit to tag upstream/1.1.0_beta1
in repository sikuli.

commit fa3d2392ae60004d4af9fbac90693ba08e6019d7
Author: Raimund Hocke <rmhdevelop at me.com>
Date:   Mon Jan 20 19:40:30 2014 +0100

    added/fixed Comparable
---
 API/src/main/java/org/sikuli/script/Location.java | 29 ++++++++++++++++++++++-
 API/src/main/java/org/sikuli/script/Match.java    |  7 +++---
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/API/src/main/java/org/sikuli/script/Location.java b/API/src/main/java/org/sikuli/script/Location.java
index 89d3b92..40432df 100755
--- a/API/src/main/java/org/sikuli/script/Location.java
+++ b/API/src/main/java/org/sikuli/script/Location.java
@@ -16,7 +16,7 @@ import java.awt.Rectangle;
  * any screen (not checked as is done with region)
  *
  */
-public class Location {
+public class Location implements Comparable<Location>{
   
   public int x;
   public int y;
@@ -378,6 +378,33 @@ public class Location {
     return this;
   }
 
+  @Override
+  public boolean equals(Object oThat) {
+    if (this == oThat) {
+      return true;
+    }
+    if (!(oThat instanceof Location)) {
+      return false;
+    }
+    Location that = (Location) oThat;
+    return x == that.x && y == that.y; 
+  }
+
+  @Override
+  public int compareTo(Location l) {
+    if (equals(l)) {
+      return 0;
+    }
+    if (l.x > x) {
+      return 1;
+    } else if (l.x == x) {
+      if (l.y > y) {
+        return 1;
+      }
+    }
+    return -1;        
+  }
+
   /**
    * {@inheritDoc}
    * @return the description
diff --git a/API/src/main/java/org/sikuli/script/Match.java b/API/src/main/java/org/sikuli/script/Match.java
index 4cd6728..97d8e53 100755
--- a/API/src/main/java/org/sikuli/script/Match.java
+++ b/API/src/main/java/org/sikuli/script/Match.java
@@ -17,7 +17,7 @@ import org.sikuli.natives.FindResult;
  * from Pattern)<br> the filename of the used image<br>or the text used for
  * findX text
  */
-public class Match extends Region implements Comparable {
+public class Match extends Region implements Comparable<Match> {
 
   private double simScore;
   private Location target = null;
@@ -186,8 +186,7 @@ public class Match extends Region implements Comparable {
   }
 
   @Override
-  public int compareTo(Object o) {
-    Match m = (Match) o;
+  public int compareTo(Match m) {
     if (simScore != m.simScore) {
       return simScore < m.simScore ? -1 : 1;
     }
@@ -203,7 +202,7 @@ public class Match extends Region implements Comparable {
     if (h != m.h) {
       return h - m.h;
     }
-    if (equals(o)) {
+    if (equals(m)) {
       return 0;
     }
     return -1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git



More information about the pkg-java-commits mailing list