net.pacbell.jfai.toh.domain
Class Disk

java.lang.Object
  extended by java.util.Observable
      extended by net.pacbell.jfai.toh.domain.Disk
All Implemented Interfaces:
Comparable

public class Disk
extends Observable
implements Comparable

Disks are stacked to form a tower.


Constructor Summary
Disk(int size, Pin pin)
          Create an instance with the given size and located at the given Pin.
 
Method Summary
 void changePinTo(Pin aPin)
          Move the receiver from the current pin to the given pin.
 int compareTo(Object o)
          Interface Comparable: Compare the receiver with the argument.
 boolean equals(Object obj)
          
 Pin getPin()
          Gets the pin.
 int getSize()
          Gets the size.
 int hashCode()
          
 void moveTo(Pin target)
          Remove the receiver from the top of the current pin and add it to the top of the specified pin.
 void remove()
          Remove the receiver from the puzzle.
 void setSize(int size)
          Sets the size.
 String toString()
          
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Disk

public Disk(int size,
            Pin pin)
Create an instance with the given size and located at the given Pin.

Parameters:
size - Relative radius
pin - A pin
Method Detail

changePinTo

public void changePinTo(Pin aPin)
Move the receiver from the current pin to the given pin.

Note: this does not notify observers.

Parameters:
aPin - A pin

compareTo

public int compareTo(Object o)
Interface Comparable: Compare the receiver with the argument. If the argument is not a Disk, a ClassCastException is thrown. Otherwise, the size of the two Disks are compared (disks are sorted in descending size order): this.size < o.size: result is 1 this.size = o.size: result is 0 this.size > o.size: result is -1

Specified by:
compareTo in interface Comparable
Parameters:
o - The object to compare.
Returns:
The result of the comparison - see description.

equals

public boolean equals(Object obj)

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getPin

public Pin getPin()
Gets the pin.

Returns:
the pin

getSize

public int getSize()
Gets the size.

Returns:
An integer between 1 and the total number of disks of the puzzle. The smallest disk has size 1.

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

moveTo

public void moveTo(Pin target)
            throws InvalidMoveException
Remove the receiver from the top of the current pin and add it to the top of the specified pin. An exception is thrown if this is an invalid move. Notify observers.

Parameters:
target - A pin
Throws:
InvalidMoveException - if an invalid move is attempted

remove

public void remove()
Remove the receiver from the puzzle. Note: this does not notify observers.


setSize

public void setSize(int size)
Sets the size.

Parameters:
size - An integer between 1 and the total number of disks of the puzzle. The smallest disk has size 1.

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()