util
Enum Direction

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

public enum Direction
extends Enum<Direction>
implements Orientation

Representation of the four directional orientations: up, right, down, and left.

Version:
April 25, 2007

Enum Constant Summary
DOWN
           
LEFT
           
RIGHT
           
UP
           
 
Method Summary
 Direction clockwise()
          Returns the next clockwise rotation.
 Direction counterClockwise()
          Returns the next counter-clockwise rotation.
static Direction fromString(String str)
          Returns the enum representation of a string.
 Point getOffset(Point loc)
          Returns a point offset in this direction according to inverted cartesian coordinates (the same as Graphics objects).
 boolean isVertical()
          Returns if the direction concerns vertical or horizontal directions.
static Direction random()
          Returns a random direction.
 Direction reverse()
          Returns the opposite facing direction.
 String toString()
           
static Direction valueOf(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 are declared.
 
Methods inherited from class java.lang.Enum
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

UP

public static final Direction UP

RIGHT

public static final Direction RIGHT

DOWN

public static final Direction DOWN

LEFT

public static final Direction LEFT
Method Detail

values

public static Direction[] values()
Returns an array containing the constants of this enum type, in the order they are 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 are declared

valueOf

public static Direction valueOf(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:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

fromString

public static Direction fromString(String str)
Returns the enum representation of a string. This is case sensitive.

Parameters:
str - toString representation of this enum
Returns:
enum associated with a string
Throws:
IllegalArgumentException - if argument is not represented by this enum.

random

public static Direction random()
Returns a random direction.

Returns:
randomly generated direction

clockwise

public Direction clockwise()
Description copied from interface: Orientation
Returns the next clockwise rotation.

Specified by:
clockwise in interface Orientation
Returns:
next clockwise orientation

counterClockwise

public Direction counterClockwise()
Description copied from interface: Orientation
Returns the next counter-clockwise rotation.

Specified by:
counterClockwise in interface Orientation
Returns:
next counter-clockwise orientation

reverse

public Direction reverse()
Description copied from interface: Orientation
Returns the opposite facing direction.

Specified by:
reverse in interface Orientation
Returns:
opposing direction

getOffset

public Point getOffset(Point loc)
Description copied from interface: Orientation
Returns a point offset in this direction according to inverted cartesian coordinates (the same as Graphics objects). In other words coordinates grow toward the lower-right, with shifts as follows: Up = -Y Down = +Y Left = -X Right = +X

Specified by:
getOffset in interface Orientation
Parameters:
loc - location to be offset
Returns:
shifted point

isVertical

public boolean isVertical()
Returns if the direction concerns vertical or horizontal directions.

Returns:
true if enum is up or down, false otherwise

toString

public String toString()
Overrides:
toString in class Enum<Direction>