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

162 lines
3.7 KiB
Java
Raw Normal View History

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;
2016-03-07 12:16:11 +00:00
// http://www.bricklin.com/history/refcard1.htm
// Functions:
// @AVERAGE
// @NPV
// @LOOKUP(v,range)
// @NA
// @ERROR
// @PI
// @ABS
// @INT
// @EXP
// @SQRT
// @LN
// @LOG10
// @SIN
// @ASIN
// @COS
// @ACOS
// @TAN
// @ATAN
2017-02-25 03:56:22 +00:00
abstract class Function extends AbstractValue implements Iterable<Value>
2016-03-07 04:37:01 +00:00
{
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-02-26 10:44:10 +00:00
if (text.startsWith ("@ABS("))
2017-03-14 11:28:52 +00:00
return new Abs (parent, cell, text);
2017-02-26 10:44:10 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@ACOS("))
return new Acos (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@AND("))
2017-03-14 11:28:52 +00:00
return new And (parent, cell, text);
2017-02-26 10:44:10 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@ASIN("))
return new Asin (parent, cell, text);
if (text.startsWith ("@ATAN("))
return new Atan (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@AVERAGE("))
2017-03-14 11:28:52 +00:00
return new Average (parent, cell, text);
2016-03-07 04:37:01 +00:00
if (text.startsWith ("@COUNT("))
2017-03-14 11:28:52 +00:00
return new Count (parent, cell, text);
2016-03-07 04:37:01 +00:00
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@CHOOSE("))
2017-03-14 11:28:52 +00:00
return new Choose (parent, cell, text);
2016-03-07 04:37:01 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@COS("))
return new Cos (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@ERROR"))
2017-03-14 11:28:52 +00:00
return new Error (parent, cell, text);
2016-03-07 04:37:01 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@EXP"))
return new Exp (parent, cell, text);
2016-03-09 10:38:53 +00:00
if (text.startsWith ("@IF("))
2017-03-14 11:28:52 +00:00
return new If (parent, cell, text);
2016-03-09 10:38:53 +00:00
2016-03-15 04:40:57 +00:00
if (text.startsWith ("@INT("))
2017-03-14 11:28:52 +00:00
return new Int (parent, cell, text);
2016-03-15 04:40:57 +00:00
2016-03-10 02:39:23 +00:00
if (text.startsWith ("@ISERROR("))
2017-03-14 11:28:52 +00:00
return new IsError (parent, cell, text);
2016-03-10 02:39:23 +00:00
2016-03-15 04:40:57 +00:00
if (text.startsWith ("@ISNA("))
2017-03-14 11:28:52 +00:00
return new IsNa (parent, cell, text);
2016-03-15 04:40:57 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@LOG10("))
return new Log10 (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@LOOKUP("))
2017-03-14 11:28:52 +00:00
return new Lookup (parent, cell, text);
2016-03-15 04:40:57 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@LN("))
return new Ln (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@MIN("))
2017-03-14 11:28:52 +00:00
return new Min (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@MAX("))
2017-03-14 11:28:52 +00:00
return new Max (parent, cell, text);
2016-03-11 01:52:22 +00:00
2016-03-14 08:58:54 +00:00
if (text.equals ("@NA"))
2017-03-14 11:28:52 +00:00
return new Na (parent, cell, text);
2016-03-14 08:58:54 +00:00
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@NPV("))
2017-03-14 11:28:52 +00:00
return new Npv (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@OR("))
2017-03-14 11:28:52 +00:00
return new Or (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@PI"))
2017-03-14 11:28:52 +00:00
return new Pi (parent, cell, text);
2017-02-26 10:44:10 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@SIN("))
return new Sin (parent, cell, text);
2017-02-26 10:44:10 +00:00
if (text.startsWith ("@SUM("))
2017-03-14 11:28:52 +00:00
return new Sum (parent, cell, text);
2017-02-26 10:44:10 +00:00
2017-03-05 10:42:27 +00:00
if (text.startsWith ("@SQRT("))
2017-03-14 11:28:52 +00:00
return new Sqrt (parent, cell, text);
2017-03-05 10:42:27 +00:00
2017-03-16 01:44:26 +00:00
if (text.startsWith ("@TAN("))
return new Tan (parent, cell, text);
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
}