comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/IJKey.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.math;
10
11 import java.io.Serializable;
12
13 /**
14 * Tuple (i, j) to model a pair of integers. Useful to store index pairs
15 * in maps.
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
17 */
18 public class IJKey
19 implements Serializable
20 {
21 /**
22 * i component of the tuple.
23 */
24 public int i;
25 /**
26 * j component of the tuple.
27 */
28 public int j;
29
30 /**
31 * Default constructor.
32 */
33 public IJKey() {
34 }
35
36 /**
37 * Constructor to set i and j.
38 * @param i The i component.
39 * @param j The j component.
40 */
41 public IJKey(int i, int j) {
42 this.i = i;
43 this.j = j;
44 }
45
46 /**
47 * Orders i and j by their values.
48 */
49 public void sort() {
50 if (i > j) {
51 int t = i;
52 i = j;
53 j = t;
54 }
55 }
56
57 /**
58 * Hashes i and j into a common value.
59 * @return the hash code.
60 */
61 @Override
62 public int hashCode() {
63 return (i << 16) | j;
64 }
65
66 /**
67 * IJKeys are considered equal if the i and j components
68 * are equal.
69 * @param obj The other IJKey
70 * @return true if the IJKeys are equal else false.
71 */
72 @Override
73 public boolean equals(Object obj) {
74 if (!(obj instanceof IJKey)) {
75 return false;
76 }
77 IJKey other = (IJKey)obj;
78 return i == other.i && j == other.j;
79 }
80 }
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org