public static void addMap(Section[] sections, MixedItemSection mapSection) {
    if (sections == null) {
      throw new NullPointerException("sections == null");
    }

    if (mapSection.items().size() != 0) {
      throw new IllegalArgumentException("mapSection.items().size() != 0");
    }

    ArrayList<MapItem> items = new ArrayList<MapItem>(50);

    for (Section section : sections) {
      ItemType currentType = null;
      Item firstItem = null;
      Item lastItem = null;
      int count = 0;

      for (Item item : section.items()) {
        ItemType type = item.itemType();
        if (type != currentType) {
          if (count != 0) {
            items.add(new MapItem(currentType, section, firstItem, lastItem, count));
          }
          currentType = type;
          firstItem = item;
          count = 0;
        }
        lastItem = item;
        count++;
      }

      if (count != 0) {
        // Add a MapItem for the final items in the section.
        items.add(new MapItem(currentType, section, firstItem, lastItem, count));
      } else if (section == mapSection) {
        // Add a MapItem for the self-referential section.
        items.add(new MapItem(mapSection));
      }
    }

    mapSection.add(new UniformListItem<MapItem>(ItemType.TYPE_MAP_LIST, items));
  }
Constructs a list item with instances of this class representing the contents of the given
array of sections, adding it to the given map section.

@param sections {@code non-null;} the sections
@param mapSection {@code non-null;} the section that the resulting map should be added to; it
    should be empty on entry to this method
android/android_framework/dex-maker/src/main/java/com/android/dx/dex/file/MapItem.java