2017-02-26 10:44:10 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
|
|
|
|
public class Choose extends Function
|
|
|
|
{
|
2017-03-18 08:33:40 +00:00
|
|
|
Choose (Cell cell, String text)
|
2017-02-26 10:44:10 +00:00
|
|
|
{
|
2017-03-18 08:33:40 +00:00
|
|
|
super (cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-18 09:21:11 +00:00
|
|
|
assert text.startsWith ("@CHOOSE(") : text;
|
|
|
|
|
2017-03-19 01:03:57 +00:00
|
|
|
String sourceText = Expression.getParameter (functionText);
|
|
|
|
source = cell.getExpressionValue (sourceText);
|
2017-03-03 23:41:08 +00:00
|
|
|
values.add (source);
|
2017-03-18 02:22:49 +00:00
|
|
|
|
2017-03-19 01:03:57 +00:00
|
|
|
String rangeText = functionText.substring (sourceText.length () + 1);
|
2017-03-18 02:22:49 +00:00
|
|
|
range = new Range (parent, cell, rangeText);
|
2017-02-26 10:44:10 +00:00
|
|
|
}
|
2017-03-05 10:42:27 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void calculate ()
|
|
|
|
{
|
|
|
|
source.calculate ();
|
2017-03-18 02:22:49 +00:00
|
|
|
if (!source.isValueType (ValueType.VALUE))
|
|
|
|
{
|
|
|
|
valueType = source.getValueType ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-16 01:44:26 +00:00
|
|
|
int index = (int) source.getValue () - 1;
|
|
|
|
if (index < 0 || index >= range.size ())
|
|
|
|
{
|
|
|
|
valueType = ValueType.NA;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Address address = range.get (index);
|
2017-03-16 00:27:45 +00:00
|
|
|
if (address == null)
|
|
|
|
valueType = ValueType.NA;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Cell cell = parent.getCell (address);
|
|
|
|
valueType = cell.getValueType ();
|
|
|
|
value = cell.getValue ();
|
|
|
|
}
|
2017-03-05 10:42:27 +00:00
|
|
|
}
|
2017-02-26 10:44:10 +00:00
|
|
|
}
|