jrummikub.model
Class StoneSet

java.lang.Object
  extended by jrummikub.model.StoneSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Stone>, Sizeable

public class StoneSet
extends java.lang.Object
implements java.lang.Iterable<Stone>, Sizeable, java.io.Serializable

Class managing Stones joined together to form sets

See Also:
Serialized Form

Nested Class Summary
static class StoneSet.Type
          Validity type of the set
 
Field Summary
(package private) static float HORIZONTAL_BORDER
           
private static long serialVersionUID
           
private  java.util.ArrayList<Stone> stones
           
(package private) static float VERTICAL_BORDER
           
 
Constructor Summary
StoneSet(java.util.List<Stone> stones)
          Create a stone set from a list of stones
StoneSet(Stone stone)
          Create a new single stone stone set
 
Method Summary
 Pair<StoneSet.Type,java.lang.Integer> classify(GameSettings settings)
          Test for rule conflict within the StoneSet and determine whether the set is a group or a run
private  Pair<StoneSet.Type,java.lang.Integer> classifyJokersOnly(GameSettings settings)
          Test for rule conflict within a StoneSet with jokers only and determine whether the set is a group or a run
 Stone get(int i)
          Returns the i-th stone of the set (starting with 0)
 float getHeight()
          Get the height of the object
 int getSize()
          Returns the number of stones in the set.
 float getWidth()
          Get the width of the object
 boolean isValid(GameSettings settings)
          Test for rule conflict within the StoneSet
private  int isValidGroup(int value, GameSettings settings)
          Test for rule conflict within the StoneSet, assuming we have a group
private  int isValidRun(int referencePosition, GameSettings settings)
          Test for rule conflict within the StoneSet, assuming we have a run
 java.util.Iterator<Stone> iterator()
           
 StoneSet join(StoneSet other)
          Joins StoneSet to another StoneSet and returns the resulting new StoneSet
 Pair<StoneSet,StoneSet> splitAt(int position)
          Splits the StoneSet at a specified Position and returns two new Stone Sets
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

VERTICAL_BORDER

static final float VERTICAL_BORDER
See Also:
Constant Field Values

HORIZONTAL_BORDER

static final float HORIZONTAL_BORDER
See Also:
Constant Field Values

stones

private java.util.ArrayList<Stone> stones
Constructor Detail

StoneSet

public StoneSet(Stone stone)
Create a new single stone stone set

Parameters:
stone - single stone of the set

StoneSet

public StoneSet(java.util.List<Stone> stones)
Create a stone set from a list of stones

Parameters:
stones - list of stones to build a set of
Method Detail

isValid

public boolean isValid(GameSettings settings)
Test for rule conflict within the StoneSet

Parameters:
settings - GameSettings
Returns:
true when the set is valid according to the rules

classify

public Pair<StoneSet.Type,java.lang.Integer> classify(GameSettings settings)
Test for rule conflict within the StoneSet and determine whether the set is a group or a run

Parameters:
settings - GameSettings
Returns:
GROUP or RUN for valid sets, INVALID otherwise and the points

classifyJokersOnly

private Pair<StoneSet.Type,java.lang.Integer> classifyJokersOnly(GameSettings settings)
Test for rule conflict within a StoneSet with jokers only and determine whether the set is a group or a run

Parameters:
settings - the game settings
Returns:
GROUP or RUN for valid sets, INVALID otherwise and the points

isValidRun

private int isValidRun(int referencePosition,
                       GameSettings settings)
Test for rule conflict within the StoneSet, assuming we have a run

Parameters:
referencePosition - position of stone used as reference (any non-joker stone)
settings - the game settings
Returns:
the set's points

isValidGroup

private int isValidGroup(int value,
                         GameSettings settings)
Test for rule conflict within the StoneSet, assuming we have a group

Parameters:
value - the value of the stones (all have the same in a group)
settings - the game settings
Returns:
the set's points

splitAt

public Pair<StoneSet,StoneSet> splitAt(int position)
Splits the StoneSet at a specified Position and returns two new Stone Sets

Parameters:
position - Splitting Position
Returns:
A pair of StoneSets, one for each split part

join

public StoneSet join(StoneSet other)
Joins StoneSet to another StoneSet and returns the resulting new StoneSet

Parameters:
other - StoneSet to be joined to active StoneSet
Returns:
the combined StoneSet

getSize

public int getSize()
Returns the number of stones in the set.

Returns:
number of stones

get

public Stone get(int i)
Returns the i-th stone of the set (starting with 0)

Parameters:
i - number of the stone to return
Returns:
the i-th stone

iterator

public java.util.Iterator<Stone> iterator()
Specified by:
iterator in interface java.lang.Iterable<Stone>

getWidth

public float getWidth()
Description copied from interface: Sizeable
Get the width of the object

Specified by:
getWidth in interface Sizeable
Returns:
object width

getHeight

public float getHeight()
Description copied from interface: Sizeable
Get the height of the object

Specified by:
getHeight in interface Sizeable
Returns:
object height

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object