add ShipPool.assertAllocated()
[fleet.git] / src / edu / berkeley / fleet / loops / ShipPool.java
index f120139..27dbff1 100644 (file)
@@ -63,4 +63,24 @@ public class ShipPool implements Iterable<Ship> {
         for (Ship ship : toRelease)
             releaseShip(ship);
     }
+
+    public void setParent(ShipPool parent) {
+        if (this.parent!=null) {
+            for (Ship ship : allocatedShips)
+                this.parent.releaseShip(ship);
+            this.parent = null;
+        }
+        if (parent != null) {
+            for (Ship ship : allocatedShips)
+                parent.allocateShip(ship);
+        }
+        this.parent = parent;
+    }
+
+    public void assertAllocated(Ship ship) {
+        if (allocatedShips.contains(ship)) return;
+        if (parent==null) throw new RuntimeException("assertAllocated() failed");
+        parent.assertAllocated(ship);
+    }
+
 }