com.webstersmalley.chessweb.model
Class Position

java.lang.Object
  extended by com.webstersmalley.chessweb.model.Position
All Implemented Interfaces:
java.lang.Cloneable

public final class Position
extends java.lang.Object
implements java.lang.Cloneable

Simple coordinate system for the position of a piece on the board.

Author:
Matthew Smalley

Constructor Summary
Position()
          Default constructor.
Position(int file, int rank)
          Create a Position based on file and rank (0-index) coordinates.
Position(java.lang.String algebraicNotation)
          Convenience constructor.
Position(java.lang.String file, int rank)
          Convenience constructor.
 
Method Summary
 void add(int fileIncrement, int rankIncrement)
          Adds a vector onto the position.
 java.lang.Object clone()
          Create a clone of this position.
 boolean equals(java.lang.Object obj)
          Whether two objects are equal.
 java.lang.String getAlgebraicNotation()
          Returns the algebraic notation of this position.
 java.lang.String getFile()
           
 int getFileNumber()
          Return the file number.
 int getModulus()
          Return the modulus of the square number.
 int getRank()
           
 int hashCode()
          Get the hash code of the Object.
 void setAlgebraicNotation(java.lang.String algebraicNotation)
          Resets the position based on the algebraic notation.
 void setFile(java.lang.String file)
           
 void setRank(int rank)
           
 java.lang.String toString()
          Returns a String representation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Position

public Position()
Default constructor.


Position

public Position(java.lang.String file,
                int rank)
Convenience constructor.

Parameters:
file - the file coordinate
rank - the rank coordinate

Position

public Position(java.lang.String algebraicNotation)
Convenience constructor.

Parameters:
algebraicNotation - the algebraicNotation

Position

public Position(int file,
                int rank)
Create a Position based on file and rank (0-index) coordinates.

Parameters:
file - the file
rank - the rank
Method Detail

getFile

public java.lang.String getFile()
Returns:
Returns the file.

setFile

public void setFile(java.lang.String file)
Parameters:
file - The file to set.

getRank

public int getRank()
Returns:
Returns the rank.

setRank

public void setRank(int rank)
Parameters:
rank - The rank to set.

toString

public java.lang.String toString()
Returns a String representation.

Overrides:
toString in class java.lang.Object
Returns:
String the string

getModulus

public int getModulus()
Return the modulus of the square number. Useful for working out blank/white of the square.

Returns:
the modulus

getFileNumber

public int getFileNumber()
Return the file number.

Returns:
the file number

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a clone of this position.

Overrides:
clone in class java.lang.Object
Returns:
the clone
Throws:
java.lang.CloneNotSupportedException - (This should not happen!)

equals

public boolean equals(java.lang.Object obj)
Whether two objects are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the comparator
Returns:
whether they are equal

hashCode

public int hashCode()
Get the hash code of the Object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode

add

public void add(int fileIncrement,
                int rankIncrement)
Adds a vector onto the position.

Parameters:
fileIncrement - the change in file
rankIncrement - the change in rank

getAlgebraicNotation

public java.lang.String getAlgebraicNotation()
Returns the algebraic notation of this position.

Returns:
the algebraic notation.

setAlgebraicNotation

public void setAlgebraicNotation(java.lang.String algebraicNotation)
Resets the position based on the algebraic notation.

Parameters:
algebraicNotation - the position


Copyright © 2005 Webster Smalley. All Rights Reserved.