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

49 lines
1.4 KiB
Java
Raw Permalink Normal View History

2017-02-26 10:44:10 +00:00
package com.bytezone.diskbrowser.visicalc;
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
// ---------------------------------------------------------------------------------//
Choose (Cell cell, String text)
2020-02-10 11:05:40 +00:00
// ---------------------------------------------------------------------------------//
2017-02-26 10:44:10 +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
// ---------------------------------------------------------------------------------//
{
Value source = list.get (0);
2017-03-23 13:30:41 +00:00
valueResult = ValueResult.VALID;
source.calculate ();
2017-03-23 13:30:41 +00:00
if (!source.isValid ())
{
2017-03-23 13:30:41 +00:00
valueResult = source.getValueResult ();
return;
}
2017-03-23 13:30:41 +00:00
int index = (int) source.getDouble ();
if (index < 1 || index >= list.size ())
{
2017-03-23 13:30:41 +00:00
valueResult = ValueResult.NA;
return;
}
Cell cell = (Cell) list.get (index);
if (cell.isCellType (CellType.EMPTY))
2017-03-23 13:30:41 +00:00
valueResult = ValueResult.NA;
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
}