util
Enum HexDirection

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

public enum HexDirection
extends Enum<HexDirection>
implements Orientation

Represents the six directions out of a horizontal hexagon. hexGrid.png

Version:
January 7, 2008

Enum Constant Summary
DOWN
           
LOWER_LEFT
           
LOWER_RIGHT
           
UP
           
UPPER_LEFT
           
UPPER_RIGHT
           
 
Method Summary
 HexDirection clockwise()
          Returns the next clockwise rotation.
 HexDirection counterClockwise()
          Returns the next counter-clockwise rotation.
static HexDirection 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 isUpper()
          Returns if the direction has an upward orientation (upper left, up, or upper right).
static HexDirection random()
          Returns a random hexagonal direction.
 HexDirection reverse()
          Returns the opposite facing direction.
 String toString()
           
static HexDirection valueOf(String name)
          Returns the enum constant of this type with the specified name.
static HexDirection[] 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 HexDirection UP

UPPER_RIGHT

public static final HexDirection UPPER_RIGHT

LOWER_RIGHT

public static final HexDirection LOWER_RIGHT

DOWN

public static final HexDirection DOWN

LOWER_LEFT

public static final HexDirection LOWER_LEFT

UPPER_LEFT

public static final HexDirection UPPER_LEFT
Method Detail

values

public static HexDirection[] 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 (HexDirection c : HexDirection.values())
    System.out.println(c);

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

valueOf

public static HexDirection 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 HexDirection 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 HexDirection random()
Returns a random hexagonal direction.

Returns:
randomly generated direction

clockwise

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

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

counterClockwise

public HexDirection 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 HexDirection 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

isUpper

public boolean isUpper()
Returns if the direction has an upward orientation (upper left, up, or upper right).

Returns:
true if enum is an upward orientation, false otherwise

toString

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