created ValueFunction

This commit is contained in:
Denis Molony 2017-03-20 10:21:10 +11:00
parent 60d908b6d1
commit 36750a11e7
17 changed files with 58 additions and 193 deletions

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Abs extends Function public class Abs extends ValueFunction
{ {
Abs (Cell cell, String text) Abs (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ABS(") : text; assert text.startsWith ("@ABS(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.abs (source.getValue ()); value = Math.abs (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,17 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Acos extends Function public class Acos extends ValueFunction
{ {
Acos (Cell cell, String text) Acos (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ACOS(") : text; assert text.startsWith ("@ACOS(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.acos (source.getValue ()); value = Math.acos (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Asin extends Function public class Asin extends ValueFunction
{ {
Asin (Cell cell, String text) Asin (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ASIN(") : text; assert text.startsWith ("@ASIN(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.asin (source.getValue ()); value = Math.asin (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Atan extends Function public class Atan extends ValueFunction
{ {
Atan (Cell cell, String text) Atan (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ATAN(") : text; assert text.startsWith ("@ATAN(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.atan (source.getValue ()); value = Math.atan (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Cos extends Function public class Cos extends ValueFunction
{ {
Cos (Cell cell, String text) Cos (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@COS(") : text; assert text.startsWith ("@COS(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.cos (source.getValue ()); value = Math.cos (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Exp extends Function public class Exp extends ValueFunction
{ {
Exp (Cell cell, String text) Exp (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@EXP(") : text; assert text.startsWith ("@EXP(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.exp (source.getValue ()); value = Math.exp (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,23 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Int extends Function public class Int extends ValueFunction
{ {
Int (Cell cell, String text) Int (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@INT(") : text; assert text.startsWith ("@INT(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
value = (int) source.getValue (); value = (int) source.getValue ();
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,15 +1,11 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
class IsError extends Function class IsError extends ValueFunction
{ {
public IsError (Cell cell, String text) public IsError (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ISERROR(") : text; assert text.startsWith ("@ISERROR(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
@ -19,11 +15,8 @@ class IsError extends Function
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
value = source.isValueType (ValueType.ERROR) ? 1 : 0; value = source.isValueType (ValueType.ERROR) ? 1 : 0;
valueType = ValueType.VALUE;
} }
} }

View File

@ -1,15 +1,11 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class IsNa extends Function public class IsNa extends ValueFunction
{ {
IsNa (Cell cell, String text) IsNa (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@ISNA(") : text; assert text.startsWith ("@ISNA(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
@ -19,11 +15,8 @@ public class IsNa extends Function
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
value = source.isValueType (ValueType.NA) ? 1 : 0; value = source.isValueType (ValueType.NA) ? 1 : 0;
valueType = source.getValueType ();
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Ln extends Function public class Ln extends ValueFunction
{ {
Ln (Cell cell, String text) Ln (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@LN(") : text; assert text.startsWith ("@LN(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.log (source.getValue ()); value = Math.log (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Log10 extends Function public class Log10 extends ValueFunction
{ {
Log10 (Cell cell, String text) Log10 (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@LOG10(") : text; assert text.startsWith ("@LOG10(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.log10 (source.getValue ()); value = Math.log10 (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -57,7 +57,6 @@ class Lookup extends Function
{ {
Address adjacentAddress = isVertical ? target.nextColumn () : target.nextRow (); Address adjacentAddress = isVertical ? target.nextColumn () : target.nextRow ();
// Sheet parent = cell.getParent ();
if (cell.cellExists (adjacentAddress)) if (cell.cellExists (adjacentAddress))
{ {
value = cell.getCell (adjacentAddress).getValue (); value = cell.getCell (adjacentAddress).getValue ();

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Sin extends Function public class Sin extends ValueFunction
{ {
Sin (Cell cell, String text) Sin (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@SIN(") : text; assert text.startsWith ("@SIN(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.sin (source.getValue ()); value = Math.sin (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Sqrt extends Function public class Sqrt extends ValueFunction
{ {
Sqrt (Cell cell, String text) Sqrt (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@SQRT(") : text; assert text.startsWith ("@SQRT(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.sqrt (source.getValue ()); value = Math.sqrt (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -1,29 +1,16 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Tan extends Function public class Tan extends ValueFunction
{ {
Tan (Cell cell, String text) Tan (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
assert text.startsWith ("@TAN(") : text; assert text.startsWith ("@TAN(") : text;
source = cell.getExpressionValue (functionText);
values.add (source);
} }
@Override @Override
public void calculate () public void setValue ()
{ {
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
value = Math.tan (source.getValue ()); value = Math.tan (source.getValue ());
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
} }

View File

@ -0,0 +1,30 @@
package com.bytezone.diskbrowser.visicalc;
public abstract class ValueFunction extends Function
{
ValueFunction (Cell cell, String text)
{
super (cell, text);
source = cell.getExpressionValue (functionText);
values.add (source);
}
@Override
public void calculate ()
{
source.calculate ();
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
return;
}
// value = Math.abs (source.getValue ());
setValue ();
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
}
abstract void setValue ();
}

View File

@ -11,7 +11,6 @@ public class ValueList implements Iterable<Value>
public ValueList (Cell cell, String text) public ValueList (Cell cell, String text)
{ {
// Sheet parent = cell.getParent ();
String remainder = text; String remainder = text;
while (true) while (true)