sascha@431: package de.intevation.gnv.math; sascha@431: sascha@431: import java.io.Serializable; sascha@431: sascha@431: /** sascha@798: * Tuple (i, j) to model a pair of integers. Useful to store index pairs sascha@798: * in maps. sascha@780: * @author Sascha L. Teichmann sascha@431: */ sascha@431: public class IJKey sascha@431: implements Serializable sascha@431: { sascha@798: /** sascha@798: * i component of the tuple. sascha@798: */ sascha@431: public int i; sascha@798: /** sascha@798: * j component of the tuple. sascha@798: */ sascha@431: public int j; sascha@431: sascha@798: /** sascha@798: * Default constructor. sascha@798: */ sascha@431: public IJKey() { sascha@431: } sascha@431: sascha@798: /** sascha@798: * Constructor to set i and j. sascha@798: * @param i The i component. sascha@798: * @param j The j component. sascha@798: */ sascha@431: public IJKey(int i, int j) { sascha@431: this.i = i; sascha@431: this.j = j; sascha@431: } sascha@431: sascha@798: /** sascha@798: * Orders i and j by their values. sascha@798: */ sascha@437: public void sort() { sascha@437: if (i > j) { sascha@437: int t = i; sascha@437: i = j; sascha@437: j = t; sascha@437: } sascha@437: } sascha@437: sascha@798: /** sascha@798: * Hashes i and j into a common value. sascha@801: * @return the hash code. sascha@798: */ sascha@798: @Override sascha@431: public int hashCode() { sascha@431: return (i << 16) | j; sascha@431: } sascha@431: sascha@798: /** sascha@798: * IJKeys are considered equal if the i and j components sascha@798: * are equal. sascha@798: * @param obj The other IJKey sascha@798: * @return true if the IJKeys are equal else false. sascha@798: */ sascha@798: @Override sascha@431: public boolean equals(Object obj) { sascha@798: if (!(obj instanceof IJKey)) { sascha@798: return false; sascha@798: } sascha@431: IJKey other = (IJKey)obj; sascha@431: return i == other.i && j == other.j; sascha@431: } sascha@431: } sascha@798: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :