int (List<? extends SearchResult> allMatchesAtFrame, SearchTaskOptions options) { if (!allMatchesAtFrame.isEmpty()) { SearchResult searchResult; if (options.searchForwardDirection) { /* FORWARD */ if (options.leftBoundPageNumber == SearchTaskOptions.NO_LIMIT) { return 0; } for (int i = 0; i < allMatchesAtFrame.size(); i++) { searchResult = allMatchesAtFrame.get(i); if (searchResult.startPosition.pageNumber > options.leftBoundPageNumber || searchResult.startPosition.pageNumber == options.leftBoundPageNumber && searchResult.startPosition.symbolOffsetInPage >= options.leftBoundCaretPageOffset) { return i; } } } else { /* BACKWARD */ if (options.rightBoundPageNumber == SearchTaskOptions.NO_LIMIT) { return allMatchesAtFrame.size() - 1; } for (int i = allMatchesAtFrame.size() - 1; i >= 0; i--) { searchResult = allMatchesAtFrame.get(i); if (searchResult.endPostion.pageNumber < options.rightBoundPageNumber || searchResult.endPostion.pageNumber == options.rightBoundPageNumber && searchResult.endPostion.symbolOffsetInPage < options.rightBoundCaretPageOffset) { return i; } } } } return -1; }