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

49 lines
988 B
Java
Raw Normal View History

2017-02-26 10:44:10 +00:00
package com.bytezone.diskbrowser.visicalc;
public class Average extends Function
{
2017-03-15 00:41:45 +00:00
// private final Range range;
private final ExpressionList list;
2017-02-26 10:44:10 +00:00
2017-03-14 11:28:52 +00:00
public Average (Sheet parent, Cell cell, String text)
2017-02-26 10:44:10 +00:00
{
2017-03-14 11:28:52 +00:00
super (parent, cell, text);
2017-03-03 23:41:08 +00:00
2017-03-15 00:41:45 +00:00
// range = new Range (parent, cell, text); // use list instead
list = new ExpressionList (parent, cell, functionText);
2017-02-26 10:44:10 +00:00
}
@Override
2017-02-28 20:39:26 +00:00
public void calculate ()
2017-02-26 10:44:10 +00:00
{
double total = 0.0;
int totalChecked = 0;
2017-03-15 00:41:45 +00:00
for (Value v : list)
2017-02-26 10:44:10 +00:00
{
2017-03-15 00:41:45 +00:00
v.calculate ();
// Cell cell = parent.getCell (address);
2017-03-08 09:18:59 +00:00
2017-03-15 00:41:45 +00:00
if (v.isValueType (ValueType.NA))
2017-02-26 10:44:10 +00:00
continue;
2017-03-15 00:41:45 +00:00
if (!v.isValueType (ValueType.VALUE))
2017-02-26 10:44:10 +00:00
{
2017-03-15 00:41:45 +00:00
valueType = v.getValueType ();
2017-03-08 09:18:59 +00:00
return;
2017-02-26 10:44:10 +00:00
}
2017-03-15 00:41:45 +00:00
total += v.getValue ();
2017-02-26 10:44:10 +00:00
totalChecked++;
}
if (totalChecked == 0)
{
2017-03-08 09:18:59 +00:00
valueType = ValueType.ERROR;
return;
2017-02-26 10:44:10 +00:00
}
2017-03-08 09:18:59 +00:00
value = total / totalChecked;
valueType = ValueType.VALUE;
2017-02-26 10:44:10 +00:00
}
}