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