package org.lucci.madhoc.node_memory;
import java.util.Collection;
import java.util.Iterator;
import org.lucci.madhoc.network.Station;
import org.lucci.madhoc.simulation.measure.NaturalNumberSensor;
import org.lucci.madhoc.simulation.measure.Unit;
import org.lucci.madhoc.simulation.projection.Projection;
public class MemorySizeSensor extends NaturalNumberSensor
{
public Unit getUnit()
{
return Unit.NUMBER_OF_STATIONS;
}
public String getName()
{
return "number of known computers";
}
public Double takeNewDoubleValue(Projection projection)
{
double sum = 0;
Collection computers = projection.getNetwork().getStations();
Iterator i = computers.iterator();
while (i.hasNext())
{
Station computer = (Station) i.next();
NodeMemory app = (NodeMemory) computer.getApplicationMap().getValue(NodeMemory.class);
sum += app.getKnownComputers().size();
}
return sum / computers.size();
}
}