comparison 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
comparison
equal deleted inserted replaced
722:bb3ffe7d719e 875:5e9efdda6894
1 package de.intevation.gnv.math;
2
3 import java.io.Serializable;
4
5 /**
6 * Tuple (i, j) to model a pair of integers. Useful to store index pairs
7 * in maps.
8 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
9 */
10 public class IJKey
11 implements Serializable
12 {
13 /**
14 * i component of the tuple.
15 */
16 public int i;
17 /**
18 * j component of the tuple.
19 */
20 public int j;
21
22 /**
23 * Default constructor.
24 */
25 public IJKey() {
26 }
27
28 /**
29 * Constructor to set i and j.
30 * @param i The i component.
31 * @param j The j component.
32 */
33 public IJKey(int i, int j) {
34 this.i = i;
35 this.j = j;
36 }
37
38 /**
39 * Orders i and j by their values.
40 */
41 public void sort() {
42 if (i > j) {
43 int t = i;
44 i = j;
45 j = t;
46 }
47 }
48
49 /**
50 * Hashes i and j into a common value.
51 * @return the hash code.
52 */
53 @Override
54 public int hashCode() {
55 return (i << 16) | j;
56 }
57
58 /**
59 * IJKeys are considered equal if the i and j components
60 * are equal.
61 * @param obj The other IJKey
62 * @return true if the IJKeys are equal else false.
63 */
64 @Override
65 public boolean equals(Object obj) {
66 if (!(obj instanceof IJKey)) {
67 return false;
68 }
69 IJKey other = (IJKey)obj;
70 return i == other.i && j == other.j;
71 }
72 }
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org