diff gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java @ 798:6cff63d0c434

Fixed vim modeline. Added some Javadoc. gnv-artifacts/trunk@880 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 06 Apr 2010 11:05:00 +0000
parents c4156275c1e1
children d766fe2d917a
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java	Tue Apr 06 07:01:03 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java	Tue Apr 06 11:05:00 2010 +0000
@@ -3,22 +3,41 @@
 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;
@@ -27,13 +46,28 @@
         }
     }
 
+    /**
+     * Hashes i and j into a common value.
+     * @return
+     */
+    @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:
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org