package org.lucci.madhoc.network.monitor.measure;

import java.util.Iterator;

import org.lucci.madhoc.network.Connection;
import org.lucci.madhoc.simulation.measure.NaturalIntegerSensor;
import org.lucci.madhoc.simulation.measure.Unit;
import org.lucci.madhoc.simulation.projection.Projection;

/*
 * Created on Jul 7, 2004
 */

/**
 * @author luc.hogie
 */

public class ConnectionUsedCountSensor extends NaturalIntegerSensor
{
    /* (non-Javadoc)
     * @see org.lucci.madhoc.simulation.Measure#takeNewValue(org.lucci.madhoc.simulation.Simulation)
     */
    public Integer takeNewIntegerValue(Projection projection)
    {
        int n = 0;
        Iterator i = projection.getNetwork().getConnections().iterator();
        
        while (i.hasNext())
        {
            Connection c = (Connection) i.next();
            
            if (c.getUsedBandwith() > 0)
            {
                ++n;
            }
        }
        
        return n;
    }

        /* (non-Javadoc)
         * @see org.lucci.madhoc.simulation.Measure#getName()
         */
        public String getName()
        {
            return "number of connections used";
        }

        /* (non-Javadoc)
         * @see org.lucci.madhoc.simulation.NumericalMeasure#getUnit()
         */
        public Unit getUnit()
        {
            return Unit.NUMBER_OF_CONNECTION;
        }
    
}