FoldedGroupState (int start, int end, int index) { if (start == end) return null; //noinspection ConstantConditions List<FoldedGroupState> ranges = myCache.ranges[index]; for (; myIndex[index] < ranges.size(); myIndex[index]++) { FoldedGroupState range = ranges.get(myIndex[index]); LineRange lineRange = range.getLineRange(); if (lineRange.end <= start) continue; if (lineRange.contains(start, end)) return range; if (lineRange.start >= start) return null; // we could need current range for enclosing next-level foldings } return null; }