Merge marina project in subdirectory marina/
[fleet.git] / marina / testCode / edu / berkeley / fleet / two / FleetTwoShip.java
1 package edu.berkeley.fleet.two;
2 import edu.berkeley.fleet.api.*;
3 import java.util.*;
4
5 /** A ship in a Fleet; each ship consists of a collection of <tt>Dock</tt>s */
6 public abstract class FleetTwoShip extends Ship {
7
8     protected final ShipDescription shipDescription;
9
10     public FleetTwoShip(Fleet fleet, ShipDescription shipDescription) {
11         super(fleet);
12         this.shipDescription = shipDescription;
13     }
14
15     /** returns the type of the ship ("Fetch", "ALU", etc) */
16     public String getType() { return shipDescription.getName(); }
17
18     public Dock getDock(String s) {
19         for(Dock b : this)
20             if (b.getName().equals(s))
21                 return b;
22         throw new RuntimeException("unknown port \""+getType()+"."+s+"\"");
23     }
24
25     public int getOrdinal() {
26         int ord = 0;
27         for(Ship s : getFleet()) {
28             if (s==this) return ord;
29             if (s.getType() != null && s.getType().equals(getType())) ord++;
30         }
31         throw new RuntimeException("inconsistency: Ship does not belong to its own Fleet!");
32     }
33
34     public BitVector getConstant(String constantName) {
35         BitVector bv = shipDescription.getConstant(constantName);
36         if (bv==null)
37             throw new RuntimeException("unknown constant \""+constantName+"\" on ship " + this);
38         return bv;
39     }
40 }