summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/model/StoneTray.java11
-rw-r--r--test/jrummikub/model/StoneTrayTest.java23
2 files changed, 31 insertions, 3 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 7f97e1b..f215164 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -209,11 +209,16 @@ public class StoneTray<E extends Sizeable> implements
};
}
- /**
- * @param object
- */
public void pickUp(E object) {
objects.remove(object);
}
+
+
+ @Override
+ public StoneTray<E> clone() {
+ StoneTray<E> copy = new StoneTray();
+ copy.objects = (HashMap<E, Position>) objects.clone();
+ return copy;
+ }
}
diff --git a/test/jrummikub/model/StoneTrayTest.java b/test/jrummikub/model/StoneTrayTest.java
index 23d9ea0..3456229 100644
--- a/test/jrummikub/model/StoneTrayTest.java
+++ b/test/jrummikub/model/StoneTrayTest.java
@@ -150,6 +150,7 @@ public class StoneTrayTest {
for (Pair<Thing, Position> i : testTray) {
assertSame(i.getFirst(), secondThing);
}
+ assertTrue(testTray.iterator().hasNext());
}
@Test
@@ -185,4 +186,26 @@ public class StoneTrayTest {
assertTrue(testThings.isEmpty());
assertTrue(testPositions.isEmpty());
}
+
+ @Test
+ public void testClone() {
+ Thing firstThing = new Thing(5, 5);
+ testTray.drop(firstThing, new Position(0, 0));
+ Thing secondThing = new Thing(3, 3);
+ testTray.drop(secondThing, new Position(-5, -5));
+ StoneTray<Thing> trayCopy = testTray.clone();
+
+
+ testTray.pickUp(firstThing);
+ for (Pair<Thing, Position> i : testTray) {
+ assertSame(i.getFirst(), secondThing);
+ }
+ assertTrue(testTray.iterator().hasNext());
+
+ trayCopy.pickUp(secondThing);
+ for (Pair<Thing, Position> i : trayCopy) {
+ assertSame(i.getFirst(), firstThing);
+ }
+ assertTrue(trayCopy.iterator().hasNext());
+ }
}