Selection { public static Trampoline<Optional<ParseItem>> findItemAtOffset(final ImmutableList<ParseItem> items, final BigInteger offset, final Source source) { checkNotNull(items, "items"); checkNotNull(source, "source"); if (items.isEmpty()) { return complete(Optional::empty); } final ParseItem head = items.head; if (head.isValue() && matchesLocation(head.asValue(), offset, source)) { return complete(() -> Optional.of(head)); } if (head.isGraph()) { final ParseValue value = getLowestOffsetValue(ImmutableList.create(head.asGraph()), null).computeResult(); if (value != null && matchesLocation(value, offset, source)) { return complete(() -> Optional.of(head)); } } return intermediate(() -> findItemAtOffset(items.tail, offset, source)); } private  Selection(); static boolean hasRootAtOffset(final ParseGraph graph, final Token definition, final BigInteger offset, final Source source); static Trampoline<Optional<ParseItem>> findItemAtOffset(final ImmutableList<ParseItem> items, final BigInteger offset, final Source source); static ImmutableList<ParseValue> getAllValues(final ParseGraph graph, final Predicate<ParseValue> predicate, final int limit); static ImmutableList<ParseValue> getAllValues(final ParseGraph graph, final Predicate<ParseValue> predicate); static ImmutableList<T> reverse(final ImmutableList<T> list); static ImmutableList<ParseItem> getAllRoots(final ParseGraph graph, final Token definition); static final int NO_LIMIT; }
@Test public void findItemAtOffsetTest() { assertEquals("the_one", findItemAtOffset(ImmutableList.create(ParseGraph.EMPTY.add(new ParseValue("two", any("a"), Slice.createFromSource(source, BigInteger.valueOf(2), BigInteger.valueOf(2)).get(), enc())) .add(new ParseValue("zero", any("a"), Slice.createFromSource(source, ZERO, BigInteger.valueOf(2)).get(), enc())) .add(new ParseValue("the_one", any("a"), Slice.createFromSource(source, ONE, BigInteger.valueOf(2)).get(), enc()))), ZERO, source).computeResult().get().asGraph().head.asValue().name); }