Skip to content

Commit

Permalink
#236: Simplified implementation of CurrentIteration, which also impro…
Browse files Browse the repository at this point in the history
…ves coverage.
  • Loading branch information
jvdb committed Jul 18, 2018
1 parent ec291c2 commit c3c961e
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ public ImmutableList<Optional<Value>> eval(final ParseState parseState, final En
}

private BigInteger findCurrentIteration(final ParseItem item, final BigInteger currentIndex) {
if (!item.isGraph() || item.asGraph().isEmpty()) { return currentIndex; }
if (!item.isGraph()) { return currentIndex; }
if (item.getDefinition().isIterable()) {
return findCurrentIteration(item.asGraph().head, countIterables(item.asGraph(), ZERO));
}
return findCurrentIteration(item.asGraph().head, currentIndex);
}

private BigInteger countIterables(final ParseGraph graph, final BigInteger count) {
if (graph.isEmpty()) { return count.subtract(ONE); }
if (graph.tail.getDefinition().equals(graph.getDefinition())) { return countIterables(graph.tail, count.add(ONE)); }
if (!graph.isEmpty()) { return countIterables(graph.tail, count.add(ONE)); }
return count.subtract(ONE);
}

Expand Down

0 comments on commit c3c961e

Please sign in to comment.