public class Location
extends java.lang.Object
implements java.lang.Comparable
Location
object represents the row and column of a location
in a two-dimensional grid. Modifier and Type | Field and Description |
---|---|
static int |
AHEAD
The turn angle for making no turn.
|
static int |
EAST
The compass direction for east.
|
static int |
FULL_CIRCLE
The turn angle for turning a full circle.
|
static int |
HALF_CIRCLE
The turn angle for turning a half circle.
|
static int |
HALF_LEFT
The turn angle for turning 45 degrees to the left.
|
static int |
HALF_RIGHT
The turn angle for turning 45 degrees to the right.
|
static int |
LEFT
The turn angle for turning 90 degrees to the left.
|
static int |
NORTH
The compass direction for north.
|
static int |
NORTHEAST
The compass direction for northeast.
|
static int |
NORTHWEST
The compass direction for northwest.
|
static int |
RIGHT
The turn angle for turning 90 degrees to the right.
|
static int |
SOUTH
The compass direction for south.
|
static int |
SOUTHEAST
The compass direction for southeast.
|
static int |
SOUTHWEST
The compass direction for southwest.
|
static int |
WEST
The compass direction for west.
|
Constructor and Description |
---|
Location(int r,
int c)
Constructs a location with given row and column coordinates.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.lang.Object other)
Compares this location to
other for ordering. |
boolean |
equals(java.lang.Object other)
Indicates whether some other
Location object is "equal to"
this one. |
Location |
getAdjacentLocation(int direction)
Gets the adjacent location in any one of the eight compass directions.
|
int |
getCol()
Gets the column coordinate.
|
int |
getDirectionToward(Location target)
Returns the direction from this location toward another location.
|
int |
getRow()
Gets the row coordinate.
|
int |
hashCode()
Generates a hash code.
|
java.lang.String |
toString()
Creates a string that describes this location.
|
public static final int LEFT
public static final int RIGHT
public static final int HALF_LEFT
public static final int HALF_RIGHT
public static final int FULL_CIRCLE
public static final int HALF_CIRCLE
public static final int AHEAD
public static final int NORTH
public static final int NORTHEAST
public static final int EAST
public static final int SOUTHEAST
public static final int SOUTH
public static final int SOUTHWEST
public static final int WEST
public static final int NORTHWEST
public Location(int r, int c)
r
- the rowc
- the columnpublic int getRow()
public int getCol()
public Location getAdjacentLocation(int direction)
direction
- the direction in which to find a neighbor locationpublic int getDirectionToward(Location target)
target
- a location that is different from this locationtarget
public boolean equals(java.lang.Object other)
Location
object is "equal to"
this one.equals
in class java.lang.Object
other
- the other location to testtrue
if other
is a
Location
with the same row and column as this location;
false
otherwisepublic int hashCode()
hashCode
in class java.lang.Object
public int compareTo(java.lang.Object other)
other
for ordering. Returns a
negative integer, zero, or a positive integer as this location is less
than, equal to, or greater than other
. Locations are
ordered in row-major order. other
is a Location
object.)compareTo
in interface java.lang.Comparable
other
- the other location to testother
, zero if the two locations are equal, or a positive
integer if this location is greater than other
public java.lang.String toString()
toString
in class java.lang.Object