+ public List<ArgValue> getArgValueListFromSubValOrArg(ArgValue av, Arg a,
+ SubVals sv)
+ {
+ return getArgValueListFromSubValArgOrPrefWithSubstitutionsWithinTypes(
+ null, a, Position.AFTER, av, sv, null, null, null, true);
+ }
+
+ public List<ArgValue> getArgValueListFromSubValArgOrPrefWithSubstitutionsWithinTypes(
+ ArgParser ap, Arg a, ArgValuesMap.Position pos, ArgValue av,
+ SubVals sv, String key, String pref, String def,
+ boolean withinTypes)
+ {
+ if (key == null)
+ key = a.getName();
+ List<ArgValue> avList = new ArrayList<>();
+ if (sv != null && sv.has(key) && sv.get(key) != null)
+ {
+ String value = ap == null ? sv.get(key)
+ : sv.getWithSubstitutions(ap, getLinkedId(), key);
+ // protected ArgValue(Arg a, SubVals sv, Type type, String content, int
+ // argIndex)
+
+ avList.add(new ArgValue(a, null, null, value, av.getArgIndex()));
+ }
+ else if (containsArg(a))
+ {
+ if (pos == ArgValuesMap.Position.FIRST && getValue(a) != null)
+ avList.add(getArgValue(a));
+ else if (pos == ArgValuesMap.Position.BEFORE
+ && getClosestPreviousArgValueOfArg(av, a) != null)
+ {
+ for (ArgValue tmpAv : getArgValues(a).getArgValueList())
+ {
+ if (tmpAv.getArgIndex() >= av.getArgIndex())
+ {
+ continue;
+ }
+ avList.add(tmpAv);
+ }
+ }
+ else if (pos == ArgValuesMap.Position.AFTER
+ && getClosestNextArgValueOfArg(av, a, withinTypes) != null)
+ {
+ for (ArgValue tmpAv : getArgValues(a).getArgValueList())
+ {
+ if (tmpAv.getArgIndex() <= av.getArgIndex())
+ {
+ continue;
+ }
+ avList.add(tmpAv);
+ }
+ }
+ }
+
+ // check if withinType the avs don't belong to the next primary arg
+ // of this type. Checking for *any* shared type.
+ if (withinTypes && !avList.isEmpty())
+ {
+ int nextPrimaryArgOfSameTypeIndex = Integer.MAX_VALUE;
+ // run through every Arg used in this ArgValuesMap
+ for (Arg tmpA : this.getArgKeys())
+ {
+ // only interested in Opt.PRIMARY args of the same type
+ if (tmpA.sharesType(a) && tmpA.hasOption(Opt.PRIMARY))
+ {
+ for (ArgValue tmpAv : getArgValueList(tmpA))
+ {
+ int tmpArgIndex = tmpAv.getArgIndex();
+ if (tmpArgIndex > av.getArgIndex()
+ && tmpArgIndex < nextPrimaryArgOfSameTypeIndex)
+ {
+ nextPrimaryArgOfSameTypeIndex = tmpArgIndex;
+ }
+ }
+ }
+ }
+ List<ArgValue> tmpList = List.copyOf(avList);
+ for (ArgValue tmpAv : tmpList)
+ {
+ if (nextPrimaryArgOfSameTypeIndex < tmpAv.getArgIndex())
+ {
+ // looks like this tmpAv actually belongs to a different primary Arg
+ avList.remove(tmpAv);
+ }
+ }
+ }
+
+ return avList;
+ }
+