FileDocCategorySizeDatePackage
Item.javaAPI DocAndroid 1.5 API4625Wed May 06 22:41:16 BST 2009com.vladium.emma.report

Item

public abstract class Item extends Object implements IItem
author
Vlad Roubtsov, (C) 2003

Fields Summary
protected final IItem
m_parent
protected final int[]
m_aggregates
private final List
m_children
Constructors Summary
Item(IItem parent)

        m_parent = parent;
        m_children = new ArrayList ();
        
        m_aggregates = new int [NUM_OF_AGGREGATES];
        for (int i = 0; i < m_aggregates.length; ++ i) m_aggregates [i] = -1;
    
Methods Summary
protected voidaddChild(IItem item)

        if (item == null) throw new IllegalArgumentException ("null input: item");
        
        m_children.add (item);
    
public intgetAggregate(int type)

        final int [] aggregates = m_aggregates;
        int value = aggregates [type];
        
        if (value < 0)
        {
            // don't fault aggregate types all at once since there are
            // plenty of exceptions to the additive roll up rule:
            
            value = 0;
            for (Iterator children = m_children.iterator (); children.hasNext (); )
            {
                value += ((IItem) children.next ()).getAggregate (type);
            }
            aggregates [type] = value;
            
            return value;
        }
        
        return value;
    
public final IItemAttributegetAttribute(int attributeID, int unitsID)

        //if ($assert.ENABLED) $assert.ASSERT ((attributeID & getMetadata ().getAttributeIDs ()) != 0, "invalid attribute ID [" + attributeID + "] for type [" + getMetadata ().getTypeID () + "]");
        
        if ((getMetadata ().getAttributeIDs () & (1 << attributeID)) == 0)
            return null;
        else
            return IItemAttribute.Factory.getAttribute (attributeID, unitsID);
    
public final intgetChildCount()

        return m_children.size ();
    
public final java.util.IteratorgetChildren()

        return m_children.iterator ();
    
public final java.util.IteratorgetChildren(ItemComparator order)

        // TODO: soft caching keyed off 'order'
        
        if (order == null)
            return getChildren ();
        else
        {        
            final IItem [] items = new IItem [m_children.size ()];
            m_children.toArray (items);
            
            Arrays.sort (items, order);
            
            return Arrays.asList (items).iterator ();
        }
    
public final IItemgetParent()

        return m_parent;