2017-02-26 10:44:10 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
|
2017-03-19 02:31:20 +00:00
|
|
|
import com.bytezone.diskbrowser.visicalc.Cell.CellType;
|
|
|
|
|
2020-02-10 11:05:40 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
class Choose extends ValueListFunction
|
|
|
|
// -----------------------------------------------------------------------------------//
|
2017-02-26 10:44:10 +00:00
|
|
|
{
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-03-18 08:33:40 +00:00
|
|
|
Choose (Cell cell, String text)
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-02-26 10:44:10 +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 ("@CHOOSE(") : text;
|
2017-02-26 10:44:10 +00:00
|
|
|
}
|
2017-03-05 10:42:27 +00:00
|
|
|
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-03-05 10:42:27 +00:00
|
|
|
@Override
|
|
|
|
public void calculate ()
|
2020-02-10 11:05:40 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2017-03-19 02:31:20 +00:00
|
|
|
{
|
|
|
|
Value source = list.get (0);
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = ValueResult.VALID;
|
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
|
|
|
int index = (int) source.getDouble ();
|
2017-03-19 02:31:20 +00:00
|
|
|
if (index < 1 || index >= list.size ())
|
|
|
|
{
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = ValueResult.NA;
|
2017-03-19 02:31:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell cell = (Cell) list.get (index);
|
|
|
|
if (cell.isCellType (CellType.EMPTY))
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = ValueResult.NA;
|
2017-03-19 02:31:20 +00:00
|
|
|
else
|
|
|
|
{
|
2017-03-23 13:30:41 +00:00
|
|
|
valueResult = cell.getValueResult ();
|
|
|
|
value = cell.getDouble ();
|
2017-03-16 00:27:45 +00:00
|
|
|
}
|
2017-03-05 10:42:27 +00:00
|
|
|
}
|
2017-02-26 10:44:10 +00:00
|
|
|
}
|