/* * Index2D.java * * Copyright (c) 2009 by Kevin McGuinness */ package ie.dcu.matrix; import java.io.Serializable; /** * An immutable class encapsulating a two dimensional index. * * @author Kevin McGuinness */ public final class Index2D implements Serializable { /** * Serialization UID. */ private static final long serialVersionUID = 2722263604670361463L; /** * The row index. */ public final int i; /** * The column index. */ public final int j; /** * Create an two dimensional index for the given co-ordinates. * * @param i * The row index. * @param j * The column index. */ public Index2D(int i, int j) { this.i = i; this.j = j; } /** * Returns true if the passed object is an Index2D and both objects are * have equal values. */ @Override public boolean equals(Object o) { if (o instanceof Index2D) { Index2D index = (Index2D) o; return i == index.i && j == index.j; } return false; } /** * Returns the hash code. */ @Override public int hashCode() { return (i ^ j); } /** * Returns a string of the form i,j */ public String toString() { return String.format("%d,%d", i, j); } }