2017-02-26 10:44:10 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
|
|
|
|
public class Choose extends Function
|
|
|
|
{
|
2017-03-03 23:41:08 +00:00
|
|
|
private final Range range;
|
|
|
|
private final String sourceText;
|
|
|
|
private final String rangeText;
|
2017-03-16 00:27:45 +00:00
|
|
|
private final Value source;
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-14 11:28:52 +00:00
|
|
|
Choose (Sheet parent, Cell cell, String text)
|
2017-02-26 10:44:10 +00:00
|
|
|
{
|
2017-03-14 11:28:52 +00:00
|
|
|
super (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 00:27:45 +00:00
|
|
|
int pos = functionText.indexOf (',');
|
|
|
|
sourceText = functionText.substring (0, pos);
|
|
|
|
source = new Expression (parent, cell, sourceText).reduce ();
|
|
|
|
rangeText = functionText.substring (pos + 1);
|
2017-03-15 00:41:45 +00:00
|
|
|
range = new Range (parent, cell, rangeText);
|
2017-03-03 23:41:08 +00:00
|
|
|
|
|
|
|
values.add (source);
|
2017-02-26 10:44:10 +00:00
|
|
|
}
|
2017-03-05 10:42:27 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void calculate ()
|
|
|
|
{
|
|
|
|
source.calculate ();
|
2017-03-16 00:27:45 +00:00
|
|
|
Address address = range.get ((int) source.getValue () - 1);
|
|
|
|
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
|
|
|
}
|