org.moyoman.module.loosegroups.simplelgimpl
Class StoneDistance

java.lang.Object
  |
  +--org.moyoman.module.loosegroups.simplelgimpl.StoneDistance
All Implemented Interfaces:
Comparable

class StoneDistance
extends Object
implements Comparable

This class is used to represent the distance between two stones. It implements the Comparable interface, so objects of this type can be automatically sorted by a SortedSet object.


Field Summary
private  short distance
          The square of the distance between two stones.
private  short hor
          The horizontal distance between the two stones.
private  Stone stone1
          One of the stones.
private  Stone stone2
          The other stone.
private  short vert
          The vertical distance between the two stones.
 
Constructor Summary
protected StoneDistance(Stone s1, Stone s2)
          Create the StoneDistance object.
 
Method Summary
protected  int compare(int h, int v)
          Compare the distance of the current object with that specified by the two parameters.
 int compareTo(Object o)
          This method implements the Comparable interface.
private  short getDistance()
          Get the square of the distance between the two stones.
protected  short getHorizontal()
          Get the horizontal distance between the two stones.
protected  Stone getStone1()
          Get the first stone.
protected  Stone getStone2()
          Get the second stone.
protected  short getVertical()
          Get the vertical distance between the two stones.
 String toString()
          Return a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hor

private short hor
The horizontal distance between the two stones.


vert

private short vert
The vertical distance between the two stones.


distance

private short distance
The square of the distance between two stones.


stone1

private Stone stone1
One of the stones.


stone2

private Stone stone2
The other stone.

Constructor Detail

StoneDistance

protected StoneDistance(Stone s1,
                        Stone s2)
Create the StoneDistance object.

Parameters:
s1 - One of the stones.
s2 - The other stone.
Method Detail

getStone1

protected Stone getStone1()
Get the first stone.

Returns:
A Stone object.

getStone2

protected Stone getStone2()
Get the second stone.

Returns:
A Stone object.

getHorizontal

protected short getHorizontal()
Get the horizontal distance between the two stones.

Returns:
A short which is the horizontal distance between the two stones.

getVertical

protected short getVertical()
Get the vertical distance between the two stones.

Returns:
A short which is the vertical distance between the two stones.

getDistance

private short getDistance()
Get the square of the distance between the two stones.

Returns:
A short which is the square of the distance between the two stones.

compare

protected int compare(int h,
                      int v)
Compare the distance of the current object with that specified by the two parameters.

Parameters:
h - The horizontal distance between two stones.
v - The vertical distance between two stones.
Returns:
An int, which is -1 if this object has a shorter distance, 0 is the two have the same distance, or 1 if this object has a longer distance.

toString

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

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

compareTo

public int compareTo(Object o)
This method implements the Comparable interface.

Specified by:
compareTo in interface Comparable
Parameters:
o - The object being compared with this one.
Returns:
-1 if this object is smaller, 0 if the two are the same, or 1.