public abstract class Ship {
+ /** return the Fleet that this Ship belongs to */
+ public abstract Fleet getFleet();
+
/** returns the type of the ship ("Fetch", "ALU", etc) */
public abstract String getType();
/** return all benkoboxes which feed this ship; order is NOT significant */
public abstract Iterable<BenkoBox> getBenkoBoxes();
+ public BenkoBox getBenkoBox(String s) {
+ for(BenkoBox b : getBenkoBoxes())
+ if (b.getName().equals(s))
+ return b;
+ throw new RuntimeException("unknown port \""+getType()+"."+s+"\"");
+ }
+
+ public int getOrdinal() {
+ int ord = 0;
+ for(Ship s : getFleet()) {
+ if (s==this) return ord;
+ if (s.getType() != null && s.getType().equals(getType())) ord++;
+ }
+ throw new RuntimeException("inconsistency: Ship does not belong to its own Fleet!");
+ }
+
+ public String toString() { return getType() + "[" + getOrdinal() + "]"; }
+
}