mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-04 07:30:01 +00:00
tidying
This commit is contained in:
parent
2d27cd697c
commit
341979755d
|
@ -10,17 +10,11 @@ public class Choose extends Function
|
|||
|
||||
assert text.startsWith ("@CHOOSE(") : text;
|
||||
|
||||
// parameters are a Value, followed by a Range
|
||||
list = new ValueList (cell, functionText);
|
||||
|
||||
for (Value v : list)
|
||||
values.add (v);
|
||||
|
||||
// String sourceText = Expression.getParameter (functionText);
|
||||
// source = cell.getExpressionValue (sourceText);
|
||||
// values.add (source);
|
||||
//
|
||||
// String rangeText = functionText.substring (sourceText.length () + 1);
|
||||
// range = new Range (parent, cell, rangeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,39 +37,10 @@ public class Choose extends Function
|
|||
}
|
||||
|
||||
Cell cell = (Cell) list.get (index);
|
||||
// Address address = range.get (index);
|
||||
if (cell.isCellType (CellType.EMPTY))
|
||||
valueType = ValueType.NA;
|
||||
else
|
||||
{
|
||||
// Cell cell = parent.getCell (address);
|
||||
valueType = cell.getValueType ();
|
||||
value = cell.getValue ();
|
||||
}
|
||||
}
|
||||
|
||||
public void calculate2 ()
|
||||
{
|
||||
source.calculate ();
|
||||
if (!source.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = source.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = (int) source.getValue () - 1;
|
||||
if (index < 0 || index >= range.size ())
|
||||
{
|
||||
valueType = ValueType.NA;
|
||||
return;
|
||||
}
|
||||
|
||||
Address address = range.get (index);
|
||||
if (address == null)
|
||||
valueType = ValueType.NA;
|
||||
else
|
||||
{
|
||||
Cell cell = parent.getCell (address);
|
||||
valueType = cell.getValueType ();
|
||||
value = cell.getValue ();
|
||||
}
|
||||
|
|
|
@ -8,17 +8,11 @@ class Lookup extends Function
|
|||
|
||||
assert text.startsWith ("@LOOKUP(") : text;
|
||||
|
||||
// parameters are a Value, followed by a Range
|
||||
list = new ValueList (cell, functionText);
|
||||
|
||||
for (Value v : list)
|
||||
values.add (v);
|
||||
|
||||
// String sourceText = Expression.getParameter (functionText);
|
||||
// source = cell.getExpressionValue (sourceText);
|
||||
// values.add (source);
|
||||
//
|
||||
// String rangeText = functionText.substring (sourceText.length () + 1);
|
||||
// range = new Range (parent, cell, rangeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,11 +40,10 @@ class Lookup extends Function
|
|||
Cell lastCell = (Cell) list.get (list.size () - 1);
|
||||
boolean isVertical = firstCell.getAddress ().columnMatches (lastCell.getAddress ());
|
||||
|
||||
for (int i = 1; i < list.size (); i++)
|
||||
for (int i = 1; i < list.size (); i++) // skip first entry
|
||||
{
|
||||
Cell cell = (Cell) list.get (i);
|
||||
// Cell cell = parent.getCell (address);
|
||||
if (cell.getValue () > sourceValue) // past the value
|
||||
if (cell.getValue () > sourceValue) // past the value
|
||||
break;
|
||||
target = cell.getAddress ();
|
||||
}
|
||||
|
@ -76,54 +69,4 @@ class Lookup extends Function
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void calculate2 ()
|
||||
{
|
||||
source.calculate ();
|
||||
|
||||
if (!source.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = source.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (range.size () == 0)
|
||||
{
|
||||
valueType = ValueType.NA;
|
||||
return;
|
||||
}
|
||||
|
||||
double sourceValue = source.getValue ();
|
||||
Address target = null;
|
||||
|
||||
for (Address address : range)
|
||||
{
|
||||
Cell cell = parent.getCell (address);
|
||||
if (cell.getValue () > sourceValue) // past the value
|
||||
break;
|
||||
target = address;
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
valueType = ValueType.NA;
|
||||
value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Address adjacentAddress =
|
||||
range.isVertical () ? target.nextColumn () : target.nextRow ();
|
||||
|
||||
if (parent.cellExists (adjacentAddress))
|
||||
{
|
||||
value = parent.getCell (adjacentAddress).getValue ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = 0;
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,16 +10,11 @@ public class Npv extends Function
|
|||
|
||||
assert text.startsWith ("@NPV(") : text;
|
||||
|
||||
// parameters are a Value, followed by a Range
|
||||
list = new ValueList (cell, functionText);
|
||||
|
||||
for (Value v : list)
|
||||
values.add (v);
|
||||
// String sourceText = Expression.getParameter (functionText);
|
||||
// source = cell.getExpressionValue (sourceText);
|
||||
// values.add (source);
|
||||
//
|
||||
// String rangeText = functionText.substring (sourceText.length () + 1);
|
||||
// range = new Range (parent, cell, rangeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,40 +41,6 @@ public class Npv extends Function
|
|||
|
||||
++period;
|
||||
|
||||
// Cell cell = parent.getCell (address);
|
||||
if (cell.isCellType (CellType.EMPTY))
|
||||
continue;
|
||||
|
||||
if (!cell.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = cell.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value += cell.getValue () / Math.pow (rate, period);
|
||||
}
|
||||
}
|
||||
|
||||
public void calculate2 ()
|
||||
{
|
||||
value = 0;
|
||||
valueType = ValueType.VALUE;
|
||||
|
||||
source.calculate ();
|
||||
if (!source.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = source.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
double rate = 1 + source.getValue ();
|
||||
|
||||
int period = 0;
|
||||
for (Address address : range)
|
||||
{
|
||||
++period;
|
||||
|
||||
Cell cell = parent.getCell (address);
|
||||
if (cell.isCellType (CellType.EMPTY))
|
||||
continue;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user