changed setValue() to calculateValue()

This commit is contained in:
Denis Molony 2017-03-20 12:45:14 +11:00
parent 4ce850a4de
commit adeab79258
27 changed files with 84 additions and 66 deletions

View File

@ -9,8 +9,8 @@ public class Abs extends ValueFunction
} }
@Override @Override
void setValue () double calculateValue ()
{ {
value = Math.abs (source.getValue ()); return Math.abs (source.getValue ());
} }
} }

View File

@ -1,9 +1,10 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public abstract class AbstractValue implements Value public abstract class AbstractValue implements Value, Iterable<Value>
{ {
protected final String typeText; protected final String typeText;
protected double value; protected double value;
@ -71,6 +72,12 @@ public abstract class AbstractValue implements Value
return false; return false;
} }
@Override
public Iterator<Value> iterator ()
{
return values.iterator ();
}
// for debugging // for debugging
String getValueText (int depth) String getValueText (int depth)
{ {

View File

@ -5,13 +5,12 @@ 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;
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.acos (source.getValue ()); return Math.acos (source.getValue ());
} }
} }

View File

@ -9,8 +9,8 @@ public class Asin extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.asin (source.getValue ()); return Math.asin (source.getValue ());
} }
} }

View File

@ -9,8 +9,8 @@ public class Atan extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.atan (source.getValue ()); return Math.atan (source.getValue ());
} }
} }

View File

@ -96,7 +96,7 @@ class Condition extends AbstractValue implements Iterable<Value>
@Override @Override
public String toString () public String toString ()
{ {
return String.format ("[cond=%s, op=%s, value=%s]", conditionText, comparator, return String.format ("[cond=%s, op:%s, value=%s]", conditionText, comparator,
valueText); valueText);
} }

View File

@ -0,0 +1,9 @@
package com.bytezone.diskbrowser.visicalc;
public abstract class ConstantFunction extends Function
{
public ConstantFunction (Cell cell, String text)
{
super (cell, text);
}
}

View File

@ -9,8 +9,8 @@ public class Cos extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.cos (source.getValue ()); return Math.cos (source.getValue ());
} }
} }

View File

@ -1,6 +1,6 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
class Error extends Function class Error extends ConstantFunction
{ {
public Error (Cell cell, String text) public Error (Cell cell, String text)
{ {

View File

@ -9,8 +9,8 @@ public class Exp extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.exp (source.getValue ()); return Math.exp (source.getValue ());
} }
} }

View File

@ -1,10 +1,9 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
class Expression extends AbstractValue implements Iterable<Value> class Expression extends AbstractValue //implements Iterable<Value>
{ {
// Expressions: // Expressions:
// number // number
@ -386,11 +385,11 @@ class Expression extends AbstractValue implements Iterable<Value>
return text.toString (); return text.toString ();
} }
@Override // @Override
public Iterator<Value> iterator () // public Iterator<Value> iterator ()
{ // {
return values.iterator (); // return values.iterator ();
} // }
@Override @Override
public String toString () public String toString ()

View File

@ -1,6 +1,6 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class False extends Function public class False extends ConstantFunction
{ {
False (Cell cell, String text) False (Cell cell, String text)
{ {

View File

@ -1,8 +1,6 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
import java.util.Iterator; abstract class Function extends AbstractValue
abstract class Function extends AbstractValue implements Iterable<Value>
{ {
static final String[] functionList = static final String[] functionList =
{ "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(", { "@ABS(", "@ACOS(", "@AND(", "@ASIN(", "@ATAN(", "@AVERAGE(", "@COUNT(",
@ -11,13 +9,10 @@ abstract class Function extends AbstractValue implements Iterable<Value>
"@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" }; "@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
protected final Cell cell; protected final Cell cell;
protected final String fullText;
protected String functionName; protected final String functionName;
protected String functionText; protected final String functionText;
protected String fullText;
protected Value source;
protected Range range;
Function (Cell cell, String text) Function (Cell cell, String text)
{ {
@ -35,17 +30,11 @@ abstract class Function extends AbstractValue implements Iterable<Value>
} }
else else
{ {
functionName = ""; functionName = text;
functionText = ""; functionText = "";
} }
} }
@Override
public Iterator<Value> iterator ()
{
return values.iterator ();
}
@Override @Override
public String toString () public String toString ()
{ {

View File

@ -9,8 +9,8 @@ public class Int extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = (int) source.getValue (); return (int) source.getValue ();
} }
} }

View File

@ -15,8 +15,16 @@ class IsError extends ValueFunction
} }
@Override @Override
public void setValue () public void calculate ()
{ {
value = source.isValueType (ValueType.ERROR) ? 1 : 0; source.calculate ();
value = calculateValue ();
valueType = ValueType.VALUE; // do not use source.getValueType()
}
@Override
public double calculateValue ()
{
return source.isValueType (ValueType.ERROR) ? 1 : 0;
} }
} }

View File

@ -15,8 +15,16 @@ public class IsNa extends ValueFunction
} }
@Override @Override
public void setValue () public void calculate ()
{ {
value = source.isValueType (ValueType.NA) ? 1 : 0; source.calculate ();
value = calculateValue ();
valueType = ValueType.VALUE; // do not use source.getValueType()
}
@Override
public double calculateValue ()
{
return source.isValueType (ValueType.NA) ? 1 : 0;
} }
} }

View File

@ -9,8 +9,8 @@ public class Ln extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.log (source.getValue ()); return Math.log (source.getValue ());
} }
} }

View File

@ -9,8 +9,8 @@ public class Log10 extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.log10 (source.getValue ()); return Math.log10 (source.getValue ());
} }
} }

View File

@ -1,6 +1,6 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class Na extends Function public class Na extends ConstantFunction
{ {
public Na (Cell cell, String text) public Na (Cell cell, String text)
{ {

View File

@ -2,7 +2,7 @@ package com.bytezone.diskbrowser.visicalc;
class Or extends Function class Or extends Function
{ {
ConditionList conditions; private final ConditionList conditions;
public Or (Cell cell, String text) public Or (Cell cell, String text)
{ {

View File

@ -1,15 +1,14 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
class Pi extends Function class Pi extends ConstantFunction
{ {
Pi (Cell cell, String text) Pi (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
value = Math.PI;
assert text.equals ("@PI") : text; assert text.equals ("@PI") : text;
value = Math.PI;
valueType = ValueType.VALUE; valueType = ValueType.VALUE;
} }
} }

View File

@ -9,8 +9,8 @@ public class Sin extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.sin (source.getValue ()); return Math.sin (source.getValue ());
} }
} }

View File

@ -9,8 +9,8 @@ public class Sqrt extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.sqrt (source.getValue ()); return Math.sqrt (source.getValue ());
} }
} }

View File

@ -9,8 +9,8 @@ public class Tan extends ValueFunction
} }
@Override @Override
public void setValue () public double calculateValue ()
{ {
value = Math.tan (source.getValue ()); return Math.tan (source.getValue ());
} }
} }

View File

@ -1,6 +1,6 @@
package com.bytezone.diskbrowser.visicalc; package com.bytezone.diskbrowser.visicalc;
public class True extends Function public class True extends ConstantFunction
{ {
True (Cell cell, String text) True (Cell cell, String text)
{ {

View File

@ -2,6 +2,8 @@ package com.bytezone.diskbrowser.visicalc;
public abstract class ValueFunction extends Function public abstract class ValueFunction extends Function
{ {
protected Value source;
ValueFunction (Cell cell, String text) ValueFunction (Cell cell, String text)
{ {
super (cell, text); super (cell, text);
@ -21,10 +23,9 @@ public abstract class ValueFunction extends Function
return; return;
} }
// value = Math.abs (source.getValue ()); value = calculateValue ();
setValue ();
valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE; valueType = Double.isNaN (value) ? ValueType.ERROR : ValueType.VALUE;
} }
abstract void setValue (); abstract double calculateValue ();
} }

View File

@ -15,5 +15,4 @@ public abstract class ValueListFunction extends Function
for (Value v : list) for (Value v : list)
values.add (v); values.add (v);
} }
} }