jrummikub.model
Class StoneSet

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

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

Class managing Stones joined together to form sets


Nested Class Summary
static class StoneSet.Type
          Validity type of the set
 
Field Summary
(package private) static float HORIZONTAL_BORDER
           
(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
 StoneSet.Type classify()
          Test for rule conflict within the StoneSet 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
 float getWidth()
          Get the width of the object
 boolean isValid()
          Test for rule conflict within the StoneSet
 java.util.Iterator<Stone> iterator()
           
 StoneSet join(StoneSet other)
          Joins StoneSet to another StoneSet and returns the resulting new StoneSet
 int size()
          Returns the number of stones in the set.
 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

VERTICAL_BORDER

static final float VERTICAL_BORDER
See Also:
Constant Field Values

HORIZONTAL_BORDER

static final float HORIZONTAL_BORDER
See Also:
Constant Field Values
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()
Test for rule conflict within the StoneSet

Returns:
true when the set is valid according to the rules

classify

public StoneSet.Type classify()
Test for rule conflict within the StoneSet and determine whether the set is a group or a run

Returns:
GROUP or RUN for valid sets, INVALID otherwise

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

size

public int size()
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