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

MethodCollection

public final class MethodCollection extends Object implements IMethodCollection
author
(C) 2001, Vlad Roubtsov

Fields Summary
private List
m_methods
Constructors Summary
MethodCollection(int capacity)

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

        visitor.visit (this, ctx);
    
public intadd(Method_info method)

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

        try
        {
            final MethodCollection _clone = (MethodCollection) super.clone ();
            
            // deep clone:
            final int methods_count = m_methods.size (); // use size() if class becomes non-final
            _clone.m_methods = new ArrayList (methods_count);
            for (int m = 0; m < methods_count; ++ m)
            {
                _clone.m_methods.add (((Method_info) m_methods.get (m)).clone ());
            }
            
            return _clone;
        }
        catch (CloneNotSupportedException e)
        {
            throw new InternalError (e.toString ());
        }        
    
public Method_infoget(int offset)

        return (Method_info) m_methods.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_methods.size (); // use size() if class becomes non-final
        final IntVector result = new IntVector (count);

        for (int m = 0; m < count; ++ m)
        {
            final Method_info method = (Method_info) m_methods.get (m);
            
            if (method.getName (cls).equals (name))  
                result.add (m);
        }
        
        return result.values (); // IntVector optimizes for the empty case 
    
public Method_inforemove(int offset)

        return (Method_info) m_methods.remove (offset);
    
public Method_infoset(int offset, Method_info method)

        return (Method_info) m_methods.set (offset, method);
    
public intsize()

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

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