FileDocCategorySizeDatePackage
StringIdsSection.javaAPI DocAndroid 1.5 API5630Wed May 06 22:41:02 BST 2009com.android.dx.dex.file

StringIdsSection

public final class StringIdsSection extends UniformItemSection
Strings list section of a .dex file.

Fields Summary
private final TreeMap
strings
non-null; map from string constants to {@link StringIdItem} instances
Constructors Summary
public StringIdsSection(DexFile file)
Constructs an instance. The file offset is initially unknown.

param
file non-null; file that this instance is part of

        super("string_ids", file, 4);

        strings = new TreeMap<CstUtf8, StringIdItem>();
    
Methods Summary
public IndexedItemget(com.android.dx.rop.cst.Constant cst)
{@inheritDoc}

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

        throwIfNotPrepared();

        if (cst instanceof CstString) {
            cst = ((CstString) cst).getString();
        }

        IndexedItem result = strings.get((CstUtf8) cst);

        if (result == null) {
            throw new IllegalArgumentException("not found");
        }

        return result;
    
public intindexOf(com.android.dx.rop.cst.CstUtf8 string)
Gets the index of the given string, which must have been added to this instance.

param
string non-null; the string to look up
return
>= 0; the string's index

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

        throwIfNotPrepared();

        StringIdItem s = strings.get(string);

        if (s == null) {
            throw new IllegalArgumentException("not found");
        }

        return s.getIndex();
    
public intindexOf(com.android.dx.rop.cst.CstString string)
Gets the index of the given string, which must have been added to this instance.

param
string non-null; the string to look up
return
>= 0; the string's index

        return indexOf(string.getString());
    
public StringIdItemintern(java.lang.String string)
Interns an element into this instance.

param
string non-null; the string to intern, as a regular Java String
return
non-null; the interned string

        CstUtf8 utf8 = new CstUtf8(string);
        return intern(new StringIdItem(utf8));
    
public StringIdItemintern(com.android.dx.rop.cst.CstString string)
Interns an element into this instance.

param
string non-null; the string to intern, as a {@link CstString}
return
non-null; the interned string

        CstUtf8 utf8 = string.getString();
        return intern(new StringIdItem(utf8));
    
public StringIdItemintern(com.android.dx.rop.cst.CstUtf8 string)
Interns an element into this instance.

param
string non-null; the string to intern, as a constant
return
non-null; the interned string

        return intern(new StringIdItem(string));
    
public StringIdItemintern(StringIdItem string)
Interns an element into this instance.

param
string non-null; the string to intern
return
non-null; the interned string

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

        throwIfPrepared();

        CstUtf8 value = string.getValue();
        StringIdItem already = strings.get(value);

        if (already != null) {
            return already;
        }

        strings.put(value, string);
        return string;
    
public voidintern(com.android.dx.rop.cst.CstNat nat)
Interns the components of a name-and-type into this instance.

param
nat non-null; the name-and-type

        intern(nat.getName());
        intern(nat.getDescriptor());
    
public java.util.Collectionitems()
{@inheritDoc}

        return strings.values();
    
protected voidorderItems()
{@inheritDoc}

        int idx = 0;

        for (StringIdItem s : strings.values()) {
            s.setIndex(idx);
            idx++;
        }
    
public voidwriteHeaderPart(com.android.dx.util.AnnotatedOutput out)
Writes the portion of the file header that refers to this instance.

param
out non-null; where to write

        throwIfNotPrepared();

        int sz = strings.size();
        int offset = (sz == 0) ? 0 : getFileOffset();

        if (out.annotates()) {
            out.annotate(4, "string_ids_size: " + Hex.u4(sz));
            out.annotate(4, "string_ids_off:  " + Hex.u4(offset));
        }

        out.writeInt(sz);
        out.writeInt(offset);