import jalview.bin.Console;
import jalview.bin.argparser.Arg.Opt;
+import jalview.bin.argparser.Arg.Type;
public class ArgValues
{
private boolean negated = false;
+ private boolean setByWildcard = false;
+
private int boolIndex = -1;
private List<Integer> argsIndexes;
private Map<String, ArgValue> idMap = new HashMap<>();
+ /*
+ * Type type is only really used by --help-type
+ */
+ private Type type = null;
+
protected ArgValues(Arg a)
{
this.arg = a;
this.boolValue = arg.getDefaultBoolValue();
}
+ protected boolean setByWildcard()
+ {
+ return setByWildcard;
+ }
+
+ protected void setSetByWildcard(boolean b)
+ {
+ setByWildcard = b;
+ }
+
public Arg arg()
{
return arg;
}
+ protected void setType(Type t)
+ {
+ if (this.arg().hasOption(Opt.HASTYPE))
+ this.type = t;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
protected int getCount()
{
return argCount;
argCount++;
}
- protected void setNegated(boolean b)
+ protected void setNegated(boolean b, boolean beingSetByWildcard)
{
+ // don't overwrite a wildcard set boolean with a non-wildcard set boolean
+ if (boolIndex >= 0 && !this.setByWildcard && beingSetByWildcard)
+ return;
this.negated = b;
}
return this.negated;
}
- protected void setBoolean(boolean b, int i)
+ protected void setBoolean(Type t, boolean b, int i,
+ boolean beingSetByWildcard)
{
+ this.setType(t);
+ // don't overwrite a wildcard set boolean with a non-wildcard set boolean
+ if (boolIndex >= 0 && !this.setByWildcard && beingSetByWildcard)
+ return;
this.boolValue = b;
this.boolIndex = i;
+ this.setSetByWildcard(beingSetByWildcard);
}
protected boolean getBoolean()
return sb.toString();
}
- protected void addValue()
+ protected void addValue(Type type, String val, int argIndex,
+ boolean wildcard)
{
- addValue(null, -1);
+ addArgValue(new ArgValue(arg(), type, val, argIndex), wildcard);
}
- protected void addValue(String val, int argIndex)
+ protected void addValue(SubVals sv, Type type, String content,
+ int argIndex, boolean wildcard)
{
- addArgValue(new ArgValue(val, argIndex));
+ addArgValue(new ArgValue(arg(), sv, type, content, argIndex), wildcard);
}
- protected void addValue(SubVals sv, String content, int argIndex)
+ protected void addArgValue(ArgValue av, boolean beingSetByWildcard)
{
- addArgValue(new ArgValue(sv, content, argIndex));
- }
-
- protected void addArgValue(ArgValue av)
- {
- if ((!arg.hasOption(Opt.MULTI) && argValueList.size() > 0)
- || (arg.hasOption(Opt.NODUPLICATEVALUES)
- && argValueList.contains(av.getValue())))
+ // allow a non-wildcard value to overwrite a wildcard set single value
+ boolean overwrite = !arg.hasOption(Opt.MULTIVALUE) && setByWildcard
+ && !beingSetByWildcard;
+ if ((!arg.hasOption(Opt.MULTIVALUE) && argValueList.size() > 0)
+ && !overwrite)
return;
- if (argValueList == null)
+ if (arg.hasOption(Opt.NODUPLICATEVALUES)
+ && this.containsValue(av.getValue()))
+ return;
+ // new or overwrite if single valued
+ if (argValueList == null || overwrite)
{
argValueList = new ArrayList<ArgValue>();
}
idMap.put(id, av);
}
argValueList.add(av);
+ this.setSetByWildcard(beingSetByWildcard);
}
protected boolean hasValue(String val)
protected ArgValue getArgValue()
{
- if (arg.hasOption(Opt.MULTI))
+ if (arg.hasOption(Opt.MULTIVALUE))
Console.warn("Requesting single value for multi value argument");
return argValueList.size() > 0 ? argValueList.get(0) : null;
}
{
return idMap.get(id);
}
+
+ private boolean containsValue(String v)
+ {
+ if (argValueList == null)
+ return false;
+ for (ArgValue av : argValueList)
+ {
+ String val = av.getValue();
+ if (v == null && val == null)
+ return true;
+ if (v == null)
+ continue;
+ if (v.equals(val))
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file