boolean canBeUsedByOrderByAfterFilter(OIndex<?> index, List<String> equalsFilterFields,
      List<OPair<String, String>> orderedFields) {
    if (orderedFields.isEmpty())
      return false;

    if (!index.supportsOrderedIterations())
      return false;

    final OIndexDefinition definition = index.getDefinition();
    final List<String> indexFields = definition.getFields();
    int endIndex = Math.min(indexFields.size(), equalsFilterFields.size());

    final String firstOrder = orderedFields.get(0).getValue();

    //check that all the "equals" clauses are a prefix for the index
    for (int i = 0; i < endIndex; i++) {
      final String equalsFieldName = equalsFilterFields.get(i);
      final String indexFieldName = indexFields.get(i);
      if (!equalsFieldName.equals(indexFieldName))
        return false;
    }

    endIndex = Math.min(indexFields.size(), orderedFields.size() + equalsFilterFields.size());
    if (endIndex == equalsFilterFields.size()) {
      //the index is used only for filtering
      return false;
    }
    //check that after that prefix there all the Order By fields in the right order
    for (int i = equalsFilterFields.size(); i < endIndex; i++) {
      int fieldOrderInOrderByClause = i - equalsFilterFields.size();
      final OPair<String, String> pair = orderedFields.get(fieldOrderInOrderByClause);

      if (!firstOrder.equals(pair.getValue()))
        return false;

      final String orderFieldName = pair.getKey();
      final String indexFieldName = indexFields.get(i);

      if (!orderFieldName.equals(indexFieldName))
        return false;
    }

    return true;
  }
boolean canBeUsedByOrderByAfterFilter ( OIndex < ? > index , List < String > equalsFilterFields , List < OPair < String , String > > orderedFields ) { if ( orderedFields . isEmpty ( ) ) return false ; if ( ! index . supportsOrderedIterations ( ) ) return false ; final OIndexDefinition definition = index . getDefinition ( ) ; final List < String > indexFields = definition . getFields ( ) ; int endIndex = Math . min ( indexFields . size ( ) , equalsFilterFields . size ( ) ) ; final String firstOrder = orderedFields . get ( 0 ) . getValue ( ) ; for ( int i = 0 ; i < endIndex ; i ++ ) { final String equalsFieldName = equalsFilterFields . get ( i ) ; final String indexFieldName = indexFields . get ( i ) ; if ( ! equalsFieldName . equals ( indexFieldName ) ) return false ; } endIndex = Math . min ( indexFields . size ( ) , orderedFields . size ( ) + equalsFilterFields . size ( ) ) ; if ( endIndex == equalsFilterFields . size ( ) ) { return false ; } for ( int i = equalsFilterFields . size ( ) ; i < endIndex ; i ++ ) { int fieldOrderInOrderByClause = i - equalsFilterFields . size ( ) ; final OPair < String , String > pair = orderedFields . get ( fieldOrderInOrderByClause ) ; if ( ! firstOrder . equals ( pair . getValue ( ) ) ) return false ; final String orderFieldName = pair . getKey ( ) ; final String indexFieldName = indexFields . get ( i ) ; if ( ! orderFieldName . equals ( indexFieldName ) ) return false ; } return true ; }
checks if, given a list of "=" conditions and a set of ORDER BY fields

@param index
@param equalsFilterFields
@param orderedFields
@return