diff gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java @ 875:5e9efdda6894

merged gnv-artifacts/1.0
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:56 +0200
parents d766fe2d917a
children f953c9a559d8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java	Fri Sep 28 12:13:56 2012 +0200
@@ -0,0 +1,73 @@
+package de.intevation.gnv.math;
+
+import java.io.Serializable;
+
+/**
+ * Tuple (i, j) to model a pair of integers. Useful to store index pairs
+ * in maps.
+ * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
+ */
+public class IJKey
+implements   Serializable
+{
+    /**
+     * i component of the tuple.
+     */
+    public int i;
+    /**
+     * j component of the tuple.
+     */
+    public int j;
+
+    /**
+     * Default constructor.
+     */
+    public IJKey() {
+    }
+
+    /**
+     * Constructor to set i and j.
+     * @param i The i component.
+     * @param j The j component.
+     */
+    public IJKey(int i, int j) {
+        this.i = i;
+        this.j = j;
+    }
+
+    /**
+     * Orders i and j by their values.
+     */
+    public void sort() {
+        if (i > j) {
+            int t = i;
+            i = j;
+            j = t;
+        }
+    }
+
+    /**
+     * Hashes i and j into a common value.
+     * @return the hash code.
+     */
+    @Override
+    public int hashCode() {
+        return (i << 16) | j;
+    }
+
+    /**
+     * IJKeys are considered equal if the i and j components
+     * are equal.
+     * @param obj The other IJKey
+     * @return true if the IJKeys are equal else false.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof IJKey)) {
+            return false;
+        }
+        IJKey other = (IJKey)obj;
+        return i == other.i && j == other.j;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org