FileDocCategorySizeDatePackage
FieldCollection.javaAPI DocAndroid 1.5 API3943Wed May 06 22:41:16 BST 2009com.vladium.jcd.cls

FieldCollection

public final class FieldCollection extends Object implements IFieldCollection
author
(C) 2001, Vlad Roubtsov

Fields Summary
private List
m_fields
Constructors Summary
FieldCollection(int capacity)

        m_fields = capacity < 0 ? new ArrayList () : new ArrayList (capacity);
    
Methods Summary
public voidaccept(IClassDefVisitor visitor, java.lang.Object ctx)

        visitor.visit (this, ctx);
    
public intadd(Field_info field)

        final int newoffset = m_fields.size (); // use size() if class becomes non-final
        m_fields.add (field);
        
        return newoffset;
    
public java.lang.Objectclone()
Performs a deep copy.

        try
        {
            final FieldCollection _clone = (FieldCollection) super.clone ();
            
            // deep clone:
            final int fields_count = m_fields.size (); // use size() if class becomes non-final
            _clone.m_fields = new ArrayList (fields_count);
            for (int f = 0; f < fields_count; ++ f)
            {
                _clone.m_fields.add (((Field_info) m_fields.get (f)).clone ());
            }
            
            return _clone;
        }
        catch (CloneNotSupportedException e)
        {
            throw new InternalError (e.toString ());
        }        
    
public Field_infoget(int offset)

        return (Field_info) m_fields.get (offset);
    
public int[]get(ClassDef cls, java.lang.String name)

        if (cls == null) throw new IllegalArgumentException  ("null input: cls");
        
        // TODO: hash impl [not possible without having access to the parent ClassDef]
        
        final int count = m_fields.size (); // use size() if class becomes non-final
        final IntVector result = new IntVector (count);

        for (int f = 0; f < count; ++ f)
        {
            final Field_info field = (Field_info) m_fields.get (f);
            
            if (field.getName (cls).equals (name))  
                result.add (f);
        }
        
        return result.values (); // IntVector optimizes for the empty case 
    
public Field_infoset(int offset, Field_info field)

        return (Field_info) m_fields.set (offset, field);
    
public intsize()

        return m_fields.size ();
    
public voidwriteInClassFormat(com.vladium.jcd.lib.UDataOutputStream out)

        final int fields_count = m_fields.size (); // use size() if class becomes non-final
        out.writeU2 (fields_count);
        
        for (int i = 0; i < fields_count; i++)
        {
            get (i).writeInClassFormat (out);
        }