moved call to parent cell functions to Cell

This commit is contained in:
Denis Molony 2017-03-20 08:45:31 +11:00
parent c40ac67be9
commit 60d908b6d1
7 changed files with 28 additions and 26 deletions

View File

@ -33,6 +33,21 @@ class Cell extends AbstractValue implements Comparable<Cell>
isVolatile = false;
}
Cell getCell (Address address)
{
return parent.getCell (address);
}
Cell getCell (String addressText)
{
return parent.getCell (addressText);
}
boolean cellExists (Address address)
{
return parent.cellExists (address);
}
Function getFunction (String text)
{
return parent.getFunction (this, text);

View File

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

View File

@ -40,7 +40,6 @@ class Expression extends AbstractValue implements Iterable<Value>
super ("Exp");
this.cell = cell;
this.text = text;
Sheet parent = cell.getParent ();
String line = balanceBrackets (text); // add trailing right brackets if necessary
@ -93,7 +92,7 @@ class Expression extends AbstractValue implements Iterable<Value>
{
String addressText = getAddressText (line.substring (ptr));
ptr += addressText.length ();
values.add (parent.getCell (addressText));
values.add (cell.getCell (addressText));
}
else
{

View File

@ -10,7 +10,6 @@ abstract class Function extends AbstractValue implements Iterable<Value>
"@ISNA(", "@LOG10(", "@LOOKUP(", "@LN(", "@MIN(", "@MAX(", "@NA", "@NPV(", "@OR(",
"@PI", "@SIN(", "@SUM(", "@SQRT(", "@TAN(", "@TRUE" };
protected final Sheet parent;
protected final Cell cell;
protected String functionName;
@ -25,7 +24,6 @@ abstract class Function extends AbstractValue implements Iterable<Value>
{
super ("Function");
this.parent = cell.getParent ();
this.cell = cell;
fullText = text;

View File

@ -57,9 +57,10 @@ class Lookup extends Function
{
Address adjacentAddress = isVertical ? target.nextColumn () : target.nextRow ();
if (parent.cellExists (adjacentAddress))
// Sheet parent = cell.getParent ();
if (cell.cellExists (adjacentAddress))
{
value = parent.getCell (adjacentAddress).getValue ();
value = cell.getCell (adjacentAddress).getValue ();
valueType = ValueType.VALUE;
}
else

View File

@ -16,13 +16,13 @@ class Range implements Iterable<Address>
private Address from, to;
private final List<Address> range = new ArrayList<Address> ();
private final Sheet parent;
private final Cell cell;
private boolean isHorizontal;
public Range (Sheet parent, Cell cell, String rangeText)
public Range (Cell cell, String rangeText)
{
this.parent = parent;
this.cell = cell;
Matcher m = rangePattern.matcher (rangeText);
if (m.find ())
@ -36,20 +36,10 @@ class Range implements Iterable<Address>
throw new IllegalArgumentException (rangeText);
}
public Range (Sheet parent, Address from, Address to)
{
this.parent = parent;
this.from = from;
this.to = to;
isHorizontal = from.rowMatches (to);
populateRange ();
}
private void populateRange ()
{
range.add (from);
parent.getCell (from);
cell.getCell (from);
Address tempFrom = from;
if (from.rowMatches (to))
@ -57,14 +47,14 @@ class Range implements Iterable<Address>
{
from = from.nextColumn ();
range.add (from);
parent.getCell (from);
cell.getCell (from);
}
else if (from.columnMatches (to))
while (from.compareTo (to) < 0)
{
from = from.nextRow ();
range.add (from);
parent.getCell (from);
cell.getCell (from);
}
else
throw new InvalidParameterException ();

View File

@ -11,7 +11,7 @@ public class ValueList implements Iterable<Value>
public ValueList (Cell cell, String text)
{
Sheet parent = cell.getParent ();
// Sheet parent = cell.getParent ();
String remainder = text;
while (true)
@ -21,8 +21,8 @@ public class ValueList implements Iterable<Value>
if (Range.isRange (parameter))
{
rangeFound = true;
for (Address address : new Range (parent, cell, parameter))
values.add (parent.getCell (address));
for (Address address : new Range (cell, parameter))
values.add (cell.getCell (address));
}
else
values.add (new Expression (cell, parameter).reduce ());