From 05cb1ec01257fbe00d00638686ee9d30cde8bd6c Mon Sep 17 00:00:00 2001 From: Adam Megacz Date: Sun, 20 Sep 2009 12:33:39 -0700 Subject: [PATCH] ShipDescription: add support for conditional sections --- src/edu/berkeley/fleet/two/ShipDescription.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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; } -- 1.7.10.4