Enum Move
java.lang.Object
java.lang.Enum<Move>
Move
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable<Move>
public enum Move
- extends java.lang.Enum<Move>
An enumerative type that defines legal moves on a two-dimensional grid.
One could use integers or characters to represent moves. For example, 1,
2, 3, 4 could designate up, down, left and right. However, the compiler would
not be able to detect errors such as move = 5, because 5 is a
valid value for an integer. By using an enumerative type, that kind of
errors can be detected at compile-time.
Field Summary |
static Move[] |
moves
Caching the array to avoid regenerating it several times |
Method Summary |
static Move |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. |
static Move[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared. |
Methods inherited from class java.lang.Enum |
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Up
public static final Move Up
Down
public static final Move Down
Left
public static final Move Left
Right
public static final Move Right
moves
public static final Move[] moves
- Caching the array to avoid regenerating it several times
values
public static Move[] 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 (Move c : Move.values())
System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in
the order they are declared
valueOf
public static Move 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
java.lang.NullPointerException
- if the argument is null