+ /**
+ * Adjust lastURIStepIndex by the number of steps that are in hasContainers.
+ * A HasContainer can contain multiple steps, which skews the original index.
+ * Returns the step index and split position inside the hasContainer
+ *
+ * @param steps the list of steps to go through
+ * @param lastURIStepIndex the list index to adjust
+ * @return a Tuple<Integer, Integer> of the form (index, splitPosition)
+ */
+ private ImmutablePair<Integer, Integer> getHasContainerAdjustedIndexAndSplitPosition(List<Step> steps,
+ int lastURIStepIndex) {
+ int stepCount = 0;
+ for (int j = 0; j <= lastURIStepIndex; j++) {
+ Step step = steps.get(j);
+ if (step instanceof HasStep) {
+ stepCount += ((HasStep<?>) step).getHasContainers().size();
+ } else {
+ stepCount++;
+ }
+ if (stepCount == lastURIStepIndex) {
+ int splitPosition = stepCount + 1 - lastURIStepIndex;
+ return new ImmutablePair<>(j + 1, splitPosition);
+ } else if (stepCount > lastURIStepIndex) {
+ int splitPosition = stepCount + 1 - lastURIStepIndex;
+ return new ImmutablePair<>(j, splitPosition);
+ }
+ }
+ return new ImmutablePair<>(lastURIStepIndex, lastURIStepIndex);
+ }
+