int (int textOffset, int[] tokenOffsets, boolean leanForward) { if (textOffset < 0 || textOffset > length()) { throw new IllegalArgumentException("Text offset " + textOffset + " should be between 0 and " + length()); } int index = Arrays.binarySearch(tokenOffsets, textOffset); if (index < 0) return -index - 2; if (leanForward) { while (index < tokens.size() - 1 && tokens.get(index).length() == 0) index++; if (tokens.get(index) instanceof WSTokenInfo) { index--; } } else { if (index > 0 && !(tokens.get(index - 1) instanceof WSTokenInfo)) index--; } return index; }