mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-22 14:31:00 +00:00
ExpressionList changes
This commit is contained in:
parent
7056f5c49d
commit
0d193d8da9
@ -26,11 +26,10 @@ class Count extends Function
|
||||
else
|
||||
for (Value v : list)
|
||||
{
|
||||
v.calculate ();
|
||||
|
||||
if (v instanceof Cell && ((Cell) v).isCellType (CellType.EMPTY))
|
||||
continue;
|
||||
|
||||
v.calculate (); // is this required?
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
@ -9,37 +9,60 @@ public class ExpressionList extends AbstractValue implements Iterable<Value>
|
||||
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
||||
|
||||
private final Sheet parent;
|
||||
// private final List<Expression> expressions = new ArrayList<Expression> ();
|
||||
|
||||
public ExpressionList (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super ("expL");
|
||||
this.parent = parent;
|
||||
|
||||
int pos = text.indexOf ("...");
|
||||
if (pos > 0)
|
||||
int ptr = 0;
|
||||
while (ptr < text.length ())
|
||||
{
|
||||
String fromAddress = text.substring (0, pos);
|
||||
String toAddress = text.substring (pos + 3);
|
||||
if (text.charAt (ptr) == '@')
|
||||
{
|
||||
String functionText = Expression.getBalancedText (text.substring (ptr));
|
||||
Value v = new Expression (parent, cell, functionText).reduce ();
|
||||
values.add (v);
|
||||
ptr += functionText.length ();
|
||||
}
|
||||
else
|
||||
{
|
||||
String item = getNextItem (text, ptr);
|
||||
int pos = item.indexOf ("...");
|
||||
if (pos > 0) // range
|
||||
{
|
||||
String fromAddress = item.substring (0, pos);
|
||||
String toAddress = item.substring (pos + 3);
|
||||
|
||||
Address from = new Address (fromAddress);
|
||||
Address to = new Address (toAddress);
|
||||
Address from = new Address (fromAddress);
|
||||
Address to = new Address (toAddress);
|
||||
|
||||
Range range = new Range (parent, from, to);
|
||||
for (Address address : range)
|
||||
values.add (parent.getCell (address));
|
||||
Range range = new Range (parent, from, to);
|
||||
|
||||
return;
|
||||
for (Address address : range)
|
||||
values.add (parent.getCell (address));
|
||||
}
|
||||
else
|
||||
{
|
||||
Value v = new Expression (parent, cell, item).reduce ();
|
||||
values.add (v);
|
||||
}
|
||||
ptr += item.length ();
|
||||
}
|
||||
|
||||
if (ptr < text.length () && text.charAt (ptr) == ',')
|
||||
ptr++;
|
||||
if (ptr < text.length () && text.charAt (ptr) == ')')
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
String[] chunks = text.split (",");
|
||||
for (String s : chunks)
|
||||
{
|
||||
// System.out.println (s);
|
||||
Value v = new Expression (parent, cell, s).reduce ();
|
||||
// expressions.add (expression);
|
||||
values.add (v);
|
||||
}
|
||||
private String getNextItem (String text, int ptr)
|
||||
{
|
||||
int p = ptr;
|
||||
while (++p < text.length () && text.charAt (p) != ',')
|
||||
;
|
||||
return text.substring (ptr, p);
|
||||
}
|
||||
|
||||
public int size ()
|
||||
|
@ -23,18 +23,13 @@ class Max extends Function
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = cell.getValueType ();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
double temp = v.getValue ();
|
||||
if (temp > value)
|
||||
value = temp;
|
||||
value = Math.max (value, v.getValue ());
|
||||
totalChecked++;
|
||||
}
|
||||
|
||||
if (totalChecked == 0)
|
||||
valueType = ValueType.NA;
|
||||
else
|
||||
valueType = ValueType.VALUE;
|
||||
valueType = totalChecked == 0 ? ValueType.NA : ValueType.VALUE;
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ class Min extends Function
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
System.out.println (text);
|
||||
list = new ExpressionList (parent, cell, functionText);
|
||||
}
|
||||
|
||||
@ -24,18 +23,13 @@ class Min extends Function
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = cell.getValueType ();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
double temp = v.getValue ();
|
||||
if (temp < value)
|
||||
value = temp;
|
||||
value = Math.min (value, v.getValue ());
|
||||
totalChecked++;
|
||||
}
|
||||
|
||||
if (totalChecked == 0)
|
||||
valueType = ValueType.NA;
|
||||
else
|
||||
valueType = ValueType.VALUE;
|
||||
valueType = totalChecked == 0 ? ValueType.NA : ValueType.VALUE;
|
||||
}
|
||||
}
|
@ -33,8 +33,7 @@ class Range implements Iterable<Address>
|
||||
populateRange ();
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
throw new IllegalArgumentException (rangeText);
|
||||
}
|
||||
|
||||
public Range (Sheet parent, Address from, Address to)
|
||||
@ -47,16 +46,6 @@ class Range implements Iterable<Address>
|
||||
populateRange ();
|
||||
}
|
||||
|
||||
// public Range (Sheet parent, String[] cells)
|
||||
// {
|
||||
// this.parent = parent;
|
||||
//
|
||||
// for (String s : cells)
|
||||
// range.add (new Address (s));
|
||||
//
|
||||
// createCells ();
|
||||
// }
|
||||
|
||||
private void populateRange ()
|
||||
{
|
||||
range.add (from);
|
||||
@ -81,29 +70,15 @@ class Range implements Iterable<Address>
|
||||
throw new InvalidParameterException ();
|
||||
|
||||
from = tempFrom;
|
||||
|
||||
// createCells ();
|
||||
}
|
||||
|
||||
// private void createCells ()
|
||||
// {
|
||||
// for (Address address : range)
|
||||
// parent.getCell (address); // ensure that the cell exists
|
||||
// }
|
||||
|
||||
boolean isHorizontal ()
|
||||
{
|
||||
// Address first = range.get (0);
|
||||
// Address last = range.get (range.size () - 1);
|
||||
// return first.rowMatches (last);
|
||||
return isHorizontal;
|
||||
}
|
||||
|
||||
boolean isVertical ()
|
||||
{
|
||||
// Address first = range.get (0);
|
||||
// Address last = range.get (range.size () - 1);
|
||||
// return first.columnMatches (last);
|
||||
return !isHorizontal;
|
||||
}
|
||||
|
||||
@ -115,60 +90,9 @@ class Range implements Iterable<Address>
|
||||
|
||||
public int size ()
|
||||
{
|
||||
// int total = 0;
|
||||
//
|
||||
// for (Address address : range)
|
||||
// if (parent.getCell (address) != null)
|
||||
// ++total;
|
||||
|
||||
return range.size ();
|
||||
}
|
||||
|
||||
// private void setRange (String text)
|
||||
// {
|
||||
// Matcher m = rangePattern.matcher (text);
|
||||
// if (m.find ())
|
||||
// {
|
||||
// from = new Address (m.group (1), m.group (2));
|
||||
// to = new Address (m.group (3), m.group (4));
|
||||
// populateRange ();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // m = addressList.matcher (text);
|
||||
// // if (m.find ())
|
||||
// // {
|
||||
// // System.out.printf ("Address list: %s%n", text);
|
||||
// // String[] cells = m.group (1).split (",");
|
||||
// // for (String s : cells)
|
||||
// // {
|
||||
// // System.out.println (s);
|
||||
// // if (cellAddress.matcher (s).matches ())
|
||||
// // range.add (new Address (s));
|
||||
// // else
|
||||
// // {
|
||||
// // System.out.println ("Not a cell address: " + s);
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // System.out.println ();
|
||||
// // return;
|
||||
// // }
|
||||
//
|
||||
// int pos = text.indexOf ("...");
|
||||
// if (pos > 0)
|
||||
// {
|
||||
// String fromAddress = text.substring (0, pos);
|
||||
// String toAddress = text.substring (pos + 3);
|
||||
// from = new Address (fromAddress);
|
||||
// to = new Address (toAddress);
|
||||
// populateRange ();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// System.out.printf ("null range [%s]%n", text);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user