mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-19 12:30:27 +00:00
added Condition
This commit is contained in:
parent
5408d01b9c
commit
de682dc190
@ -83,7 +83,7 @@ class Cell implements Comparable<Cell>, Value
|
|||||||
expressionText = "15";
|
expressionText = "15";
|
||||||
|
|
||||||
// CARLOAN.VC
|
// CARLOAN.VC
|
||||||
if (false)
|
if (true)
|
||||||
if (address.sortValue == 67)
|
if (address.sortValue == 67)
|
||||||
expressionText = "9375";
|
expressionText = "9375";
|
||||||
else if (address.sortValue == 131)
|
else if (address.sortValue == 131)
|
||||||
|
79
src/com/bytezone/diskbrowser/visicalc/Condition.java
Normal file
79
src/com/bytezone/diskbrowser/visicalc/Condition.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package com.bytezone.diskbrowser.visicalc;
|
||||||
|
|
||||||
|
public class Condition
|
||||||
|
{
|
||||||
|
private static String[] comparators = { "<>", "<=", ">=", "=", "<", ">" };
|
||||||
|
|
||||||
|
private final Sheet parent;
|
||||||
|
|
||||||
|
private String comparator;
|
||||||
|
private String cond;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private Expression expCond;
|
||||||
|
private Expression expValue;
|
||||||
|
|
||||||
|
public Condition (Sheet parent, String text)
|
||||||
|
{
|
||||||
|
this.parent = parent;
|
||||||
|
|
||||||
|
for (String comp : comparators)
|
||||||
|
{
|
||||||
|
int pos = text.indexOf (comp);
|
||||||
|
if (pos > 0)
|
||||||
|
{
|
||||||
|
cond = text.substring (0, pos);
|
||||||
|
value = text.substring (pos + comp.length ());
|
||||||
|
comparator = comp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comparator == null)
|
||||||
|
{
|
||||||
|
if (text.startsWith ("@"))
|
||||||
|
{
|
||||||
|
cond = text;
|
||||||
|
value = "1";
|
||||||
|
comparator = "=";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println ("No comparator and not a function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getResult ()
|
||||||
|
{
|
||||||
|
if (expCond == null)
|
||||||
|
{
|
||||||
|
expCond = new Expression (parent, cond);
|
||||||
|
expValue = new Expression (parent, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
double condValue = expCond.getValue ();
|
||||||
|
double valueValue = expValue.getValue ();
|
||||||
|
|
||||||
|
if (comparator.equals ("="))
|
||||||
|
return condValue == valueValue;
|
||||||
|
else if (comparator.equals ("<>"))
|
||||||
|
return condValue != valueValue;
|
||||||
|
else if (comparator.equals ("<"))
|
||||||
|
return condValue < valueValue;
|
||||||
|
else if (comparator.equals (">"))
|
||||||
|
return condValue > valueValue;
|
||||||
|
else if (comparator.equals ("<="))
|
||||||
|
return condValue <= valueValue;
|
||||||
|
else if (comparator.equals (">="))
|
||||||
|
return condValue >= valueValue;
|
||||||
|
else
|
||||||
|
System.out.printf ("Unexpected comparator result [%s]%n", comparator);
|
||||||
|
|
||||||
|
return false; // flag error?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
return String.format ("[cond=%s, op=%s, value=%s]", cond, comparator, value);
|
||||||
|
}
|
||||||
|
}
|
@ -2,94 +2,28 @@ package com.bytezone.diskbrowser.visicalc;
|
|||||||
|
|
||||||
public class If extends Function
|
public class If extends Function
|
||||||
{
|
{
|
||||||
private static String[] comparators = { "<>", "<=", ">=", "=", "<", ">" };
|
private final Condition condition;
|
||||||
|
|
||||||
private final String condition;
|
|
||||||
private final String textTrue;
|
private final String textTrue;
|
||||||
private final String textFalse;
|
private final String textFalse;
|
||||||
private String comparator;
|
|
||||||
private String cond;
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
private Expression expTrue;
|
private Expression expTrue;
|
||||||
private Expression expFalse;
|
private Expression expFalse;
|
||||||
private Expression expCond;
|
|
||||||
private Expression expValue;
|
|
||||||
|
|
||||||
public If (Sheet parent, String text)
|
public If (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
text = text.substring (4, text.length () - 1);
|
int pos1 = functionText.indexOf (',');
|
||||||
System.out.println (text);
|
int pos2 = functionText.indexOf (',', pos1 + 1);
|
||||||
int pos1 = text.indexOf (',');
|
condition = new Condition (parent, functionText.substring (0, pos1));
|
||||||
int pos2 = text.indexOf (',', pos1 + 1);
|
textTrue = functionText.substring (pos1 + 1, pos2);
|
||||||
condition = text.substring (0, pos1);
|
textFalse = functionText.substring (pos2 + 1);
|
||||||
textTrue = text.substring (pos1 + 1, pos2);
|
|
||||||
textFalse = text.substring (pos2 + 1);
|
|
||||||
|
|
||||||
System.out.printf ("Cond:%s, true=%s, false=%s%n", condition, textTrue, textFalse);
|
|
||||||
|
|
||||||
for (String comp : comparators)
|
|
||||||
{
|
|
||||||
int pos = condition.indexOf (comp);
|
|
||||||
if (pos > 0)
|
|
||||||
{
|
|
||||||
cond = condition.substring (0, pos);
|
|
||||||
value = condition.substring (pos + comp.length ());
|
|
||||||
comparator = comp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comparator == null)
|
|
||||||
{
|
|
||||||
if (condition.startsWith ("@"))
|
|
||||||
{
|
|
||||||
cond = condition;
|
|
||||||
value = "1";
|
|
||||||
comparator = "=";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
System.out.println ("No comparator and not a function");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf ("cond=%s, op=%s, value=%s%n", cond, comparator, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getValue ()
|
public double getValue ()
|
||||||
{
|
{
|
||||||
if (expCond == null)
|
if (condition.getResult ())
|
||||||
{
|
|
||||||
expCond = new Expression (parent, cond);
|
|
||||||
expValue = new Expression (parent, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
double condValue = expCond.getValue ();
|
|
||||||
double valueValue = expValue.getValue ();
|
|
||||||
|
|
||||||
boolean result;
|
|
||||||
|
|
||||||
if (comparator.equals ("="))
|
|
||||||
result = condValue == valueValue;
|
|
||||||
else if (comparator.equals ("<>"))
|
|
||||||
result = condValue != valueValue;
|
|
||||||
else if (comparator.equals ("<"))
|
|
||||||
result = condValue < valueValue;
|
|
||||||
else if (comparator.equals (">"))
|
|
||||||
result = condValue > valueValue;
|
|
||||||
else if (comparator.equals ("<="))
|
|
||||||
result = condValue <= valueValue;
|
|
||||||
else if (comparator.equals (">="))
|
|
||||||
result = condValue >= valueValue;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.out.printf ("Unexpected comparator result [%s]%n", comparator);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
{
|
{
|
||||||
if (expTrue == null)
|
if (expTrue == null)
|
||||||
expTrue = new Expression (parent, textTrue);
|
expTrue = new Expression (parent, textTrue);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user