add Fleet.getDefaultImpl() and use it in Makefile
[fleet.git] / src / edu / berkeley / fleet / api / Fleet.java
index 361f5af..0e9700c 100644 (file)
@@ -60,4 +60,16 @@ public abstract class Fleet implements Iterable<Ship> {
     public FleetProcess run(Instruction[] program) {
         throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
     }
+
+    /** Assumes that the system property "fleet.impl" holds the name of a subclass to instantiate */
+    public static Fleet getDefaultImpl() {
+        String impl = System.getProperty("fleet.impl");
+        if (impl==null) throw new RuntimeException("You must invoke the JVM with -Dfleet.impl=<impl>");
+        try {
+            return (Fleet)Class.forName(impl).newInstance();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
 }