X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2Fargparser%2FArgValues.java;h=f25fc9ad0876497c21f86ce411fc64815087b70e;hb=b382fe5af3f138ede6db2ab1efc05ddd0819eea6;hp=0be776822c816d15153b451b6073e17c72f2a5f8;hpb=2e59bc7938c0f10bde61fd30d1841bedb3d8319e;p=jalview.git diff --git a/src/jalview/bin/argparser/ArgValues.java b/src/jalview/bin/argparser/ArgValues.java index 0be7768..f25fc9a 100644 --- a/src/jalview/bin/argparser/ArgValues.java +++ b/src/jalview/bin/argparser/ArgValues.java @@ -4,13 +4,15 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import jalview.bin.Console; import jalview.bin.argparser.Arg.Opt; +import jalview.bin.argparser.Arg.Type; public class ArgValues { - protected static final String ID = "id"; + public static final String ID = "id"; private Arg arg; @@ -20,6 +22,8 @@ public class ArgValues private boolean negated = false; + private boolean setByWildcard = false; + private int boolIndex = -1; private List argsIndexes; @@ -28,6 +32,11 @@ public class ArgValues private Map idMap = new HashMap<>(); + /* + * Type type is only really used by --help-type + */ + private Type type = null; + protected ArgValues(Arg a) { this.arg = a; @@ -35,11 +44,32 @@ public class ArgValues 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; @@ -50,8 +80,11 @@ public class ArgValues 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; } @@ -60,10 +93,16 @@ public class ArgValues 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() @@ -85,43 +124,47 @@ public class ArgValues if (arg.hasOption(Opt.STRING)) { sb.append("Values:"); - boolean first = true; - for (ArgValue av : argValueList) - { - String v = av.getValue(); - if (!first) - sb.append(","); - sb.append("\n '"); - sb.append(v).append("'"); - first = false; - } + sb.append("'") + .append(String + .join("',\n '", + argValueList.stream().map(av -> av.getValue()) + .collect(Collectors.toList()))) + .append("'"); sb.append("\n"); } sb.append("Count: ").append(argCount).append("\n"); 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 addArgValue(ArgValue av) + protected void addArgValue(ArgValue av, boolean beingSetByWildcard) { + // allow a non-wildcard value to overwrite a wildcard set single value + boolean overwrite = !arg.hasOption(Opt.MULTI) && setByWildcard + && !beingSetByWildcard; if ((!arg.hasOption(Opt.MULTI) && argValueList.size() > 0) - || (arg.hasOption(Opt.NODUPLICATEVALUES) - && argValueList.contains(av.getValue()))) + && !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(); } - SubVals sv = ArgParser.getSubVals(av.getValue()); + SubVals sv = new SubVals(av.getValue()); if (sv.has(ID)) { String id = sv.get(ID); @@ -129,6 +172,7 @@ public class ArgValues idMap.put(id, av); } argValueList.add(av); + this.setSetByWildcard(beingSetByWildcard); } protected boolean hasValue(String val) @@ -157,4 +201,21 @@ public class ArgValues { 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