Package net.sf.freecol.common.model
Enum Direction
- java.lang.Object
-
- java.lang.Enum<Direction>
-
- net.sf.freecol.common.model.Direction
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<Direction>
allDirections
static java.util.List<Direction>
corners
private int
evenDX
private int
evenDY
static java.util.List<Direction>
longSides
static int
NUMBER_OF_DIRECTIONS
private int
oddDX
The direction increments.private int
oddDY
-
Constructor Summary
Constructors Modifier Constructor Description private
Direction(int oddDX, int oddDY, int evenDX, int evenDY)
Create a new direction with the given increments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Direction
angleToDirection(double angle)
Convert an angle (radians) to a direction.Direction[]
getClosestDirections(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Creates an array of the directions in an order that favours a supplied one.Direction
getEWMirroredDirection()
Gets the direction with east-west part mirrored.java.lang.String
getKey()
Get a message key for this direction.java.lang.String
getNameKey()
Gets the name of this named object.Direction
getNextDirection()
Get the next direction after this one (clockwise).Direction
getPreviousDirection()
Get the previous direction after this one (anticlockwise).static Direction
getRandomDirection(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Gets a random Direction.static Direction[]
getRandomDirections(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Creates an array of the eight directions in a random order.Direction
getReverseDirection()
Gets the reverse direction of this one.Direction
rotate(int n)
Gets this direction rotated by n places.Map.Position
step(int x, int y)
Step the x and y coordinates in this direction.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 are declared.
-
-
-
Enum Constant Detail
-
N
public static final Direction N
-
NE
public static final Direction NE
-
E
public static final Direction E
-
SE
public static final Direction SE
-
S
public static final Direction S
-
SW
public static final Direction SW
-
W
public static final Direction W
-
NW
public static final Direction NW
-
-
Field Detail
-
NUMBER_OF_DIRECTIONS
public static final int NUMBER_OF_DIRECTIONS
-
allDirections
public static final java.util.List<Direction> allDirections
-
longSides
public static final java.util.List<Direction> longSides
-
corners
public static final java.util.List<Direction> corners
-
oddDX
private final int oddDX
The direction increments.
-
oddDY
private final int oddDY
-
evenDX
private final int evenDX
-
evenDY
private final int evenDY
-
-
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(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 namejava.lang.NullPointerException
- if the argument is null
-
step
public Map.Position step(int x, int y)
Step the x and y coordinates in this direction.- Parameters:
x
- The x coordinate.y
- The y coordinate.- Returns:
- The map position after the step.
-
rotate
public Direction rotate(int n)
Gets this direction rotated by n places.- Parameters:
n
- The number of places to rotate (-#directions ≤ n ≤ #directions).- Returns:
- The rotated direction.
-
getNextDirection
public Direction getNextDirection()
Get the next direction after this one (clockwise).- Returns:
- The next
Direction
.
-
getPreviousDirection
public Direction getPreviousDirection()
Get the previous direction after this one (anticlockwise).- Returns:
- The previous
Direction
.
-
getReverseDirection
public Direction getReverseDirection()
Gets the reverse direction of this one.- Returns:
- The reverse
Direction
.
-
getEWMirroredDirection
public Direction getEWMirroredDirection()
Gets the direction with east-west part mirrored.- Returns:
- The mirrored
Direction
.
-
getRandomDirection
public static Direction getRandomDirection(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Gets a random Direction.- Parameters:
logMe
- A string to log with the random results.logger
- ALogger
to log to.random
- ARandom
number source.- Returns:
- A random
Direction
value.
-
getRandomDirections
public static Direction[] getRandomDirections(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Creates an array of the eight directions in a random order.- Parameters:
logMe
- A string to log with the random results.logger
- ALogger
to log to.random
- ARandom
number source.- Returns:
- An array of the
Direction
s in a random order.
-
getClosestDirections
public Direction[] getClosestDirections(java.lang.String logMe, java.util.logging.Logger logger, java.util.Random random)
Creates an array of the directions in an order that favours a supplied one. Entry 0 will be the supplied direction, entry 1+2 will be those immediately to the left and right of it (chosen randomly), and so on until the last entry will be the complete reverse of the supplied direction. Useful if we want to travel in a particular direction, but if this fails to be able to try the closest other directions to the original one in order.- Parameters:
logMe
- A string to log with the random results.logger
- ALogger
to log to.random
- ARandom
number source.- Returns:
- An array of the
Direction
s favouring this one.
-
angleToDirection
public static Direction angleToDirection(double angle)
Convert an angle (radians) to a direction.- Parameters:
angle
- The angle to convert.- Returns:
- An equivalent
Direction
.
-
getKey
public java.lang.String getKey()
Get a message key for this direction.- Returns:
- A suitable message key.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
-