FileDocCategorySizeDatePackage
MapItem.javaAPI DocAndroid 1.5 API7076Wed May 06 22:41:02 BST 2009com.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 uints
private final ItemType
type
non-null; item type this instance covers
private final Section
section
non-null; section this instance covers
private final Item
firstItem
null-ok; first item covered or null if this is a self-reference
private final Item
lastItem
null-ok; last item covered or null if this is a self-reference
private final int
itemCount
> 0; count of items covered; 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 non-null; item type this instance covers
param
section non-null; section this instance covers
param
firstItem non-null; first item covered
param
lastItem non-null; last item covered
param
itemCount > 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 map_list.

param
section 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 non-null; the sections
param
mapSection 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);