argIndex, doSubs);
}
- private void NOTaddValue(String linkedId, ArgValues avs, SubVals sv,
- String v, int argIndex, boolean doSubs)
- {
- Arg a = avs.arg();
-
- List<String> wildcardLinkedIds = null;
- if (a.hasOption(Opt.ALLOWALL))
- {
- switch (linkedId)
- {
- case MATCHALLLINKEDIDS:
- wildcardLinkedIds = getLinkedIds();
- break;
- case MATCHOPENEDLINKEDIDS:
- wildcardLinkedIds = this.storedLinkedIds;
- break;
- }
- }
-
- // if we're not a wildcard linkedId and the arg is marked to be stored, add
- // to storedLinkedIds
- if (linkedId != null && wildcardLinkedIds == null
- && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- // if we are a wildcard linkedId, apply the arg and value to all appropriate
- // linkedIds
- if (wildcardLinkedIds != null)
- {
- for (String id : wildcardLinkedIds)
- {
- // skip incorrectly stored wildcard ids!
- if (id == null || MATCHALLLINKEDIDS.equals(id)
- || MATCHOPENEDLINKEDIDS.equals(id))
- continue;
- ArgValuesMap avm = linkedArgs.get(id);
- if (a.hasOption(Opt.REQUIREINPUT)
- && !avm.hasArgWithOption(Opt.INPUT))
- continue;
- ArgValues tavs = avm.getOrCreateArgValues(a);
- String val = v;
- if (doSubs)
- {
- val = makeSubstitutions(v, id);
- sv = new SubVals(sv, val);
- }
- tavs.addValue(sv, val, argIndex);
- finaliseStoringArgValue(id, tavs);
- }
- }
- else
- {
- String val = v;
- if (doSubs)
- {
- val = makeSubstitutions(v, linkedId);
- sv = new SubVals(sv, val);
- }
- avs.addValue(sv, val, argIndex);
- finaliseStoringArgValue(linkedId, avs);
- }
- }
-
private void addValue(String linkedId, ArgValues avs, String v,
int argIndex, boolean doSubs)
{
argIndex, doSubs);
}
- // the following methods look for the "*" linkedId and add the argvalue to all
- // linkedId ArgValues if it does.
- private void NOTaddValue(String linkedId, ArgValues avs, String v,
- int argIndex, boolean doSubs)
- {
- Arg a = avs.arg();
- if (linkedId != null && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- List<String> wildcardLinkedIds = null;
- if (a.hasOption(Opt.ALLOWALL))
- {
- switch (linkedId)
- {
- case MATCHALLLINKEDIDS:
- wildcardLinkedIds = getLinkedIds();
- break;
- case MATCHOPENEDLINKEDIDS:
- wildcardLinkedIds = this.storedLinkedIds;
- break;
- }
- }
-
- // if we're not a wildcard linkedId and the arg is marked to be stored, add
- // to storedLinkedIds
- if (linkedId != null && wildcardLinkedIds == null
- && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- // if we are a wildcard linkedId, apply the arg and value to all appropriate
- // linkedIds
- if (wildcardLinkedIds != null)
- {
- for (String id : wildcardLinkedIds)
- {
- // skip incorrectly stored wildcard ids!
- if (id == null || MATCHALLLINKEDIDS.equals(id)
- || MATCHOPENEDLINKEDIDS.equals(id))
- continue;
- ArgValuesMap avm = linkedArgs.get(id);
- // don't set an output if there isn't an input
- if (a.hasOption(Opt.REQUIREINPUT)
- && !avm.hasArgWithOption(Opt.INPUT))
- continue;
- ArgValues tavs = avm.getOrCreateArgValues(a);
- String val = doSubs ? makeSubstitutions(v, id) : v;
- tavs.addValue(val, argIndex);
- finaliseStoringArgValue(id, tavs);
- }
- }
- else
- {
- String val = doSubs ? makeSubstitutions(v, linkedId) : v;
- avs.addValue(val, argIndex);
- finaliseStoringArgValue(linkedId, avs);
- }
- }
-
private void setBoolean(String linkedId, ArgValues avs, boolean b,
int argIndex)
{
argIndex, false);
}
- private void NOTsetBoolean(String linkedId, ArgValues avs, boolean b,
- int argIndex)
- {
- Arg a = avs.arg();
- if (linkedId != null && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- List<String> wildcardLinkedIds = null;
- if (a.hasOption(Opt.ALLOWALL))
- {
- switch (linkedId)
- {
- case MATCHALLLINKEDIDS:
- wildcardLinkedIds = getLinkedIds();
- break;
- case MATCHOPENEDLINKEDIDS:
- wildcardLinkedIds = this.storedLinkedIds;
- break;
- }
- }
-
- // if we're not a wildcard linkedId and the arg is marked to be stored, add
- // to storedLinkedIds
- if (linkedId != null && wildcardLinkedIds == null
- && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- // if we are a wildcard linkedId, apply the arg and value to all appropriate
- // linkedIds
- if (wildcardLinkedIds != null)
- {
- for (String id : wildcardLinkedIds)
- {
- // skip incorrectly stored wildcard ids!
- if (id == null || MATCHALLLINKEDIDS.equals(id)
- || MATCHOPENEDLINKEDIDS.equals(id))
- continue;
- ArgValuesMap avm = linkedArgs.get(id);
- if (a.hasOption(Opt.REQUIREINPUT)
- && !avm.hasArgWithOption(Opt.INPUT))
- continue;
- ArgValues tavs = avm.getOrCreateArgValues(a);
- tavs.setBoolean(b, argIndex);
- finaliseStoringArgValue(id, tavs);
- }
- }
- else
- {
- avs.setBoolean(b, argIndex);
- finaliseStoringArgValue(linkedId, avs);
- }
- }
-
private void setNegated(String linkedId, ArgValues avs, boolean b)
{
this.argValueOperation(Op.SETNEGATED, linkedId, avs, null, null, b, 0,
false);
}
- private void NOTsetNegated(String linkedId, ArgValues avs, boolean b)
- {
- Arg a = avs.arg();
- if (linkedId != null && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- List<String> wildcardLinkedIds = null;
- if (a.hasOption(Opt.ALLOWALL))
- {
- switch (linkedId)
- {
- case MATCHALLLINKEDIDS:
- wildcardLinkedIds = getLinkedIds();
- break;
- case MATCHOPENEDLINKEDIDS:
- wildcardLinkedIds = this.storedLinkedIds;
- break;
- }
- }
-
- // if we're not a wildcard linkedId and the arg is marked to be stored, add
- // to storedLinkedIds
- if (linkedId != null && wildcardLinkedIds == null
- && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- // if we are a wildcard linkedId, apply the arg and value to all appropriate
- // linkedIds
- if (wildcardLinkedIds != null)
- {
- for (String id : wildcardLinkedIds)
- {
- // skip incorrectly stored wildcard ids!
- if (id == null || MATCHALLLINKEDIDS.equals(id)
- || MATCHOPENEDLINKEDIDS.equals(id))
- continue;
- ArgValuesMap avm = linkedArgs.get(id);
- if (a.hasOption(Opt.REQUIREINPUT)
- && !avm.hasArgWithOption(Opt.INPUT))
- continue;
- ArgValues tavs = avm.getOrCreateArgValues(a);
- tavs.setNegated(b);
- }
- }
- else
- {
- avs.setNegated(b);
- }
- }
-
private void incrementCount(String linkedId, ArgValues avs)
{
this.argValueOperation(Op.INCREMENTCOUNT, linkedId, avs, null, null,
false, 0, false);
}
- private void NOTincrementCount(String linkedId, ArgValues avs)
- {
- Arg a = avs.arg();
-
- List<String> wildcardLinkedIds = null;
- if (a.hasOption(Opt.ALLOWALL))
- {
- switch (linkedId)
- {
- case MATCHALLLINKEDIDS:
- wildcardLinkedIds = getLinkedIds();
- break;
- case MATCHOPENEDLINKEDIDS:
- wildcardLinkedIds = this.storedLinkedIds;
- break;
- }
- }
-
- // if we're not a wildcard linkedId and the arg is marked to be stored, add
- // to storedLinkedIds
- if (linkedId != null && wildcardLinkedIds == null
- && a.hasOption(Opt.STORED)
- && !storedLinkedIds.contains(linkedId))
- {
- storedLinkedIds.add(linkedId);
- }
-
- // if we are a wildcard linkedId, apply the arg and value to all appropriate
- // linkedIds
- if (wildcardLinkedIds != null)
- {
- for (String id : wildcardLinkedIds)
- {
- // skip incorrectly stored wildcard ids!
- if (id == null || MATCHALLLINKEDIDS.equals(id)
- || MATCHOPENEDLINKEDIDS.equals(id))
- continue;
- ArgValuesMap avm = linkedArgs.get(id);
- if (a.hasOption(Opt.REQUIREINPUT)
- && !avm.hasArgWithOption(Opt.INPUT))
- continue;
- ArgValues tavs = avm.getOrCreateArgValues(a);
- tavs.incrementCount();
- }
- }
- else
- {
- avs.incrementCount();
- }
- }
-
private enum Op
{
ADDVALUE, SETBOOLEAN, SETNEGATED, INCREMENTCOUNT
val = makeSubstitutions(v, id);
sv = new SubVals(sv, val);
}
- tavs.addValue(sv, val, argIndex);
+ tavs.addValue(sv, val, argIndex, true);
}
else
{
{
val = makeSubstitutions(v, id);
}
- tavs.addValue(val, argIndex);
+ tavs.addValue(val, argIndex, true);
}
finaliseStoringArgValue(id, tavs);
break;
case SETBOOLEAN:
- tavs.setBoolean(b, argIndex);
+ tavs.setBoolean(b, argIndex, true);
finaliseStoringArgValue(id, tavs);
break;
case SETNEGATED:
- tavs.setNegated(b);
+ tavs.setNegated(b, true);
break;
case INCREMENTCOUNT:
val = makeSubstitutions(v, linkedId);
sv = new SubVals(sv, val);
}
- avs.addValue(sv, val, argIndex);
+ avs.addValue(sv, val, argIndex, false);
}
else
{
{
val = makeSubstitutions(v, linkedId);
}
- avs.addValue(val, argIndex);
+ avs.addValue(val, argIndex, false);
}
finaliseStoringArgValue(linkedId, avs);
break;
case SETBOOLEAN:
- avs.setBoolean(b, argIndex);
+ avs.setBoolean(b, argIndex, false);
finaliseStoringArgValue(linkedId, avs);
break;
case SETNEGATED:
- avs.setNegated(b);
+ avs.setNegated(b, false);
break;
case INCREMENTCOUNT:
private boolean negated = false;
+ private boolean setByWildcard = false;
+
private int boolIndex = -1;
private List<Integer> argsIndexes;
this.boolValue = arg.getDefaultBoolValue();
}
+ protected boolean setByWildcard()
+ {
+ return setByWildcard;
+ }
+
+ protected void setSetByWildcard(boolean b)
+ {
+ setByWildcard = b;
+ }
+
public Arg arg()
{
return arg;
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(boolean b, int i, boolean beingSetByWildcard)
{
+ // 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()
- {
- addValue(null, -1);
- }
-
- protected void addValue(String val, int argIndex)
+ protected void addValue(String val, int argIndex, boolean wildcard)
{
- addArgValue(new ArgValue(arg(), val, argIndex));
+ addArgValue(new ArgValue(arg(), val, argIndex), wildcard);
}
- protected void addValue(SubVals sv, String content, int argIndex)
+ protected void addValue(SubVals sv, String content, int argIndex,
+ boolean wildcard)
{
- addArgValue(new ArgValue(arg(), sv, content, argIndex));
+ addArgValue(new ArgValue(arg(), sv, 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<ArgValue>();
}
idMap.put(id, av);
}
argValueList.add(av);
+ this.setSetByWildcard(beingSetByWildcard);
}
protected boolean hasValue(String val)
{
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