org.moyoman.util
Class Stone

java.lang.Object
  |
  +--org.moyoman.util.Point
        |
        +--org.moyoman.util.Stone
All Implemented Interfaces:
Cloneable, Serializable
Direct Known Subclasses:
NumberedStone, PartialStone

public class Stone
extends Point
implements Serializable

This class represents one stone. It is either black, white, or empty, and has a horizontal and vertical position between 0 and 18.

See Also:
Serialized Form

Field Summary
private static Stone[][] blackStones
          All of the black stone objects that are instantiated.
private  Color color
          The color of the stone.
private static Stone[][] emptyStones
          All of the empty stone objects that are instantiated.
private static Stone[][] whiteStones
          All of the white stone objects that are instantiated.
 
Fields inherited from class org.moyoman.util.Point
 
Constructor Summary
protected Stone(Color c, int x, int y)
          Create the Stone object.
protected Stone(Stone s)
          Create the Stone object.
 
Method Summary
 Stone castToStone()
          Get the Stone object corresponding to this one.
 Object clone()
          Clone this object.
 boolean equals(Object o)
          Comprare the object with this Stone object.
static Stone get(Color c, int x, int y)
          Get the Stone object with these attributes.
static Stone get(Color c, Point pt)
          Get the Stone object with these attributes.
 Stone[] getAdjacentStonesOfSameColor()
          Get the stones of the same color immediately adjacent to this one.
 Color getColor()
          Return the color of the stone.
 int hashCode()
          Get the hash code for this object.
 String toString()
          Return a String representation of this object.
 
Methods inherited from class org.moyoman.util.Point
castToPoint, get, getAdjacentPoints, getConcentricPoints, getX, getY, isInCorner, isOnSide
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

color

private Color color
The color of the stone.


blackStones

private static final Stone[][] blackStones
All of the black stone objects that are instantiated.


whiteStones

private static final Stone[][] whiteStones
All of the white stone objects that are instantiated.


emptyStones

private static final Stone[][] emptyStones
All of the empty stone objects that are instantiated.

Constructor Detail

Stone

protected Stone(Color c,
                int x,
                int y)
         throws IllegalArgumentException
Create the Stone object.

Parameters:
c - The color of the stone.
x - The horizontal position, between 0 and 18.
y - The vertical position, between 0 and 18.
Throws:
IllegalArgumentException - Thrown if the x or y parameters are out of range.

Stone

protected Stone(Stone s)
Create the Stone object. The purpose of this constructor might seem confusing. It can be used by derived classes like NumberedStone when creating a new object of the derived class type.

Parameters:
s - The Stone object.
Method Detail

get

public static Stone get(Color c,
                        int x,
                        int y)
Get the Stone object with these attributes.

Parameters:
c - - The color of the stone to retrieve.
x - - The x coordinate of the stone.
y - - The y coordinate of the stone.
Returns:
A Stone object.

get

public static Stone get(Color c,
                        Point pt)
Get the Stone object with these attributes.

Parameters:
c - - The color of the stone to retrieve.
pt - - The point at which to get the Stone.
Returns:
A Stone object.

castToStone

public Stone castToStone()
Get the Stone object corresponding to this one. This is similar to the Point.castToPoint() method. If this object is of type Stone, then it is returned. If it is a derived class, such as NumberedStone, then the Stone object of the same color and x and y coordinates is returned.

Returns:
A Stone object.

getColor

public Color getColor()
Return the color of the stone.

Returns:
The color of the stone.

getAdjacentStonesOfSameColor

public Stone[] getAdjacentStonesOfSameColor()
Get the stones of the same color immediately adjacent to this one. These Stone object do not necessarily correspond to any actual board position. There is one Stone object returned for each adjacent point which is on the board, regardless of the actual Stone there.

Returns:
An array of Stone objects.

hashCode

public int hashCode()
Get the hash code for this object. Make sure that the hash code is not the same as that for any Point object.

Overrides:
hashCode in class Point
Returns:
An int which is the hash code.

equals

public boolean equals(Object o)
Comprare the object with this Stone object.

Overrides:
equals in class Point
Parameters:
o - The object being compared.
Returns:
true if the two objects are the same, or false.

clone

public Object clone()
Clone this object. Since the flyweight pattern is used for Stone objects, this method just returns the current object.

Overrides:
clone in class Point
Returns:
A Stone object.

toString

public String toString()
Return a String representation of this object.

Overrides:
toString in class Point
Returns:
A String which represents this object.