Added toString method to StoneSet

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@97 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-03 21:34:58 +02:00
parent 14bb9dd4c2
commit 2aeedc6241

View file

@ -40,8 +40,8 @@ public class StoneSet implements Iterable<Stone>, 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<Stone>, 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<Stone>, 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<Stone>, Sizeable {
* Stone Sets
*
* @param position
* Splitting {@link Position}
* Splitting {@link Position}
* @return A pair of StoneSets, one for each split part
*/
public Pair<StoneSet, StoneSet> splitAt(int position) {
@ -138,8 +137,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
return new Pair<StoneSet, StoneSet>(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<StoneSet, StoneSet>(firstSet, secondSet);
}
@ -147,7 +145,7 @@ public class StoneSet implements Iterable<Stone>, 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<Stone>, 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<Stone>, 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 + "]";
}
}