+ return index == NOTSET && subVals == null;
+ }
+
+ public String get(String key)
+ {
+ return subVals == null ? null : subVals.get(key);
+ }
+
+ public boolean has(String key)
+ {
+ return subVals == null ? false : subVals.containsKey(key);
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public String getContent()
+ {
+ return content;
+ }
+ }
+
+ /**
+ * Helper class to allow easy extraction of information about specific
+ * argument values (without having to check for null etc all the time)
+ */
+ protected static class ArgValuesMap
+ {
+ protected Map<Arg, ArgValues> m;
+
+ protected ArgValuesMap(Map<Arg, ArgValues> map)
+ {
+ this.m = map;
+ }
+
+ protected ArgValues getArgValues(Arg a)
+ {
+ return m == null ? null : m.get(a);
+ }
+
+ protected List<ArgValue> getArgValueList(Arg a)
+ {
+ ArgValues av = getArgValues(a);
+ return av == null ? null : av.getArgValueList();
+ }
+
+ protected ArgValue getArgValue(Arg a)
+ {
+ List<ArgValue> vals = getArgValueList(a);
+ return (vals == null || vals.size() == 0) ? null : vals.get(0);
+ }
+
+ protected String getValue(Arg a)
+ {
+ ArgValue av = getArgValue(a);
+ return av == null ? null : av.getValue();
+ }
+
+ protected boolean hasValue(Arg a)
+ {
+ if (!m.containsKey(a))
+ return false;
+ return getArgValue(a) != null;
+ }
+
+ protected boolean getBoolean(Arg a)
+ {
+ ArgValues av = getArgValues(a);
+ return av == null ? false : av.getBoolean();
+ }
+
+ protected ArgValue getClosestPreviousArgValueOfArg(ArgValue thisAv,
+ Arg a)
+ {
+ ArgValue closestAv = null;
+ int thisArgIndex = thisAv.getArgIndex();
+ ArgValues compareAvs = this.getArgValues(a);
+ int closestPreviousIndex = -1;
+ for (ArgValue av : compareAvs.getArgValueList())
+ {
+ int argIndex = av.getArgIndex();
+ if (argIndex < thisArgIndex && argIndex > closestPreviousIndex)
+ {
+ closestPreviousIndex = argIndex;
+ closestAv = av;
+ }
+ }
+ return closestAv;
+ }
+ }
+
+ private static final Collection<Arg> bootstrapArgs = new ArrayList(
+ Arrays.asList(Arg.PROPS, Arg.DEBUG));
+
+ public static Map<Arg, String> bootstrapArgs(String[] args)
+ {
+ Map<Arg, String> bootstrapArgMap = new HashMap<>();
+ if (args == null)
+ return bootstrapArgMap;
+ Enumeration<String> argE = Collections.enumeration(Arrays.asList(args));
+ while (argE.hasMoreElements())
+ {
+ String arg = argE.nextElement();
+ String argName = null;
+ String val = null;
+ if (arg.startsWith("--"))
+ {
+ int equalPos = arg.indexOf('=');
+ if (equalPos > -1)
+ {
+ argName = arg.substring(2, equalPos);
+ val = arg.substring(equalPos + 1);
+ }
+ else
+ {
+ argName = arg.substring(2);
+ }
+ Arg a = argMap.get(argName);
+ if (a != null && bootstrapArgs.contains(a))
+ bootstrapArgMap.put(a, val);
+ }