[Dive4elements-commits] [PATCH 1 of 2] Add hashCode and equals implementation to Range

Wald Commits scm-commit at wald.intevation.org
Thu Jun 20 08:51:50 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1371627638 -7200
# Node ID 01073acf6735b05c296a384c7be410acc0c8093a
# Parent  19459037b3c72c637bae95246f10841da473a250
Add hashCode and equals implementation to Range.

diff -r 19459037b3c7 -r 01073acf6735 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java	Wed Jun 19 15:03:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java	Wed Jun 19 09:40:38 2013 +0200
@@ -69,5 +69,25 @@
     public boolean inside(double x) {
         return x > start-EPSILON && x < end+EPSILON;
     }
+
+    @Override
+    public int hashCode() {
+        return new Double(this.start).hashCode() ^
+               new Double(this.end).hashCode();
+    }
+
+    @Override
+    public boolean equals(Object otherRange) {
+        if (otherRange == null) {
+            return false;
+        }
+        else if (otherRange instanceof Range) {
+            Range oRange = (Range) otherRange;
+            return
+                Math.abs(oRange.start - this.start) <= EPSILON
+                && Math.abs(oRange.end - this.end) <= EPSILON;
+        }
+        return false;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list