2016-03-07 04:37:01 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
|
|
|
|
2017-02-25 03:56:22 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
abstract class Function extends AbstractValue implements Iterable<Value>
|
2016-03-07 04:37:01 +00:00
|
|
|
{
|
2017-03-17 23:57:48 +00:00
|
|
|
static final String[] functionList =
|
|
|
|
{ "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(",
|
|
|
|
"@CHOOSE(", "@COS(", "@ERROR", "@EXP(", "@FALSE", "@IF(", "@INT(", "@ISERROR(",
|
2017-03-18 00:24:05 +00:00
|
|
|
"@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NPV(", "@OR(",
|
2017-03-17 23:57:48 +00:00
|
|
|
"@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
|
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
protected final Sheet parent;
|
2017-03-14 11:28:52 +00:00
|
|
|
protected final Cell cell;
|
2016-03-17 04:40:43 +00:00
|
|
|
protected String functionName;
|
2016-03-14 08:58:54 +00:00
|
|
|
protected String functionText;
|
2017-02-25 03:56:22 +00:00
|
|
|
protected String fullText;
|
2016-03-16 06:15:39 +00:00
|
|
|
|
2017-03-14 11:28:52 +00:00
|
|
|
static Function getInstance (Sheet parent, Cell cell, String text)
|
2016-03-07 04:37:01 +00:00
|
|
|
{
|
2016-04-16 05:33:31 +00:00
|
|
|
if (text.charAt (0) != '@')
|
|
|
|
{
|
|
|
|
System.out.printf ("Unknown function: [%s]%n", text);
|
2017-03-14 11:28:52 +00:00
|
|
|
return new Error (parent, cell, "@ERROR");
|
2016-04-16 05:33:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.charAt (1) == 'A')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@ABS("))
|
|
|
|
return new Abs (parent, cell, text);
|
2017-03-16 01:44:26 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@ACOS("))
|
|
|
|
return new Acos (parent, cell, text);
|
2016-03-09 10:38:53 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@AND("))
|
|
|
|
return new And (parent, cell, text);
|
2016-03-15 04:40:57 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@ASIN("))
|
|
|
|
return new Asin (parent, cell, text);
|
2016-03-10 02:39:23 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@ATAN("))
|
|
|
|
return new Atan (parent, cell, text);
|
2016-03-15 04:40:57 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@AVERAGE("))
|
|
|
|
return new Average (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'C')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@COUNT("))
|
|
|
|
return new Count (parent, cell, text);
|
2017-03-16 01:44:26 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@CHOOSE("))
|
|
|
|
return new Choose (parent, cell, text);
|
2016-03-15 04:40:57 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@COS("))
|
|
|
|
return new Cos (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'E')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@ERROR"))
|
|
|
|
return new Error (parent, cell, text);
|
2017-03-16 01:44:26 +00:00
|
|
|
|
2017-03-17 23:57:48 +00:00
|
|
|
if (text.startsWith ("@EXP("))
|
2017-03-16 09:58:48 +00:00
|
|
|
return new Exp (parent, cell, text);
|
|
|
|
}
|
2017-03-17 23:57:48 +00:00
|
|
|
else if (text.charAt (1) == 'F')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@FALSE"))
|
|
|
|
return new False (parent, cell, text);
|
|
|
|
}
|
2017-03-16 09:58:48 +00:00
|
|
|
else if (text.charAt (1) == 'I')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@IF("))
|
|
|
|
return new If (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@INT("))
|
|
|
|
return new Int (parent, cell, text);
|
2016-03-11 01:52:22 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@ISERROR("))
|
|
|
|
return new IsError (parent, cell, text);
|
2016-03-14 08:58:54 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@ISNA("))
|
|
|
|
return new IsNa (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'L')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@LOG10("))
|
|
|
|
return new Log10 (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@LOOKUP("))
|
|
|
|
return new Lookup (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@LN("))
|
|
|
|
return new Ln (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'M')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@MIN("))
|
|
|
|
return new Min (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@MAX("))
|
|
|
|
return new Max (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'N')
|
|
|
|
{
|
|
|
|
if (text.equals ("@NA"))
|
|
|
|
return new Na (parent, cell, text);
|
2017-03-16 01:44:26 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@NPV("))
|
|
|
|
return new Npv (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'O')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@OR("))
|
|
|
|
return new Or (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'P')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@PI"))
|
|
|
|
return new Pi (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'S')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@SIN("))
|
|
|
|
return new Sin (parent, cell, text);
|
2017-02-26 10:44:10 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@SUM("))
|
|
|
|
return new Sum (parent, cell, text);
|
2017-03-05 10:42:27 +00:00
|
|
|
|
2017-03-16 09:58:48 +00:00
|
|
|
if (text.startsWith ("@SQRT("))
|
|
|
|
return new Sqrt (parent, cell, text);
|
|
|
|
}
|
|
|
|
else if (text.charAt (1) == 'T')
|
|
|
|
{
|
|
|
|
if (text.startsWith ("@TAN("))
|
|
|
|
return new Tan (parent, cell, text);
|
2017-03-17 23:57:48 +00:00
|
|
|
|
|
|
|
if (text.startsWith ("@TRUE"))
|
|
|
|
return new True (parent, cell, text);
|
2017-03-16 09:58:48 +00:00
|
|
|
}
|
2017-03-16 01:44:26 +00:00
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
System.out.printf ("Unknown function: [%s]%n", text);
|
2017-03-14 11:28:52 +00:00
|
|
|
return new Error (parent, cell, "@ERROR");
|
2016-03-07 04:37:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-14 11:28:52 +00:00
|
|
|
Function (Sheet parent, Cell cell, String text)
|
2016-03-09 10:38:53 +00:00
|
|
|
{
|
2017-02-25 03:56:22 +00:00
|
|
|
super ("Function");
|
2016-03-09 10:38:53 +00:00
|
|
|
this.parent = parent;
|
2017-03-14 11:28:52 +00:00
|
|
|
this.cell = cell;
|
2017-02-25 03:56:22 +00:00
|
|
|
fullText = text;
|
2016-03-11 01:52:22 +00:00
|
|
|
|
|
|
|
// get function's parameter string
|
2016-03-10 02:39:23 +00:00
|
|
|
int pos = text.indexOf ('(');
|
2016-03-14 08:58:54 +00:00
|
|
|
if (pos >= 0)
|
2016-03-17 04:40:43 +00:00
|
|
|
{
|
|
|
|
functionName = text.substring (0, pos);
|
2016-03-16 06:15:39 +00:00
|
|
|
functionText = text.substring (pos + 1, text.length () - 1);
|
2016-03-17 04:40:43 +00:00
|
|
|
}
|
2016-03-16 06:15:39 +00:00
|
|
|
else
|
2016-03-17 04:40:43 +00:00
|
|
|
{
|
|
|
|
functionName = "";
|
2016-03-16 06:15:39 +00:00
|
|
|
functionText = "";
|
2016-03-17 04:40:43 +00:00
|
|
|
}
|
2016-03-16 06:15:39 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 03:56:22 +00:00
|
|
|
@Override
|
|
|
|
public Iterator<Value> iterator ()
|
|
|
|
{
|
|
|
|
return values.iterator ();
|
|
|
|
}
|
|
|
|
|
2016-03-09 10:38:53 +00:00
|
|
|
@Override
|
|
|
|
public String toString ()
|
|
|
|
{
|
2016-03-17 04:40:43 +00:00
|
|
|
return String.format ("Function: %s %s", functionName, functionText);
|
2016-03-09 10:38:53 +00:00
|
|
|
}
|
2016-03-07 04:37:01 +00:00
|
|
|
}
|