Switched Cell.value from Object to Serializable.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@201 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
3e0ac50e17
commit
9d8b746121
@ -1,6 +1,7 @@
|
||||
package com.metaweb.gridworks.commands.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@ -78,8 +79,8 @@ public class PreviewExpressionCommand extends Command {
|
||||
result = eval.evaluate(bindings);
|
||||
|
||||
if (repeat) {
|
||||
for (int r = 0; r < repeatCount; r++) {
|
||||
Cell newCell = new Cell(result, (cell != null) ? cell.recon : null);
|
||||
for (int r = 0; r < repeatCount && ExpressionUtils.isStorable(result); r++) {
|
||||
Cell newCell = new Cell((Serializable) result, (cell != null) ? cell.recon : null);
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, newCell);
|
||||
|
||||
Object newResult = eval.evaluate(bindings);
|
||||
@ -87,9 +88,9 @@ public class PreviewExpressionCommand extends Command {
|
||||
break;
|
||||
} else if (ExpressionUtils.sameValue(result, newResult)) {
|
||||
break;
|
||||
} else {
|
||||
result = newResult;
|
||||
}
|
||||
|
||||
result = newResult;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.metaweb.gridworks.expr;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
@ -67,4 +70,20 @@ public class ExpressionUtils {
|
||||
return v1.equals(v2);
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean isStorable(Object v) {
|
||||
return v == null ||
|
||||
v instanceof Number ||
|
||||
v instanceof String ||
|
||||
v instanceof Boolean ||
|
||||
v instanceof Date ||
|
||||
v instanceof Calendar ||
|
||||
v instanceof EvalError;
|
||||
}
|
||||
|
||||
static public Serializable wrapStorable(Object v) {
|
||||
return isStorable(v) ?
|
||||
(Serializable) v :
|
||||
new EvalError(v.getClass().getSimpleName() + " value not storable");
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.metaweb.gridworks.importers;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@ -131,7 +132,7 @@ public class ExcelImporter implements Importer {
|
||||
cellType = cell.getCachedFormulaResultType();
|
||||
}
|
||||
|
||||
Object value = null;
|
||||
Serializable value = null;
|
||||
if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN) {
|
||||
value = cell.getBooleanCellValue();
|
||||
} else if (cellType == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC) {
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.metaweb.gridworks.importers;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
|
||||
public class ImporterUtilities {
|
||||
|
||||
static public Object parseCellValue(String text) {
|
||||
static public Serializable parseCellValue(String text) {
|
||||
if (text.length() > 0) {
|
||||
if (text.length() > 1 && text.startsWith("\"") && text.endsWith("\"")) {
|
||||
return text.substring(1, text.length() - 1);
|
||||
@ -52,7 +54,7 @@ public class ImporterUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
Object value = parseCellValue(text);
|
||||
Serializable value = parseCellValue(text);
|
||||
if (ExpressionUtils.isNonBlankData(value)) {
|
||||
row.cells.add(new Cell(value, null));
|
||||
hasData = true;
|
||||
@ -71,7 +73,7 @@ public class ImporterUtilities {
|
||||
for (int c = 0; c < cells.length; c++) {
|
||||
String text = cells[c];
|
||||
|
||||
Object value = parseCellValue(text);
|
||||
Serializable value = parseCellValue(text);
|
||||
if (ExpressionUtils.isNonBlankData(value)) {
|
||||
row.cells.add(new Cell(value, null));
|
||||
hasData = true;
|
||||
|
@ -14,10 +14,10 @@ import com.metaweb.gridworks.expr.HasFields;
|
||||
public class Cell implements Serializable, HasFields, Jsonizable {
|
||||
private static final long serialVersionUID = -5891067829205458102L;
|
||||
|
||||
final public Object value;
|
||||
final public Recon recon;
|
||||
final public Serializable value;
|
||||
final public Recon recon;
|
||||
|
||||
public Cell(Object value, Recon recon) {
|
||||
public Cell(Serializable value, Recon recon) {
|
||||
this.value = value;
|
||||
this.recon = recon;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.metaweb.gridworks.operations;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@ -140,7 +141,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object v = eval.evaluate(bindings);
|
||||
Serializable v = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
|
||||
if (ExpressionUtils.isError(v)) {
|
||||
if (_onError == OnError.SetToBlank) {
|
||||
return false;
|
||||
|
@ -34,9 +34,9 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
|
||||
private static final long serialVersionUID = -4799990738910328002L;
|
||||
|
||||
final public List<String> from;
|
||||
final public Object to;
|
||||
final public Serializable to;
|
||||
|
||||
public Edit(List<String> from, Object to) {
|
||||
public Edit(List<String> from, Serializable to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
|
||||
from.add(fromA.getString(j));
|
||||
}
|
||||
|
||||
edits.add(new Edit(from, editO.get("to")));
|
||||
edits.add(new Edit(from, editO.getString("to")));
|
||||
}
|
||||
|
||||
return edits;
|
||||
@ -129,7 +129,7 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
|
||||
Evaluable eval = MetaParser.parse(_expression);
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
||||
Map<String, Object> fromTo = new HashMap<String, Object>();
|
||||
Map<String, Serializable> fromTo = new HashMap<String, Serializable>();
|
||||
for (Edit edit : _edits) {
|
||||
for (String s : edit.from) {
|
||||
fromTo.put(s, edit.to);
|
||||
@ -137,14 +137,19 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
|
||||
}
|
||||
|
||||
return new RowVisitor() {
|
||||
int cellIndex;
|
||||
Properties bindings;
|
||||
List<CellChange> cellChanges;
|
||||
Evaluable eval;
|
||||
Map<String, Object> fromTo;
|
||||
int cellIndex;
|
||||
Properties bindings;
|
||||
List<CellChange> cellChanges;
|
||||
Evaluable eval;
|
||||
Map<String, Serializable> fromTo;
|
||||
|
||||
public RowVisitor init(
|
||||
int cellIndex, Properties bindings, List<CellChange> cellChanges, Evaluable eval, Map<String, Object> fromTo) {
|
||||
int cellIndex,
|
||||
Properties bindings,
|
||||
List<CellChange> cellChanges,
|
||||
Evaluable eval,
|
||||
Map<String, Serializable> fromTo
|
||||
) {
|
||||
this.cellIndex = cellIndex;
|
||||
this.bindings = bindings;
|
||||
this.cellChanges = cellChanges;
|
||||
@ -161,7 +166,7 @@ public class FacetBasedEditOperation extends EngineDependentMassCellOperation {
|
||||
Object v = eval.evaluate(bindings);
|
||||
if (v != null) {
|
||||
String from = v.toString();
|
||||
Object to = fromTo.get(from);
|
||||
Serializable to = fromTo.get(from);
|
||||
if (to != null) {
|
||||
Cell newCell = new Cell(to, (cell != null) ? cell.recon : null);
|
||||
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.metaweb.gridworks.operations;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -125,7 +126,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
|
||||
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, cell);
|
||||
|
||||
Object newValue = eval.evaluate(bindings);
|
||||
Serializable newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
|
||||
if (ExpressionUtils.isError(newValue)) {
|
||||
if (_onError == OnError.KeepOriginal) {
|
||||
return false;
|
||||
@ -141,7 +142,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
|
||||
for (int i = 0; i < _repeatCount; i++) {
|
||||
ExpressionUtils.bind(bindings, row, rowIndex, newCell);
|
||||
|
||||
newValue = eval.evaluate(bindings);
|
||||
newValue = ExpressionUtils.wrapStorable(eval.evaluate(bindings));
|
||||
if (ExpressionUtils.isError(newValue)) {
|
||||
break;
|
||||
} else if (ExpressionUtils.sameValue(newCell.value, newValue)) {
|
||||
|
Loading…
Reference in New Issue
Block a user