int (int currentIndex, boolean scrollDown) { int index = currentIndex; do { index += scrollDown ? 1 : -1; } while (index >= 0 && index < getSize() && !isGroupFirstItem(index) && !isMoreElement(index)); return Integer.max(Integer.min(index, getSize() - 1), 0); }