FileDocCategorySizeDatePackage
MapItem.javaAPI DocAndroid 5.1 API7131Thu Mar 12 22:18:30 GMT 2015com.android.dx.dex.file

MapItem

public final class MapItem extends OffsettedItem
Class that represents a map item.

Fields Summary
private static final int
ALIGNMENT
file alignment of this class, in bytes
private static final int
WRITE_SIZE
write size of this class, in bytes: three {@code uint}s
private final ItemType
type
{@code non-null;} item type this instance covers
private final Section
section
{@code non-null;} section this instance covers
private final Item
firstItem
{@code null-ok;} first item covered or {@code null} if this is a self-reference
private final Item
lastItem
{@code null-ok;} last item covered or {@code null} if this is a self-reference
private final int
itemCount
{@code > 0;} count of items covered; {@code 1} if this is a self-reference
Constructors Summary
private MapItem(ItemType type, Section section, Item firstItem, Item lastItem, int itemCount)
Constructs an instance.

param
type {@code non-null;} item type this instance covers
param
section {@code non-null;} section this instance covers
param
firstItem {@code non-null;} first item covered
param
lastItem {@code non-null;} last item covered
param
itemCount {@code > 0;} count of items covered

        super(ALIGNMENT, WRITE_SIZE);

        if (type == null) {
            throw new NullPointerException("type == null");
        }

        if (section == null) {
            throw new NullPointerException("section == null");
        }

        if (firstItem == null) {
            throw new NullPointerException("firstItem == null");
        }

        if (lastItem == null) {
            throw new NullPointerException("lastItem == null");
        }

        if (itemCount <= 0) {
            throw new IllegalArgumentException("itemCount <= 0");
        }

        this.type = type;
        this.section = section;
        this.firstItem = firstItem;
        this.lastItem = lastItem;
        this.itemCount = itemCount;
    
private MapItem(Section section)
Constructs a self-referential instance. This instance is meant to represent the section containing the {@code map_list}.

param
section {@code non-null;} section this instance covers

        super(ALIGNMENT, WRITE_SIZE);

        if (section == null) {
            throw new NullPointerException("section == null");
        }

        this.type = ItemType.TYPE_MAP_LIST;
        this.section = section;
        this.firstItem = null;
        this.lastItem = null;
        this.itemCount = 1;
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        // We have nothing to add.
    
public static voidaddMap(Section[] sections, MixedItemSection mapSection)
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


                                                               
        
              
        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));
    
public ItemTypeitemType()
{@inheritDoc}

        return ItemType.TYPE_MAP_ITEM;
    
public final java.lang.StringtoHuman()
{@inheritDoc}

        return toString();
    
public java.lang.StringtoString()
{@inheritDoc}

        StringBuffer sb = new StringBuffer(100);

        sb.append(getClass().getName());
        sb.append('{");
        sb.append(section.toString());
        sb.append(' ");
        sb.append(type.toHuman());
        sb.append('}");

        return sb.toString();
    
protected voidwriteTo0(DexFile file, com.android.dx.util.AnnotatedOutput out)
{@inheritDoc}

        int value = type.getMapValue();
        int offset;

        if (firstItem == null) {
            offset = section.getFileOffset();
        } else {
            offset = section.getAbsoluteItemOffset(firstItem);
        }

        if (out.annotates()) {
            out.annotate(0, offsetString() + ' " + type.getTypeName() +
                    " map");
            out.annotate(2, "  type:   " + Hex.u2(value) + " // " +
                    type.toString());
            out.annotate(2, "  unused: 0");
            out.annotate(4, "  size:   " + Hex.u4(itemCount));
            out.annotate(4, "  offset: " + Hex.u4(offset));
        }

        out.writeShort(value);
        out.writeShort(0); // unused
        out.writeInt(itemCount);
        out.writeInt(offset);