jrummikub.model
Class Hand

java.lang.Object
  extended by jrummikub.model.StoneTray<Stone>
      extended by jrummikub.model.Hand
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Pair<Stone,Position>>, IHand, IStoneTray<Stone>

public class Hand
extends StoneTray<Stone>
implements IHand

Class managing a Player's Stones

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jrummikub.model.StoneTray
StoneTray.Direction
 
Field Summary
private static java.util.Comparator<Pair<java.lang.Integer,StoneColor>> comparator
          The measure to compare the stones by
private static long serialVersionUID
           
static int WIDTH
          The width of the hand
 
Fields inherited from class jrummikub.model.StoneTray
objects
 
Constructor Summary
Hand()
           
 
Method Summary
private static Pair<java.util.TreeMap<Pair<java.lang.Integer,StoneColor>,java.lang.Integer>,java.lang.Integer> countStones(java.util.List<Stone> stones)
          Counts the numbers of stones
protected  Pair<Position,StoneTray.Direction> fixInvalidDrop(Stone stone, Position pos, StoneTray.Direction dir)
          Checks whether the object may be placed on the given position, computes new position if not
 int getFreeRowSpace(int row)
          Gets the amount of free space in a hand row
 int getIdenticalStoneCount()
          Counts the pairs of identical stones
 int getRowCount()
          The number of used rows
 int getStonePoints(GameSettings settings)
          Get the accumulated number of points of stones in the hand
private static void incrementStoneCount(java.util.TreeMap<Pair<java.lang.Integer,StoneColor>,java.lang.Integer> stones, Pair<java.lang.Integer,StoneColor> stone)
          Increments the count of a stone in the list of all stones
 boolean isInitialMeldPossible(GameSettings settings)
          Tests whether it is possible to lay down an initial meld using the stones on the hand
 
Methods inherited from class jrummikub.model.StoneTray
clone, contains, drop, getPosition, getSize, iterator, pickUp
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jrummikub.model.IStoneTray
clone, contains, drop, getPosition, getSize, pickUp
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

WIDTH

public static final int WIDTH
The width of the hand

See Also:
Constant Field Values

comparator

private static final java.util.Comparator<Pair<java.lang.Integer,StoneColor>> comparator
The measure to compare the stones by

Constructor Detail

Hand

public Hand()
Method Detail

getFreeRowSpace

public int getFreeRowSpace(int row)
Description copied from interface: IHand
Gets the amount of free space in a hand row

Specified by:
getFreeRowSpace in interface IHand
Parameters:
row - the row number
Returns:
the number of stones that can fit into the row

getRowCount

public int getRowCount()
Description copied from interface: IHand
The number of used rows

Specified by:
getRowCount in interface IHand
Returns:
the number of rows

fixInvalidDrop

protected Pair<Position,StoneTray.Direction> fixInvalidDrop(Stone stone,
                                                            Position pos,
                                                            StoneTray.Direction dir)
Description copied from class: StoneTray
Checks whether the object may be placed on the given position, computes new position if not

Overrides:
fixInvalidDrop in class StoneTray<Stone>
Parameters:
stone - to be dropped
pos - the object is dropped at
Returns:
null if the drop is valid, new position otherwise

getStonePoints

public int getStonePoints(GameSettings settings)
Description copied from interface: IHand
Get the accumulated number of points of stones in the hand

Specified by:
getStonePoints in interface IHand
Parameters:
settings - the game settings
Returns:
points

isInitialMeldPossible

public boolean isInitialMeldPossible(GameSettings settings)
Description copied from interface: IHand
Tests whether it is possible to lay down an initial meld using the stones on the hand

Specified by:
isInitialMeldPossible in interface IHand
Parameters:
settings - the game settings
Returns:
true if an initial meld is possible

incrementStoneCount

private static void incrementStoneCount(java.util.TreeMap<Pair<java.lang.Integer,StoneColor>,java.lang.Integer> stones,
                                        Pair<java.lang.Integer,StoneColor> stone)
Increments the count of a stone in the list of all stones

Parameters:
stones - all stones and their respective numbers
stone - the start stone

countStones

private static Pair<java.util.TreeMap<Pair<java.lang.Integer,StoneColor>,java.lang.Integer>,java.lang.Integer> countStones(java.util.List<Stone> stones)
Counts the numbers of stones

Parameters:
stones - the stones to count
Returns:
the numbers for all stones

getIdenticalStoneCount

public int getIdenticalStoneCount()
Description copied from interface: IHand
Counts the pairs of identical stones

Specified by:
getIdenticalStoneCount in interface IHand
Returns:
number of identical stone pairs