2016-03-15 04:40:57 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
|
2017-03-16 00:27:45 +00:00
|
|
|
import com.bytezone.diskbrowser.visicalc.Cell.CellType;
|
|
|
|
|
2020-02-10 11:05:40 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
class Npv extends ValueListFunction
|
|
|
|
// -----------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-03-18 08:33:40 +00:00
|
|
|
Npv (Cell cell, String text)
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
2017-03-18 08:33:40 +00:00
|
|
|
super (cell, text);
|
2017-03-23 13:30:41 +00:00
|
|
|
|
2017-03-18 09:21:11 +00:00
|
|
|
assert text.startsWith ("@NPV(") : text;
|
2016-03-15 04:40:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
@Override
|
2017-02-28 20:39:26 +00:00
|
|
|
public void calculate ()
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
2016-03-16 06:15:39 +00:00
|
|
|
value = 0;
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = ValueResult.VALID;
|
2016-03-15 04:40:57 +00:00
|
|
|
|
2017-03-20 07:17:46 +00:00
|
|
|
Value source = list.get (0); // first Value is the rate
|
2017-03-19 02:31:20 +00:00
|
|
|
source.calculate ();
|
2017-03-23 13:30:41 +00:00
|
|
|
|
|
|
|
if (!source.isValid ())
|
2017-03-19 02:31:20 +00:00
|
|
|
{
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = source.getValueResult ();
|
2017-03-19 02:31:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-23 13:30:41 +00:00
|
|
|
double rate = 1 + source.getDouble ();
|
2017-03-19 02:31:20 +00:00
|
|
|
int period = 0;
|
|
|
|
|
2017-03-20 07:17:46 +00:00
|
|
|
for (int i = 1; i < list.size (); i++) // remaining Values are Cells
|
|
|
|
{
|
2017-03-19 02:31:20 +00:00
|
|
|
++period;
|
|
|
|
|
2017-03-20 07:17:46 +00:00
|
|
|
Cell cell = (Cell) list.get (i);
|
2017-03-16 00:27:45 +00:00
|
|
|
if (cell.isCellType (CellType.EMPTY))
|
2016-03-16 06:15:39 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-23 13:30:41 +00:00
|
|
|
if (!cell.isValid ())
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = source.getValueResult ();
|
2017-03-08 09:18:59 +00:00
|
|
|
return;
|
2016-03-15 04:40:57 +00:00
|
|
|
}
|
2016-03-16 06:15:39 +00:00
|
|
|
|
2017-03-23 13:30:41 +00:00
|
|
|
value += cell.getDouble () / Math.pow (rate, period);
|
2016-03-15 04:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|