From 2aeedc62418ab7816887f20e4ccb461fe6a0fcc0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 May 2011 21:34:58 +0200 Subject: Added toString method to StoneSet git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@97 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/jrummikub/model') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 98fa325..98a808e 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -40,8 +40,8 @@ public class StoneSet implements Iterable, Sizeable { } /** - * Test for rule conflict within the StoneSet and determine whether the set - * is a group or a run + * Test for rule conflict within the StoneSet and determine whether the set is + * a group or a run * * @return GROUP or RUN for valid sets, INVALID otherwise */ @@ -62,8 +62,7 @@ public class StoneSet implements Iterable, Sizeable { return GROUP; } // is run - if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2) - .getColor()) { + if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2).getColor()) { return isValidRun(nonJoker1) ? RUN : INVALID; } @@ -77,7 +76,7 @@ public class StoneSet implements Iterable, Sizeable { * Test for rule conflict within the StoneSet, assuming we have a run * * @param referencePosition - * position of stone used as reference (any non-joker stone) + * position of stone used as reference (any non-joker stone) */ private boolean isValidRun(int referencePosition) { StoneColor runColor = stones.get(referencePosition).getColor(); @@ -128,7 +127,7 @@ public class StoneSet implements Iterable, Sizeable { * Stone Sets * * @param position - * Splitting {@link Position} + * Splitting {@link Position} * @return A pair of StoneSets, one for each split part */ public Pair splitAt(int position) { @@ -138,8 +137,7 @@ public class StoneSet implements Iterable, Sizeable { return new Pair(this, null); } StoneSet firstSet = new StoneSet(stones.subList(0, position)); - StoneSet secondSet = new StoneSet(stones.subList(position, - stones.size())); + StoneSet secondSet = new StoneSet(stones.subList(position, stones.size())); return new Pair(firstSet, secondSet); } @@ -147,7 +145,7 @@ public class StoneSet implements Iterable, Sizeable { * Joins StoneSet to another StoneSet and returns the resulting new StoneSet * * @param other - * StoneSet to be joined to active StoneSet + * StoneSet to be joined to active StoneSet * @return the combined StoneSet */ public StoneSet join(StoneSet other) { @@ -170,7 +168,7 @@ public class StoneSet implements Iterable, Sizeable { * Returns the i-th stone of the set (starting with 0) * * @param i - * number of the stone to return + * number of the stone to return * @return the i-th stone */ public Stone get(int i) { @@ -212,4 +210,19 @@ public class StoneSet implements Iterable, Sizeable { return 1 + 2 * HORIZONTAL_BORDER; } + @Override + public String toString() { + String ret = "StoneSet["; + boolean first = true; + + for (Stone stone : stones) { + if (!first) + ret += ","; + + ret += stone.toString(); + first = false; + } + + return ret + "]"; + } } -- cgit v1.2.3