public static int indexFor(Composite name, List<IndexInfo> indexList, CType comparator, boolean reversed, int lastIndex)
    {
        if (name.isEmpty())
            return lastIndex >= 0 ? lastIndex : reversed ? indexList.size() - 1 : 0;

        if (lastIndex >= indexList.size())
            return -1;

        IndexInfo target = new IndexInfo(name, name, 0, 0);
        /*
        Take the example from the unit test, and say your index looks like this:
        [0..5][10..15][20..25]
        and you look for the slice [13..17].

        When doing forward slice, we we doing a binary search comparing 13 (the start of the query)
        to the lastName part of the index slot. You'll end up with the "first" slot, going from left to right,
        that may contain the start.

        When doing a reverse slice, we do the same thing, only using as a start column the end of the query,
        i.e. 17 in this example, compared to the firstName part of the index slots.  bsearch will give us the
        first slot where firstName > start ([20..25] here), so we subtract an extra one to get the slot just before.
        */
        int startIdx = 0;
        List<IndexInfo> toSearch = indexList;
        if (lastIndex >= 0)
        {
            if (reversed)
            {
                toSearch = indexList.subList(0, lastIndex + 1);
            }
            else
            {
                startIdx = lastIndex;
                toSearch = indexList.subList(lastIndex, indexList.size());
            }
        }
        int index = Collections.binarySearch(toSearch, target, getComparator(comparator, reversed));
        return startIdx + (index < 0 ? -index - (reversed ? 2 : 1) : index);
    }
public static int indexFor ( Composite name , List < IndexInfo > indexList , CType comparator , boolean reversed , int lastIndex ) { if ( name . isEmpty ( ) ) return lastIndex >= 0 ? lastIndex : reversed ? indexList . size ( ) - 1 : 0 ; if ( lastIndex >= indexList . size ( ) ) return - 1 ; IndexInfo target = new IndexInfo ( name , name , 0 , 0 ) ; int startIdx = 0 ; List < IndexInfo > toSearch = indexList ; if ( lastIndex >= 0 ) { if ( reversed ) { toSearch = indexList . subList ( 0 , lastIndex + 1 ) ; } else { startIdx = lastIndex ; toSearch = indexList . subList ( lastIndex , indexList . size ( ) ) ; } } int index = Collections . binarySearch ( toSearch , target , getComparator ( comparator , reversed ) ) ; return startIdx + ( index < 0 ? - index - ( reversed ? 2 : 1 ) : index ) ; }
The index of the IndexInfo in which a scan starting with @name should begin.

@param name
name of the index

@param indexList
list of the indexInfo objects

@param comparator
comparator type

@param reversed
is name reversed

@return int index