Enum Direction

java.lang.Object
  extended by java.lang.Enum<Direction>
      extended by Direction
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Direction>

public enum Direction
extends java.lang.Enum<Direction>

Cardinal direction on a grid.


Enum Constant Summary
EAST
           
NORTH
           
SOUTH
           
WEST
           
 
Method Summary
 java.awt.Point forward(java.awt.Point p)
          The point one step forward in this direction.
abstract  java.awt.Point forward(java.awt.Point p, int n)
          The point n steps forward in this direction.
static Direction fromTo(java.awt.Point a, java.awt.Point b)
          Returns the larger direction from a to b, favoring the vertical.
 boolean isHorizontal()
          True for East and West
 boolean isVertical()
          True for North and South
abstract  Direction left()
          The direction 90-degrees to the left.
 int numTurns(Direction d)
          The number of turns needed to reach direction d from this direction.
abstract  Direction opposite()
          Returns the direction 180 degrees from this one.
static Direction random()
          Uniformly distributed random direction.
abstract  Direction right()
          The direction 90-degrees to the right.
abstract  int toInt()
          Returns a number between 0 and 3: EAST = 0, NORTH = 1, ...
static Direction valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static Direction[] values()
          Returns an array containing the constants of this enum type, in the order they're declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

NORTH

public static final Direction NORTH

WEST

public static final Direction WEST

SOUTH

public static final Direction SOUTH

EAST

public static final Direction EAST
Method Detail

values

public static final Direction[] values()
Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants as follows:
for(Direction c : Direction.values())
        System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they're declared

valueOf

public static Direction valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name

random

public static Direction random()
Uniformly distributed random direction.


left

public abstract Direction left()
The direction 90-degrees to the left.


right

public abstract Direction right()
The direction 90-degrees to the right.


isHorizontal

public boolean isHorizontal()
True for East and West


isVertical

public boolean isVertical()
True for North and South


numTurns

public int numTurns(Direction d)
The number of turns needed to reach direction d from this direction.


fromTo

public static Direction fromTo(java.awt.Point a,
                               java.awt.Point b)
Returns the larger direction from a to b, favoring the vertical.


opposite

public abstract Direction opposite()
Returns the direction 180 degrees from this one.


forward

public java.awt.Point forward(java.awt.Point p)
The point one step forward in this direction.


forward

public abstract java.awt.Point forward(java.awt.Point p,
                                       int n)
The point n steps forward in this direction.


toInt

public abstract int toInt()
Returns a number between 0 and 3: EAST = 0, NORTH = 1, ...