+ public List<ArgValue> getArgValueListFromSubValOrArg(ArgValue av, Arg a,
+ SubVals sv)
+ {
+ return getArgValueListFromSubValArgOrPrefWithSubstitutionsWithinTypes(
+ null, a, Position.AFTER, av, sv, null, null, null, true, null);
+ }
+
+ public List<ArgValue> getArgValueListFromSubValArgOrPrefWithSubstitutionsWithinTypes(
+ ArgParser ap, Arg a, ArgValuesMap.Position pos, ArgValue av,
+ SubVals sv, String key, String pref, String def,
+ boolean withinTypes, Type type)
+ {
+ if (key == null)
+ {
+ key = a.getName();
+ }
+ Set<Type> types = new HashSet<>();
+ if (type == null)
+ {
+ types.addAll(Arrays.asList(av.getArg().getTypes()));
+ }
+ else
+ {
+ types.add(type);
+ }
+ 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)
+
+ ArgValue svav = new ArgValue(a, null, null, value, av.getArgIndex(),
+ false, null, this.getLinkedId());
+ avList.add(svav);
+ }
+ 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 looking up to next Opt.PRIMARY args of the same
+ // type as av (or provided type)
+ if (tmpA.hasType(types) && tmpA.hasOption(Opt.PRIMARY))
+ {
+ for (ArgValue tmpAv : getArgValueList(tmpA))
+ {
+ int tmpArgIndex = tmpAv.getArgIndex();
+ if (tmpArgIndex > av.getArgIndex()
+ && tmpArgIndex < nextPrimaryArgOfSameTypeIndex)
+ {
+ nextPrimaryArgOfSameTypeIndex = tmpArgIndex;
+ }
+ }
+ }
+ }
+ List<ArgValue> tmpList = new ArrayList<>();
+ for (ArgValue tmpAv : avList)
+ {
+ int tmpAvIndex = tmpAv.getArgIndex();
+ if (av.getArgIndex() < tmpAvIndex
+ && tmpAvIndex < nextPrimaryArgOfSameTypeIndex)
+ {
+ tmpList.add(tmpAv);
+ }
+ }
+ avList = tmpList;
+ }
+
+ return avList;
+ }
+