0b7945d584c9d774994b834ee92cfd77ab54abfd
[fleet.git] / marina / testCode / edu / berkeley / fleet / api / Ship.java
1 package edu.berkeley.fleet.api;
2 import java.util.*;
3
4 /** A ship in a Fleet; each ship consists of a collection of <tt>Dock</tt>s */
5 public abstract class Ship implements Iterable<Dock> {
6
7     private final Fleet fleet;
8
9     public Ship(Fleet fleet) {
10         this.fleet = fleet;
11     }
12
13     /** return the Fleet that this Ship belongs to */
14     public Fleet  getFleet() { return fleet; }
15
16     /** returns the type of the ship ("Fetch", "Alu", etc) */
17     public abstract String getType();
18     
19     public abstract Iterator<Dock> iterator();
20
21     /** returns the dock on this ship having name "name" */
22     public abstract Dock getDock(String name);
23
24     /** the docks of a given type are numbered; this returns the ordinal number of this dock */
25     public abstract int getOrdinal();
26
27     /** get a constant associated with a ship; returns null if none found */
28     public BitVector getConstant(String constantName) {
29         throw new RuntimeException("unknown constant \""+constantName+"\" on ship " + this);
30     }
31
32     public String toString() {
33         String name = getType();
34         name = name.substring(0,1).toLowerCase()+name.substring(1);
35         return name + "" + getOrdinal() + "";
36     }
37 }