public static boolean getFromSubValArgOrPref(ArgValuesMap avm, Arg a,
SubVals sv, String key, String pref, boolean def)
{
+ if ((key == null && a == null) || (sv == null && a == null))
+ return false;
+
+ boolean usingArgKey = false;
if (key == null)
+ {
key = a.getName();
+ usingArgKey = true;
+ }
+
String nokey = ArgParser.NEGATESTRING + key;
- if (sv != null && sv.has(key) && sv.get(key) != null)
- return sv.get(key).toLowerCase(Locale.ROOT).equals("true");
- if (sv != null && sv.has(key) && sv.get(key) != null)
- return sv.get(key).toLowerCase(Locale.ROOT).equals("true");
+ // look for key or nokey in subvals first (if using Arg check options)
+ if (sv != null)
+ {
+ // check for true boolean
+ if (sv.has(key) && sv.get(key) != null)
+ {
+ if (usingArgKey)
+ {
+ if (!(a.hasOption(Opt.BOOLEAN) || a.hasOption(Opt.UNARY)))
+ {
+ Console.debug(
+ "Looking for boolean in subval from non-boolean/non-unary Arg "
+ + a.getName());
+ return false;
+ }
+ }
+ return sv.get(key).toLowerCase(Locale.ROOT).equals("true");
+ }
- // check for negative boolean (subval "no..." will be "true")
- if (sv != null && sv.has(nokey) && sv.get(nokey) != null)
- return !sv.get(nokey).toLowerCase(Locale.ROOT).equals("true");
+ // check for negative boolean (subval "no..." will be "true")
+ if (sv.has(nokey) && sv.get(nokey) != null)
+ {
+ if (usingArgKey)
+ {
+ if (!(a.hasOption(Opt.BOOLEAN)))
+ {
+ Console.debug(
+ "Looking for negative boolean in subval from non-boolean Arg "
+ + a.getName());
+ return false;
+ }
+ }
+ return !sv.get(nokey).toLowerCase(Locale.ROOT).equals("true");
+ }
+ }
+ // check argvalues
if (avm != null && avm.containsArg(a))
return avm.getBoolean(a);
+ // return preference or default
return pref != null ? Cache.getDefault(pref, def) : def;
}