1 package edu.berkeley.fleet.api;
5 public abstract class Ship {
7 /** return the Fleet that this Ship belongs to */
8 public abstract Fleet getFleet();
10 /** returns the type of the ship ("Fetch", "ALU", etc) */
11 public abstract String getType();
13 /** return all benkoboxes which feed this ship; order is NOT significant */
14 public abstract Iterable<BenkoBox> getBenkoBoxes();
16 public BenkoBox getBenkoBox(String s) {
17 for(BenkoBox b : getBenkoBoxes())
18 if (b.getName().equals(s))
20 throw new RuntimeException("unknown port \""+getType()+"."+s+"\"");
23 public int getOrdinal() {
25 for(Ship s : getFleet()) {
26 if (s==this) return ord;
27 if (s.getType() != null && s.getType().equals(getType())) ord++;
29 throw new RuntimeException("inconsistency: Ship does not belong to its own Fleet!");
32 public String toString() { return getType() + "[" + getOrdinal() + "]"; }