HighlighterIterator (int startOffset) { int index = Collections.binarySearch(myPieces, new Element(startOffset, 0, null, null), Comparator.comparingInt(Element::getStart)); // index: (-insertion point - 1), where insertionPoint is the index of the first element greater than the key // and we need index of the first element that is less or equal (floorElement) if (index < 0) index = Math.max(-index - 2, 0); return new ProxyIterator(myDocument, index); }