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-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 02:22:49 +00:00
|
|
|
// int pos = functionText.indexOf (',');
|
|
|
|
// sourceText = functionText.substring (0, pos);
|
|
|
|
sourceText = Expression.getParameter (functionText);
|
2017-03-16 00:27:45 +00:00
|
|
|
source = new Expression (parent, cell, sourceText).reduce ();
|
2017-03-03 23:41:08 +00:00
|
|
|
values.add (source);
|
2017-03-18 02:22:49 +00:00
|
|
|
|
|
|
|
rangeText = functionText.substring (sourceText.length () + 1);
|
|
|
|
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
|
|
|
}
|