From: Adam Megacz Date: Sun, 20 Sep 2009 19:33:39 +0000 (-0700) Subject: ShipDescription: add support for conditional sections X-Git-Url: http://git.megacz.com/?p=fleet.git;a=commitdiff_plain;h=05cb1ec01257fbe00d00638686ee9d30cde8bd6c ShipDescription: add support for conditional sections --- diff --git a/src/edu/berkeley/fleet/two/ShipDescription.java b/src/edu/berkeley/fleet/two/ShipDescription.java index 6752e70..19be168 100644 --- a/src/edu/berkeley/fleet/two/ShipDescription.java +++ b/src/edu/berkeley/fleet/two/ShipDescription.java @@ -40,6 +40,21 @@ public class ShipDescription implements Iterable { 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; }