game
Interface Piece

All Known Implementing Classes:
Checker

public interface Piece

Piece represents an immutable playing piece on a board.

Each Piece object corresponds to a different physical object. So Piece.equals() (and Piece.hashCode()) implement referential equality: p1.equals(p2) if and only if p1 == p2.

Piece.similar() implements observational equality. If Piece objects p1 and p2 are indistinguishable for the rules of some particular game -- i.e., p1 and p2 could be swapped on the board without changing the board state -- then p1.similar(p2) is true. For example, two black pawns would be similar but not equal.


Method Summary
 boolean equals(Object obj)
          Test for referential equality with another object.
 int hashCode()
          Get hash code for this object.
 boolean similar(Object obj)
          Test for observational equality with another object.
 String toString()
          Get string representation of this piece.
 

Method Detail

equals

public boolean equals(Object obj)
Test for referential equality with another object.

Parameters:
obj - Object to test
Returns:
true if and only if this and obj are the same Piece object

hashCode

public int hashCode()
Get hash code for this object. Hash codes must obey the invariant that p1.equals(p2) implies p1.hashCode()==p2.hashCode(). Since Piece.equals() is defined as referential equality, Piece.hashCode() must use the Object.hashCode() implementation.

Returns:
hash code for this object

similar

public boolean similar(Object obj)
Test for observational equality with another object.

Parameters:
obj - Object to test
Returns:
true if and only obj is a Piece which is indistinguishable from this Piece for the rules of the game the Pieces belong to

toString

public String toString()
Get string representation of this piece.

Returns:
one-character string identifying this piece. Similar pieces should have the same string representation. The string should be only one character long in order to fit into Board's string representation.