X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2Fargparser%2FArgValues.java;h=8e4fe2cefead47bb4775841514923b4e0e43da80;hb=24e740c734e106a739dec7f31955f17103899641;hp=c166da0d84f17fc82cf5941fffcde61054a17fb4;hpb=f52d881ba992cf5d4570d487f6319666f13263a9;p=jalview.git diff --git a/src/jalview/bin/argparser/ArgValues.java b/src/jalview/bin/argparser/ArgValues.java index c166da0..8e4fe2c 100644 --- a/src/jalview/bin/argparser/ArgValues.java +++ b/src/jalview/bin/argparser/ArgValues.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.bin.argparser; import java.util.ArrayList; @@ -8,6 +28,7 @@ import java.util.stream.Collectors; import jalview.bin.Console; import jalview.bin.argparser.Arg.Opt; +import jalview.bin.argparser.Arg.Type; public class ArgValues { @@ -21,6 +42,8 @@ public class ArgValues private boolean negated = false; + private boolean setByWildcard = false; + private int boolIndex = -1; private List argsIndexes; @@ -29,6 +52,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; @@ -36,11 +64,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; @@ -51,8 +100,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; } @@ -61,10 +113,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() @@ -98,28 +156,31 @@ public class ArgValues 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(); } @@ -131,6 +192,7 @@ public class ArgValues idMap.put(id, av); } argValueList.add(av); + this.setSetByWildcard(beingSetByWildcard); } protected boolean hasValue(String val) @@ -140,7 +202,7 @@ public class ArgValues 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; } @@ -159,4 +221,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