mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-12 15:29:28 +00:00
55 lines
1.4 KiB
Java
55 lines
1.4 KiB
Java
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
import com.bytezone.diskbrowser.visicalc.Cell.CellType;
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
class Average extends ValueListFunction
|
|
// -----------------------------------------------------------------------------------//
|
|
{
|
|
// ---------------------------------------------------------------------------------//
|
|
Average (Cell cell, String text)
|
|
// ---------------------------------------------------------------------------------//
|
|
{
|
|
super (cell, text);
|
|
|
|
assert text.startsWith ("@AVERAGE(") : text;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------//
|
|
@Override
|
|
public void calculate ()
|
|
// ---------------------------------------------------------------------------------//
|
|
{
|
|
double total = 0.0;
|
|
int totalChecked = 0;
|
|
valueResult = ValueResult.VALID;
|
|
|
|
for (Value v : list)
|
|
{
|
|
if (v instanceof Cell cell && cell.isCellType (CellType.EMPTY))
|
|
continue;
|
|
|
|
v.calculate ();
|
|
|
|
if (v.getValueResult () == ValueResult.NA)
|
|
continue;
|
|
|
|
if (!v.isValid ())
|
|
{
|
|
valueResult = v.getValueResult ();
|
|
return;
|
|
}
|
|
|
|
total += v.getDouble ();
|
|
totalChecked++;
|
|
}
|
|
|
|
if (totalChecked == 0)
|
|
{
|
|
valueResult = ValueResult.ERROR;
|
|
return;
|
|
}
|
|
|
|
value = total / totalChecked;
|
|
}
|
|
} |