mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-23 17:30:36 +00:00
more visicalc
This commit is contained in:
parent
119d8472bd
commit
d4a7eef03c
@ -1,8 +1,14 @@
|
||||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractValue implements Value
|
||||
{
|
||||
protected final String typeText;
|
||||
protected double value;
|
||||
protected ValueType valueType = ValueType.VALUE;
|
||||
protected List<Value> values = new ArrayList<Value> ();
|
||||
|
||||
public AbstractValue (String typeText)
|
||||
{
|
||||
@ -14,4 +20,36 @@ public abstract class AbstractValue implements Value
|
||||
{
|
||||
return typeText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType ()
|
||||
{
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueType (ValueType type)
|
||||
{
|
||||
return valueType == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
switch (valueType)
|
||||
{
|
||||
case NA:
|
||||
return "NA";
|
||||
case ERROR:
|
||||
return "Error";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@ -10,12 +10,11 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
private final Sheet parent;
|
||||
private CellType cellType;
|
||||
private final Format format = new Format ();
|
||||
private String expressionText;
|
||||
|
||||
private String repeatingText;
|
||||
private String repeat = "";
|
||||
private String label;
|
||||
|
||||
private String expressionText;
|
||||
private Value value;
|
||||
|
||||
enum CellType
|
||||
@ -84,6 +83,8 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
|
||||
// FUTURE.VC
|
||||
if (false)
|
||||
{
|
||||
System.out.println ("****** Hardcoded values ******");
|
||||
if (address.rowKey == 67)
|
||||
expressionText = "1000";
|
||||
else if (address.rowKey == 131)
|
||||
@ -92,9 +93,12 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
expressionText = "12";
|
||||
else if (address.rowKey == 259)
|
||||
expressionText = "8";
|
||||
}
|
||||
|
||||
// IRA.VC
|
||||
if (true)
|
||||
if (false)
|
||||
{
|
||||
System.out.println ("****** Hardcoded values ******");
|
||||
if (address.rowKey == 66)
|
||||
expressionText = "10";
|
||||
else if (address.rowKey == 130)
|
||||
@ -105,9 +109,12 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
expressionText = "1000";
|
||||
else if (address.rowKey == 386)
|
||||
expressionText = "15";
|
||||
}
|
||||
|
||||
// CARLOAN.VC
|
||||
if (false)
|
||||
{
|
||||
System.out.println ("****** Hardcoded values ******");
|
||||
if (address.rowKey == 67)
|
||||
expressionText = "9375";
|
||||
else if (address.rowKey == 131)
|
||||
@ -117,6 +124,7 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
else if (address.rowKey == 259)
|
||||
expressionText = "11.9";
|
||||
}
|
||||
}
|
||||
|
||||
// format cell value for output
|
||||
String getText (int colWidth, char defaultFormat)
|
||||
@ -193,8 +201,10 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
expressionText = "";
|
||||
|
||||
Expression expression = new Expression (parent, expressionText);
|
||||
value = expression.size () == 1 ? expression.get (0) : expression;
|
||||
// value = expression.size () == 1 ? expression.get (0) : expression;
|
||||
value = expression.reduce ();
|
||||
}
|
||||
|
||||
value.calculate ();
|
||||
|
||||
return this;
|
||||
@ -228,8 +238,6 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
text.append (String.format ("| VALUE : %-69s |%n", expressionText));
|
||||
if (value == null)
|
||||
text.append (String.format ("| Value : %-69s |%n", "null"));
|
||||
// else if (value instanceof Expression)
|
||||
// text.append (getExpressionComponents ((Expression) value, 1));
|
||||
else
|
||||
text.append (getValueText (value, 0));
|
||||
break;
|
||||
@ -257,32 +265,20 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
||||
String.format ("| %-10s : %-69s |%n", typeText, value.getValueType ()));
|
||||
|
||||
if (value instanceof Expression)
|
||||
text.append (getExpressionComponents ((Expression) value, depth + 1));
|
||||
{
|
||||
text.append (
|
||||
String.format ("| Expression : %-69s |%n", ((Expression) value).fullText ()));
|
||||
for (Value v : (Expression) value)
|
||||
text.append (getValueText (v, depth + 1));
|
||||
}
|
||||
else if (value instanceof Function)
|
||||
text.append (getFunctionComponents ((Function) value, depth + 1));
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
private String getExpressionComponents (Expression expression, int depth)
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
text.append (String.format ("| Expression : %-69s |%n", expression.fullText ()));
|
||||
for (Value value : expression)
|
||||
text.append (getValueText (value, depth));
|
||||
|
||||
return text.toString ();
|
||||
text.append (
|
||||
String.format ("| Function : %-69s |%n", ((Function) value).fullText));
|
||||
for (Value v : (Function) value)
|
||||
text.append (getValueText (v, depth + 1));
|
||||
}
|
||||
|
||||
private String getFunctionComponents (Function function, int depth)
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
text.append (String.format ("| Function : %-69s |%n", function.fullText));
|
||||
for (Value value : function)
|
||||
text.append (getValueText (value, depth));
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package com.bytezone.diskbrowser.visicalc;
|
||||
import com.bytezone.diskbrowser.visicalc.Value.ValueType;
|
||||
|
||||
// Predicate
|
||||
class Condition
|
||||
class Condition //extends AbstractValue
|
||||
{
|
||||
private static final String[] comparators = { "<>", "<=", ">=", "=", "<", ">" };
|
||||
|
||||
@ -18,8 +18,8 @@ class Condition
|
||||
|
||||
public Condition (Sheet parent, String text)
|
||||
{
|
||||
// super ("Condition");
|
||||
this.parent = parent;
|
||||
// System.out.println (text);
|
||||
|
||||
for (String comp : comparators)
|
||||
{
|
||||
|
@ -29,12 +29,10 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||
// [.3*(B4+B7+B8+B9)]
|
||||
// [+N12+(P12*(.2*K12+K9-O12))]
|
||||
|
||||
private final List<Value> values = new ArrayList<Value> ();
|
||||
// private final List<Value> values = new ArrayList<Value> ();
|
||||
private final List<String> operators = new ArrayList<String> ();
|
||||
private final List<String> signs = new ArrayList<String> ();
|
||||
|
||||
private ValueType valueType = ValueType.VALUE;
|
||||
private double value;
|
||||
private String text;
|
||||
|
||||
public Expression (Sheet parent, String text)
|
||||
@ -128,6 +126,13 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||
System.out.printf ("Nothing[%s]%n", text);
|
||||
}
|
||||
|
||||
Value reduce ()
|
||||
{
|
||||
if (values.size () == 1 && signs.get (0).equals ("(+)"))
|
||||
return values.get (0);
|
||||
return this;
|
||||
}
|
||||
|
||||
int size ()
|
||||
{
|
||||
return values.size ();
|
||||
@ -210,48 +215,6 @@ class Expression extends AbstractValue implements Iterable<Value>
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType ()
|
||||
{
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueType (ValueType type)
|
||||
{
|
||||
return valueType == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
if (valueType == null && values.size () > 0)
|
||||
calculate ();
|
||||
|
||||
if (valueType == null)
|
||||
{
|
||||
System.out.printf ("null valuetype in exp [%s]%n", text);
|
||||
System.out.println (values.size ());
|
||||
}
|
||||
switch (valueType)
|
||||
{
|
||||
case NA:
|
||||
return "NA";
|
||||
case ERROR:
|
||||
return "Error";
|
||||
// case NAN:
|
||||
// return "NaN";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
private String checkBrackets (String input)
|
||||
{
|
||||
String line = input.trim ();
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
// http://www.bricklin.com/history/refcard1.htm
|
||||
// Functions:
|
||||
@ -33,10 +31,7 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||
protected String functionText;
|
||||
protected String fullText;
|
||||
|
||||
protected ValueType valueType;
|
||||
protected double value;
|
||||
|
||||
protected List<Value> values = new ArrayList<Value> ();
|
||||
// protected List<Value> values = new ArrayList<Value> ();
|
||||
|
||||
static Function getInstance (Sheet parent, String text)
|
||||
{
|
||||
@ -118,40 +113,6 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType ()
|
||||
{
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueType (ValueType type)
|
||||
{
|
||||
return valueType == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
switch (valueType)
|
||||
{
|
||||
case NA:
|
||||
return "NA";
|
||||
case ERROR:
|
||||
return "Error";
|
||||
// case NAN:
|
||||
// return "NaN";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Value> iterator ()
|
||||
{
|
||||
|
@ -12,7 +12,6 @@ class If extends Function
|
||||
public If (Sheet parent, String text)
|
||||
{
|
||||
super (parent, text);
|
||||
// System.out.println (text);
|
||||
|
||||
int pos1 = functionText.indexOf (',');
|
||||
int pos2 = functionText.indexOf (',', pos1 + 1);
|
||||
|
@ -2,9 +2,6 @@ package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
class Number extends AbstractValue
|
||||
{
|
||||
private double value;
|
||||
private ValueType valueType;
|
||||
|
||||
public Number (String text)
|
||||
{
|
||||
super ("Constant");
|
||||
@ -12,7 +9,6 @@ class Number extends AbstractValue
|
||||
try
|
||||
{
|
||||
value = Double.parseDouble (text);
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
@ -21,49 +17,15 @@ class Number extends AbstractValue
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueType (ValueType type)
|
||||
{
|
||||
return valueType == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return String.format ("Number: %f", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
switch (valueType)
|
||||
{
|
||||
case NA:
|
||||
return "NA";
|
||||
case ERROR:
|
||||
return "Error";
|
||||
// case NAN:
|
||||
// return "NaN";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value calculate ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType getValueType ()
|
||||
{
|
||||
return valueType;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user