
// Location.java
// Andrew Davison, Nov 2018, ad@fivedots.coe.psu.ac.th

/* Represent a location in a rectangular grid.
 * 
 * @author David J. Barnes and Michael Kolling
 * @version 2006.03.30
 */


public class Location
{
  private int row, col;


  public Location(int r, int c)
  { row = r;
    col = c;
  }
    

  public boolean equals(Object obj)
  // implements content equality
  {
    if (obj instanceof Location) {
      Location other = (Location) obj;
      return ((row == other.getRow()) && (col == other.getCol()));
    }
    else
      return false;
  }  // end of equals()
    

  public String toString()
  {  return row + "," + col;  }
    

  public int hashCode()
  /* Use the top 16 bits for the row value and the bottom for
     the column. Except for very big grids, this should give a
     unique hash code for each (row, col) pair. */
  {  return (row << 16) + col;  }
    

  public int getRow()
  {  return row;  }

  public int getCol()
  {  return col; }

}  // end of Location class
