dmolony-DiskBrowser/src/com/bytezone/diskbrowser/visicalc/Average.java

45 lines
838 B
Java
Raw Normal View History

2017-02-26 10:44:10 +00:00
package com.bytezone.diskbrowser.visicalc;
public class Average extends Function
{
private final Range range;
public Average (Sheet parent, String text)
{
super (parent, text);
range = new Range (text);
}
@Override
public Value calculate ()
{
double total = 0.0;
int totalChecked = 0;
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell == null || cell.isValueType (ValueType.NA))
continue;
if (!cell.isValueType (ValueType.VALUE))
{
valueType = cell.getValueType ();
break;
}
total += cell.getValue ();
totalChecked++;
}
if (totalChecked == 0)
valueType = ValueType.NA;
else
{
value = total / totalChecked;
valueType = ValueType.VALUE;
}
return this;
}
}