ShipDescription: add support for conditional sections
authorAdam Megacz <adam@megacz.com>
Sun, 20 Sep 2009 19:33:39 +0000 (12:33 -0700)
committerAdam Megacz <adam@megacz.com>
Sun, 20 Sep 2009 19:33:39 +0000 (12:33 -0700)
src/edu/berkeley/fleet/two/ShipDescription.java

index 6752e70..19be168 100644 (file)
@@ -40,6 +40,21 @@ public class ShipDescription implements Iterable<DockDescription> {
                     sectionName = sectionName.substring(1);
                 while(sectionName.endsWith("="))
                     sectionName = sectionName.substring(0, sectionName.length()-1);
+                sectionName = sectionName.trim();
+
+                if (sectionName.indexOf(':') != -1) {
+                    String subtype = sectionName.substring(sectionName.indexOf(':')+1);
+                    sectionName = sectionName.substring(0, sectionName.indexOf(':'));
+                    boolean good = false;
+                    for(Class c = fleet.getClass(); c!=Object.class; c = c.getSuperclass()) {
+                        if (subtype.equals(c.getSimpleName()))
+                            good = true;
+                    }
+                    if (!good) {
+                        sectionName = null;
+                        continue;
+                    }
+                }
                 sectionName = sectionName.trim().toLowerCase();
                 continue;
             }