public void allocateShip(Ship ship) {
if (allocatedShips.contains(ship))
- throw new RuntimeException("already allocated!");
+ throw new RuntimeException("ship " + ship + " is already allocated!");
if (parent != null)
parent.allocateShip(ship);
allocatedShips.add(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);
+ }
+
}