code: public int getIndexWithinSections(int listPosition) {
          boolean isSection = false;
          int numPrecedingSections = 0;
          for (Integer sectionPosition : mSections.keySet()) {
              if (listPosition > sectionPosition)
                  numPrecedingSections++;
              else if (listPosition == sectionPosition)
                  isSection = true;
              else
                  break;
          }
          return isSection ? numPrecedingSections : Math.max(numPrecedingSections - 1, 0);
      }
docs: Finds the section index for a given list position.
  
  @param listPosition the position of the current item in the list with mSections included
  @return an index in an ordered list of section names