org.moyoman.util
Class Color

java.lang.Object
  |
  +--org.moyoman.util.Color
All Implemented Interfaces:
Cloneable, Serializable

public class Color
extends Object
implements Cloneable, Serializable

This class represents the color of a point on the board. It may be black, white, or empty.

See Also:
Serialized Form

Field Summary
static Color BLACK
           
private static short BLACK_FLAG
          The short value representing black.
private  short color
          The color that this object encapsulates.
static Color EMPTY
           
private static short EMPTY_FLAG
          The short value representing an empty point.
static Color WHITE
           
private static short WHITE_FLAG
          The short value representing white.
 
Constructor Summary
private Color(short val)
          Create a Color object with the appopriate value.
 
Method Summary
 Object clone()
          Clone the Color object.
 boolean equals(Object o)
          Determine whether an object is equal to this one.
 Color flip()
          Return the opposite color of the current color.
 int hashCode()
          Return a hashcode for this object.
 boolean isBlack()
          Return true if the color is black.
 boolean isEmpty()
          Return true if the color is empty.
 boolean isWhite()
          Return true if the color is white.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BLACK_FLAG

private static final short BLACK_FLAG
The short value representing black.

See Also:
Constant Field Values

WHITE_FLAG

private static final short WHITE_FLAG
The short value representing white.

See Also:
Constant Field Values

EMPTY_FLAG

private static final short EMPTY_FLAG
The short value representing an empty point.

See Also:
Constant Field Values

BLACK

public static final Color BLACK

WHITE

public static final Color WHITE

EMPTY

public static final Color EMPTY

color

private short color
The color that this object encapsulates.

Constructor Detail

Color

private Color(short val)
       throws IllegalArgumentException
Create a Color object with the appopriate value.

Throws:
IllegalArgumentException - Thrown if the val parameter does not contain one of the legal values defined for the Color class.
Method Detail

isBlack

public boolean isBlack()
Return true if the color is black.

Returns:
true if the color is black, or false.

isWhite

public boolean isWhite()
Return true if the color is white.

Returns:
true if the color is white, or false.

isEmpty

public boolean isEmpty()
Return true if the color is empty.

Returns:
true if the color is empty, or false.

toString

public String toString()
Overrides:
toString in class Object

flip

public Color flip()
Return the opposite color of the current color. It is an error to call this method on Color.EMPTY.

Returns:
A Color object.
Throws:
InconsistentStateException - - Thrown if the current color is empty.

hashCode

public int hashCode()
Return a hashcode for this object. It is important that all Color objects with the same value have the same hashcode value.

Overrides:
hashCode in class Object
Returns:
An int which is the hashcode value.

equals

public boolean equals(Object o)
Determine whether an object is equal to this one. This is true if the other object is a Color object, and the same color as this object.

Overrides:
equals in class Object
Parameters:
o - The object to be compared to this one.
Returns:
True if the objects are the same, or false.

clone

public Object clone()
Clone the Color object. Since Color objects are reused, just return the current object.

Overrides:
clone in class Object
Returns:
The current object.