Convert tabs to spaces. No functional changes.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2172 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-08-02 20:26:32 +00:00
parent 123614539d
commit 7fd6e22af4
77 changed files with 1194 additions and 1192 deletions

View File

@ -89,11 +89,11 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
protected void expire(HttpServletResponse response) throws Exception { protected void expire(HttpServletResponse response) throws Exception {
// TODO: implement // TODO: implement
} }
protected void startProject(HttpServletResponse response, String pid, String uid, String lock, byte[] data, String metadata, List<String> transformations) throws Exception { protected void startProject(HttpServletResponse response, String pid, String uid, String lock, byte[] data, String metadata, List<String> transformations) throws Exception {
// TODO: implement // TODO: implement
} }
protected void expireLocks(HttpServletResponse response) throws Exception { protected void expireLocks(HttpServletResponse response) throws Exception {
@ -133,7 +133,7 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
PersistenceManager pm = pmfInstance.getPersistenceManager(); PersistenceManager pm = pmfInstance.getPersistenceManager();
try { try {
// TODO: implement // TODO: implement
respond(response, lockToJSON(getLock(pm,pid))); respond(response, lockToJSON(getLock(pm,pid)));
} finally { } finally {
pm.close(); pm.close();
@ -143,7 +143,7 @@ public class AppEngineRefineBrokerImpl extends RefineBroker {
protected void obtainLock(HttpServletResponse response, String pid, String uid, int locktype, String lockvalue) throws Exception { protected void obtainLock(HttpServletResponse response, String pid, String uid, int locktype, String lockvalue) throws Exception {
PersistenceManager pm = pmfInstance.getPersistenceManager(); PersistenceManager pm = pmfInstance.getPersistenceManager();
// TODO: implement // TODO: implement
try { try {
Lock lock = getLock(pm, pid); Lock lock = getLock(pm, pid);

View File

@ -48,12 +48,12 @@ import com.google.refine.freebase.protograph.transpose.Transposer;
import com.google.refine.freebase.protograph.transpose.TripleLoaderTransposedNodeFactory; import com.google.refine.freebase.protograph.transpose.TripleLoaderTransposedNodeFactory;
abstract public class ProtographTransposeExporter implements WriterExporter { abstract public class ProtographTransposeExporter implements WriterExporter {
final protected String _contentType; final protected String _contentType;
public ProtographTransposeExporter(String contentType) { public ProtographTransposeExporter(String contentType) {
_contentType = contentType; _contentType = contentType;
} }
@Override @Override
public String getContentType() { public String getContentType() {
return "application/x-unknown"; return "application/x-unknown";
@ -86,25 +86,25 @@ abstract public class ProtographTransposeExporter implements WriterExporter {
abstract protected TransposedNodeFactory createNodeFactory(Project project, Writer writer); abstract protected TransposedNodeFactory createNodeFactory(Project project, Writer writer);
static public class TripleLoaderExporter extends ProtographTransposeExporter { static public class TripleLoaderExporter extends ProtographTransposeExporter {
public TripleLoaderExporter() { public TripleLoaderExporter() {
super("application/x-unknown"); super("application/x-unknown");
} }
@Override @Override
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
return new TripleLoaderTransposedNodeFactory(project, writer); return new TripleLoaderTransposedNodeFactory(project, writer);
} }
} }
static public class MqlwriteLikeExporter extends ProtographTransposeExporter { static public class MqlwriteLikeExporter extends ProtographTransposeExporter {
public MqlwriteLikeExporter() { public MqlwriteLikeExporter() {
super("application/x-unknown"); super("application/x-unknown");
} }
@Override @Override
protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) {
return new MqlwriteLikeTransposedNodeFactory(writer); return new MqlwriteLikeTransposedNodeFactory(writer);
} }
} }
} }

View File

@ -208,13 +208,13 @@ public class DataExtensionChange implements Change {
column.setReconStats(ReconStats.create(project, cellIndex)); column.setReconStats(ReconStats.create(project, cellIndex));
try { try {
project.columnModel.addColumn(_columnInsertIndex + i, column, true); project.columnModel.addColumn(_columnInsertIndex + i, column, true);
// the column might have been renamed to avoid collision // the column might have been renamed to avoid collision
_columnNames.set(i, column.getName()); _columnNames.set(i, column.getName());
} catch (ModelException e) { } catch (ModelException e) {
// won't get here since we set the avoid collision flag // won't get here since we set the avoid collision flag
} }
} }
project.update(); project.update();

View File

@ -137,7 +137,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
jsonWriter.key("guid|="); jsonWriter.key("guid|=");
jsonWriter.array(); jsonWriter.array();
for (ReconJob job : jobs) { for (ReconJob job : jobs) {
jsonWriter.value(((GuidBasedReconJob) job).guid); jsonWriter.value(((GuidBasedReconJob) job).guid);
} }
jsonWriter.endArray(); jsonWriter.endArray();
@ -163,37 +163,37 @@ public class GuidBasedReconConfig extends StrictReconConfig {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
if (o.has("result")) { if (o.has("result")) {
JSONArray results = o.getJSONArray("result"); JSONArray results = o.getJSONArray("result");
int count = results.length(); int count = results.length();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject result = results.getJSONObject(i); JSONObject result = results.getJSONObject(i);
String guid = result.getString("guid"); String guid = result.getString("guid");
JSONArray types = result.getJSONArray("type"); JSONArray types = result.getJSONArray("type");
String[] typeIDs = new String[types.length()]; String[] typeIDs = new String[types.length()];
for (int j = 0; j < typeIDs.length; j++) { for (int j = 0; j < typeIDs.length; j++) {
typeIDs[j] = types.getString(j); typeIDs[j] = types.getString(j);
} }
ReconCandidate candidate = new ReconCandidate( ReconCandidate candidate = new ReconCandidate(
result.getString("id"), result.getString("id"),
result.getString("name"), result.getString("name"),
typeIDs, typeIDs,
100 100
); );
Recon recon = Recon.makeFreebaseRecon(historyEntryID); Recon recon = Recon.makeFreebaseRecon(historyEntryID);
recon.addCandidate(candidate); recon.addCandidate(candidate);
recon.service = "mql"; recon.service = "mql";
recon.judgment = Judgment.Matched; recon.judgment = Judgment.Matched;
recon.judgmentAction = "auto"; recon.judgmentAction = "auto";
recon.match = candidate; recon.match = candidate;
recon.matchRank = 0; recon.matchRank = 0;
guidToRecon.put(guid, recon); guidToRecon.put(guid, recon);
} }
} }
} finally { } finally {
is.close(); is.close();
@ -206,7 +206,7 @@ public class GuidBasedReconConfig extends StrictReconConfig {
String guid = ((GuidBasedReconJob) job).guid; String guid = ((GuidBasedReconJob) job).guid;
Recon recon = guidToRecon.get(guid); Recon recon = guidToRecon.get(guid);
if (recon == null) { if (recon == null) {
recon = createNoMatchRecon(historyEntryID); recon = createNoMatchRecon(historyEntryID);
} }
recons.add(recon); recons.add(recon);
} }

View File

@ -167,50 +167,50 @@ public class IdBasedReconConfig extends StrictReconConfig {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
if (o.has("result")) { if (o.has("result")) {
JSONArray results = o.getJSONArray("result"); JSONArray results = o.getJSONArray("result");
int count = results.length(); int count = results.length();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject result = results.getJSONObject(i); JSONObject result = results.getJSONObject(i);
String id = result.getString("id"); String id = result.getString("id");
JSONArray types = result.getJSONArray("type"); JSONArray types = result.getJSONArray("type");
String[] typeIDs = new String[types.length()]; String[] typeIDs = new String[types.length()];
for (int j = 0; j < typeIDs.length; j++) { for (int j = 0; j < typeIDs.length; j++) {
typeIDs[j] = types.getString(j); typeIDs[j] = types.getString(j);
} }
ReconCandidate candidate = new ReconCandidate( ReconCandidate candidate = new ReconCandidate(
id, id,
result.getString("name"), result.getString("name"),
typeIDs, typeIDs,
100 100
); );
Recon recon = Recon.makeFreebaseRecon(historyEntryID); Recon recon = Recon.makeFreebaseRecon(historyEntryID);
recon.addCandidate(candidate); recon.addCandidate(candidate);
recon.service = "mql"; recon.service = "mql";
recon.judgment = Judgment.Matched; recon.judgment = Judgment.Matched;
recon.judgmentAction = "auto"; recon.judgmentAction = "auto";
recon.match = candidate; recon.match = candidate;
recon.matchRank = 0; recon.matchRank = 0;
idToRecon.put(id, recon); idToRecon.put(id, recon);
} }
} }
} finally { } finally {
is.close(); is.close();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
for (ReconJob job : jobs) { for (ReconJob job : jobs) {
String id = ((IdBasedReconJob) job).id; String id = ((IdBasedReconJob) job).id;
Recon recon = idToRecon.get(id); Recon recon = idToRecon.get(id);
if (recon == null) { if (recon == null) {
recon = createNoMatchRecon(historyEntryID); recon = createNoMatchRecon(historyEntryID);
} }
recons.add(recon); recons.add(recon);
} }

View File

@ -181,37 +181,37 @@ public class KeyBasedReconConfig extends StrictReconConfig {
String s = ParsingUtilities.inputStreamToString(is); String s = ParsingUtilities.inputStreamToString(is);
JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
if (o.has("result")) { if (o.has("result")) {
JSONArray results = o.getJSONArray("result"); JSONArray results = o.getJSONArray("result");
int count = results.length(); int count = results.length();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject result = results.getJSONObject(i); JSONObject result = results.getJSONObject(i);
String key = result.getJSONArray("key").getJSONObject(0).getString("value"); String key = result.getJSONArray("key").getJSONObject(0).getString("value");
JSONArray types = result.getJSONArray("type"); JSONArray types = result.getJSONArray("type");
String[] typeIDs = new String[types.length()]; String[] typeIDs = new String[types.length()];
for (int j = 0; j < typeIDs.length; j++) { for (int j = 0; j < typeIDs.length; j++) {
typeIDs[j] = types.getString(j); typeIDs[j] = types.getString(j);
} }
ReconCandidate candidate = new ReconCandidate( ReconCandidate candidate = new ReconCandidate(
result.getString("id"), result.getString("id"),
result.getString("name"), result.getString("name"),
typeIDs, typeIDs,
100 100
); );
Recon recon = Recon.makeFreebaseRecon(historyEntryID); Recon recon = Recon.makeFreebaseRecon(historyEntryID);
recon.addCandidate(candidate); recon.addCandidate(candidate);
recon.service = "mql"; recon.service = "mql";
recon.judgment = Judgment.Matched; recon.judgment = Judgment.Matched;
recon.judgmentAction = "auto"; recon.judgmentAction = "auto";
recon.match = candidate; recon.match = candidate;
recon.matchRank = 0; recon.matchRank = 0;
keyToRecon.put(key, recon); keyToRecon.put(key, recon);
} }
} }
} finally { } finally {
is.close(); is.close();
@ -224,7 +224,7 @@ public class KeyBasedReconConfig extends StrictReconConfig {
String key = ((KeyBasedReconJob) job).key; String key = ((KeyBasedReconJob) job).key;
Recon recon = keyToRecon.get(key); Recon recon = keyToRecon.get(key);
if (recon == null) { if (recon == null) {
recon = createNoMatchRecon(historyEntryID); recon = createNoMatchRecon(historyEntryID);
} }
recons.add(recon); recons.add(recon);
} }

View File

@ -60,10 +60,10 @@ abstract public class StrictReconConfig extends ReconConfig {
} }
protected Recon createNoMatchRecon(long historyEntryID) { protected Recon createNoMatchRecon(long historyEntryID) {
Recon recon = createNewRecon(historyEntryID); Recon recon = createNewRecon(historyEntryID);
recon.service = "mql"; recon.service = "mql";
recon.judgment = Judgment.None; recon.judgment = Judgment.None;
recon.matchRank = -1; recon.matchRank = -1;
return recon; return recon;
} }
} }

View File

@ -188,15 +188,15 @@ public class ExtendDataOperation extends EngineDependentOperation {
_rowIndices = rowIndices; _rowIndices = rowIndices;
return this; return this;
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -266,7 +266,7 @@ public class FreebaseUtils {
} }
static public String getFreeQUrl() { static public String getFreeQUrl() {
String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq"); String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq");
return url != null ? url : FREEQ_URL; return url != null ? url : FREEQ_URL;
} }
} }

View File

@ -1,4 +1,4 @@
/* /**
Copyright 2010, Google Inc. Copyright 2010, Google Inc.
All rights reserved. All rights reserved.
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.google.refine.browsing; package com.google.refine.browsing;
@ -59,104 +59,104 @@ import com.google.refine.model.Row;
* Faceted browsing engine. * Faceted browsing engine.
*/ */
public class Engine implements Jsonizable { public class Engine implements Jsonizable {
static public enum Mode { static public enum Mode {
RowBased, RowBased,
RecordBased RecordBased
} }
public final static String INCLUDE_DEPENDENT = "includeDependent"; public final static String INCLUDE_DEPENDENT = "includeDependent";
public final static String MODE = "mode"; public final static String MODE = "mode";
public final static String MODE_ROW_BASED = "row-based"; public final static String MODE_ROW_BASED = "row-based";
public final static String MODE_RECORD_BASED = "record-based"; public final static String MODE_RECORD_BASED = "record-based";
protected Project _project; protected Project _project;
protected List<Facet> _facets = new LinkedList<Facet>(); protected List<Facet> _facets = new LinkedList<Facet>();
protected Mode _mode = Mode.RowBased; protected Mode _mode = Mode.RowBased;
static public String modeToString(Mode mode) { static public String modeToString(Mode mode) {
return mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED; return mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED;
} }
static public Mode stringToMode(String s) { static public Mode stringToMode(String s) {
return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased; return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased;
} }
public Engine(Project project) { public Engine(Project project) {
_project = project; _project = project;
} }
public Mode getMode() { public Mode getMode() {
return _mode; return _mode;
} }
public void setMode(Mode mode) { public void setMode(Mode mode) {
_mode = mode; _mode = mode;
} }
public FilteredRows getAllRows() { public FilteredRows getAllRows() {
return new FilteredRows() { return new FilteredRows() {
@Override @Override
public void accept(Project project, RowVisitor visitor) { public void accept(Project project, RowVisitor visitor) {
try { try {
visitor.start(project); visitor.start(project);
int c = project.rows.size(); int c = project.rows.size();
for (int rowIndex = 0; rowIndex < c; rowIndex++) { for (int rowIndex = 0; rowIndex < c; rowIndex++) {
Row row = project.rows.get(rowIndex); Row row = project.rows.get(rowIndex);
visitor.visit(project, rowIndex, row); visitor.visit(project, rowIndex, row);
} }
} finally { } finally {
visitor.end(project); visitor.end(project);
} }
} }
}; };
} }
public FilteredRows getAllFilteredRows() { public FilteredRows getAllFilteredRows() {
return getFilteredRows(null); return getFilteredRows(null);
} }
public FilteredRows getFilteredRows(Facet except) { public FilteredRows getFilteredRows(Facet except) {
if (_mode == Mode.RecordBased) { if (_mode == Mode.RecordBased) {
return new FilteredRecordsAsFilteredRows(getFilteredRecords(except)); return new FilteredRecordsAsFilteredRows(getFilteredRecords(except));
} else if (_mode == Mode.RowBased) { } else if (_mode == Mode.RowBased) {
ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(); ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows();
for (Facet facet : _facets) { for (Facet facet : _facets) {
if (facet != except) { if (facet != except) {
RowFilter rowFilter = facet.getRowFilter(_project); RowFilter rowFilter = facet.getRowFilter(_project);
if (rowFilter != null) { if (rowFilter != null) {
cfr.add(rowFilter); cfr.add(rowFilter);
} }
} }
} }
return cfr; return cfr;
} }
throw new InternalError("Unknown mode."); throw new InternalError("Unknown mode.");
} }
public FilteredRecords getAllRecords() { public FilteredRecords getAllRecords() {
return new FilteredRecords() { return new FilteredRecords() {
@Override @Override
public void accept(Project project, RecordVisitor visitor) { public void accept(Project project, RecordVisitor visitor) {
try { try {
visitor.start(project); visitor.start(project);
int c = project.recordModel.getRecordCount(); int c = project.recordModel.getRecordCount();
for (int r = 0; r < c; r++) { for (int r = 0; r < c; r++) {
visitor.visit(project, project.recordModel.getRecord(r)); visitor.visit(project, project.recordModel.getRecord(r));
} }
} finally { } finally {
visitor.end(project); visitor.end(project);
} }
} }
}; };
} }
public FilteredRecords getFilteredRecords() { public FilteredRecords getFilteredRecords() {
return getFilteredRecords(null); return getFilteredRecords(null);
} }
public FilteredRecords getFilteredRecords(Facet except) { public FilteredRecords getFilteredRecords(Facet except) {
if (_mode == Mode.RecordBased) { if (_mode == Mode.RecordBased) {
ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords(); ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords();
for (Facet facet : _facets) { for (Facet facet : _facets) {
if (facet != except) { if (facet != except) {
RecordFilter recordFilter = facet.getRecordFilter(_project); RecordFilter recordFilter = facet.getRecordFilter(_project);
@ -166,23 +166,23 @@ public class Engine implements Jsonizable {
} }
} }
return cfr; return cfr;
} }
throw new InternalError("This method should not be called when the engine is not in record mode."); throw new InternalError("This method should not be called when the engine is not in record mode.");
} }
public void initializeFromJSON(JSONObject o) throws Exception { public void initializeFromJSON(JSONObject o) throws Exception {
if (o == null) { if (o == null) {
return; return;
} }
if (o.has("facets") && !o.isNull("facets")) { if (o.has("facets") && !o.isNull("facets")) {
JSONArray a = o.getJSONArray("facets"); JSONArray a = o.getJSONArray("facets");
int length = a.length(); int length = a.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
JSONObject fo = a.getJSONObject(i); JSONObject fo = a.getJSONObject(i);
String type = fo.has("type") ? fo.getString("type") : "list"; String type = fo.has("type") ? fo.getString("type") : "list";
Facet facet = null; Facet facet = null;
if ("list".equals(type)) { if ("list".equals(type)) {
facet = new ListFacet(); facet = new ListFacet();
@ -195,53 +195,53 @@ public class Engine implements Jsonizable {
} else if ("text".equals(type)) { } else if ("text".equals(type)) {
facet = new TextSearchFacet(); facet = new TextSearchFacet();
} }
if (facet != null) { if (facet != null) {
facet.initializeFromJSON(_project, fo); facet.initializeFromJSON(_project, fo);
_facets.add(facet); _facets.add(facet);
} }
} }
} }
// for backward compatibility // for backward compatibility
if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) { if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) {
_mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased; _mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased;
} }
if (o.has(MODE) && !o.isNull(MODE)) { if (o.has(MODE) && !o.isNull(MODE)) {
_mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased; _mode = MODE_ROW_BASED.equals(o.getString(MODE)) ? Mode.RowBased : Mode.RecordBased;
} }
} }
public void computeFacets() throws JSONException { public void computeFacets() throws JSONException {
if (_mode == Mode.RowBased) { if (_mode == Mode.RowBased) {
for (Facet facet : _facets) { for (Facet facet : _facets) {
FilteredRows filteredRows = getFilteredRows(facet); FilteredRows filteredRows = getFilteredRows(facet);
facet.computeChoices(_project, filteredRows); facet.computeChoices(_project, filteredRows);
} }
} else if (_mode == Mode.RecordBased) { } else if (_mode == Mode.RecordBased) {
for (Facet facet : _facets) { for (Facet facet : _facets) {
FilteredRecords filteredRecords = getFilteredRecords(facet); FilteredRecords filteredRecords = getFilteredRecords(facet);
facet.computeChoices(_project, filteredRecords); facet.computeChoices(_project, filteredRecords);
} }
} else { } else {
throw new InternalError("Unknown mode."); throw new InternalError("Unknown mode.");
} }
} }
@Override @Override
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("facets"); writer.key("facets");
writer.array(); writer.array();
for (Facet facet : _facets) { for (Facet facet : _facets) {
facet.write(writer, options); facet.write(writer, options);
} }
writer.endArray(); writer.endArray();
writer.key(MODE); writer.value(_mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED); writer.key(MODE); writer.value(_mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED);
writer.endObject(); writer.endObject();
} }

View File

@ -41,12 +41,12 @@ import com.google.refine.model.Record;
* particular criteria, such as facets' constraints. * particular criteria, such as facets' constraints.
*/ */
public interface RecordVisitor { public interface RecordVisitor {
public void start(Project project); // called before any visit() call public void start(Project project); // called before any visit() call
public boolean visit( public boolean visit(
Project project, Project project,
Record record Record record
); );
public void end(Project project); // called after all visit() calls public void end(Project project); // called after all visit() calls
} }

View File

@ -41,13 +41,13 @@ import com.google.refine.model.Row;
* particular criteria, such as facets' constraints. * particular criteria, such as facets' constraints.
*/ */
public interface RowVisitor { public interface RowVisitor {
public void start(Project project); // called before any visit() call public void start(Project project); // called before any visit() call
public boolean visit( public boolean visit(
Project project, Project project,
int rowIndex, // zero-based row index int rowIndex, // zero-based row index
Row row Row row
); );
public void end(Project project); // called after all visit() calls public void end(Project project); // called after all visit() calls
} }

View File

@ -218,11 +218,11 @@ public class ListFacet implements Facet {
@Override @Override
public RecordFilter getRecordFilter(Project project) { public RecordFilter getRecordFilter(Project project) {
RowFilter rowFilter = getRowFilter(project); RowFilter rowFilter = getRowFilter(project);
return rowFilter == null ? null : return rowFilter == null ? null :
(_invert ? (_invert ?
new AllRowsRecordFilter(rowFilter) : new AllRowsRecordFilter(rowFilter) :
new AnyRowRecordFilter(rowFilter)); new AnyRowRecordFilter(rowFilter));
} }
@Override @Override

View File

@ -201,8 +201,8 @@ public class RangeFacet implements Facet {
public RowFilter getRowFilter(Project project) { public RowFilter getRowFilter(Project project) {
if (_eval != null && _errorMessage == null && _selected) { if (_eval != null && _errorMessage == null && _selected) {
return new ExpressionNumberComparisonRowFilter( return new ExpressionNumberComparisonRowFilter(
getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) { getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) {
@Override @Override
protected boolean checkValue(double d) { protected boolean checkValue(double d) {
return d >= _from && d < _to; return d >= _from && d < _to;
@ -215,8 +215,8 @@ public class RangeFacet implements Facet {
@Override @Override
public RecordFilter getRecordFilter(Project project) { public RecordFilter getRecordFilter(Project project) {
RowFilter rowFilter = getRowFilter(project); RowFilter rowFilter = getRowFilter(project);
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
} }
@Override @Override
@ -267,7 +267,7 @@ public class RangeFacet implements Facet {
} }
protected RowEvaluable getRowEvaluable(Project project) { protected RowEvaluable getRowEvaluable(Project project) {
return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval); return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval);
} }
protected void retrieveDataFromBaseBinIndex(NumericBinIndex index) { protected void retrieveDataFromBaseBinIndex(NumericBinIndex index) {

View File

@ -122,12 +122,12 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
@ -153,10 +153,10 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor {
@Override @Override
public boolean visit(Project project, Record record) { public boolean visit(Project project, Record record) {
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
visit(project, r, project.rows.get(r)); visit(project, r, project.rows.get(r));
} }
return false; return false;
} }
public RenderedImage getImage() { public RenderedImage getImage() {

View File

@ -315,8 +315,8 @@ public class ScatterplotFacet implements Facet {
@Override @Override
public RecordFilter getRecordFilter(Project project) { public RecordFilter getRecordFilter(Project project) {
RowFilter rowFilter = getRowFilter(project); RowFilter rowFilter = getRowFilter(project);
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
} }
@Override @Override
@ -414,7 +414,7 @@ public class ScatterplotFacet implements Facet {
} }
public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression) { public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression) {
return getBinIndex(project, column, eval, expression, "row-based"); return getBinIndex(project, column, eval, expression, "row-based");
} }
public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression, String mode) { public static NumericBinIndex getBinIndex(Project project, Column column, Evaluable eval, String expression, String mode) {
@ -429,10 +429,10 @@ public class ScatterplotFacet implements Facet {
NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key); NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key);
if (index == null) { if (index == null) {
index = "row-based".equals(mode) ? index = "row-based".equals(mode) ?
new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) : new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) :
new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)); new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval));
column.setPrecompute(key, index); column.setPrecompute(key, index);
} }
return index; return index;
} }

View File

@ -101,13 +101,13 @@ public class TextSearchFacet implements Facet {
if ("regex".equals(_mode)) { if ("regex".equals(_mode)) {
try { try {
_pattern = Pattern.compile( _pattern = Pattern.compile(
_query, _query,
_caseSensitive ? 0 : Pattern.CASE_INSENSITIVE); _caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
} catch (java.util.regex.PatternSyntaxException e) { } catch (java.util.regex.PatternSyntaxException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else if (!_caseSensitive) { } else if (!_caseSensitive) {
_query = _query.toLowerCase(); _query = _query.toLowerCase();
} }
} }
} }
@ -141,17 +141,17 @@ public class TextSearchFacet implements Facet {
@Override @Override
public RecordFilter getRecordFilter(Project project) { public RecordFilter getRecordFilter(Project project) {
RowFilter rowFilter = getRowFilter(project); RowFilter rowFilter = getRowFilter(project);
return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter);
} }
@Override @Override
public void computeChoices(Project project, FilteredRows filteredRows) { public void computeChoices(Project project, FilteredRows filteredRows) {
// nothing to do // nothing to do
} }
@Override @Override
public void computeChoices(Project project, FilteredRecords filteredRecords) { public void computeChoices(Project project, FilteredRecords filteredRecords) {
// nothing to do // nothing to do
} }
} }

View File

@ -55,7 +55,7 @@ import com.google.refine.model.Project;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
public class TimeRangeFacet extends RangeFacet { public class TimeRangeFacet extends RangeFacet {
protected boolean _selectTime; // whether the time selection applies, default true protected boolean _selectTime; // whether the time selection applies, default true
protected boolean _selectNonTime; protected boolean _selectNonTime;
@ -153,7 +153,7 @@ public class TimeRangeFacet extends RangeFacet {
public RowFilter getRowFilter(Project project) { public RowFilter getRowFilter(Project project) {
if (_eval != null && _errorMessage == null && _selected) { if (_eval != null && _errorMessage == null && _selected) {
return new ExpressionTimeComparisonRowFilter( return new ExpressionTimeComparisonRowFilter(
getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) { getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) {
@Override @Override
protected boolean checkValue(long t) { protected boolean checkValue(long t) {

View File

@ -39,19 +39,19 @@ import com.google.refine.model.Project;
import com.google.refine.model.Record; import com.google.refine.model.Record;
public class AllRowsRecordFilter implements RecordFilter { public class AllRowsRecordFilter implements RecordFilter {
final protected RowFilter _rowFilter; final protected RowFilter _rowFilter;
public AllRowsRecordFilter(RowFilter rowFilter) {
_rowFilter = rowFilter;
}
@Override public AllRowsRecordFilter(RowFilter rowFilter) {
public boolean filterRecord(Project project, Record record) { _rowFilter = rowFilter;
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { }
if (!_rowFilter.filterRow(project, r, project.rows.get(r))) {
return false; @Override
} public boolean filterRecord(Project project, Record record) {
} for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
return true; if (!_rowFilter.filterRow(project, r, project.rows.get(r))) {
} return false;
}
}
return true;
}
} }

View File

@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
met: met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the in the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of Google Inc. nor the names of its * Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from contributors may be used to endorse or promote products derived from
this software without specific prior written permission. this software without specific prior written permission.
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.google.refine.browsing.filters; package com.google.refine.browsing.filters;
@ -39,19 +39,19 @@ import com.google.refine.model.Project;
import com.google.refine.model.Record; import com.google.refine.model.Record;
public class AnyRowRecordFilter implements RecordFilter { public class AnyRowRecordFilter implements RecordFilter {
final protected RowFilter _rowFilter; final protected RowFilter _rowFilter;
public AnyRowRecordFilter(RowFilter rowFilter) {
_rowFilter = rowFilter;
}
@Override public AnyRowRecordFilter(RowFilter rowFilter) {
public boolean filterRecord(Project project, Record record) { _rowFilter = rowFilter;
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { }
if (_rowFilter.filterRow(project, r, project.rows.get(r))) {
return true; @Override
} public boolean filterRecord(Project project, Record record) {
} for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
return false; if (_rowFilter.filterRow(project, r, project.rows.get(r))) {
} return true;
}
}
return false;
}
} }

View File

@ -52,20 +52,20 @@ import com.google.refine.model.Row;
* values. * values.
*/ */
abstract public class ExpressionNumberComparisonRowFilter implements RowFilter { abstract public class ExpressionNumberComparisonRowFilter implements RowFilter {
final protected RowEvaluable _rowEvaluable; final protected RowEvaluable _rowEvaluable;
final protected boolean _selectNumeric; final protected boolean _selectNumeric;
final protected boolean _selectNonNumeric; final protected boolean _selectNonNumeric;
final protected boolean _selectBlank; final protected boolean _selectBlank;
final protected boolean _selectError; final protected boolean _selectError;
public ExpressionNumberComparisonRowFilter( public ExpressionNumberComparisonRowFilter(
RowEvaluable rowEvaluable, RowEvaluable rowEvaluable,
boolean selectNumeric, boolean selectNumeric,
boolean selectNonNumeric, boolean selectNonNumeric,
boolean selectBlank, boolean selectBlank,
boolean selectError boolean selectError
) { ) {
_rowEvaluable = rowEvaluable; _rowEvaluable = rowEvaluable;
_selectNumeric = selectNumeric; _selectNumeric = selectNumeric;
_selectNonNumeric = selectNonNumeric; _selectNonNumeric = selectNonNumeric;
_selectBlank = selectBlank; _selectBlank = selectBlank;

View File

@ -46,21 +46,21 @@ import com.google.refine.expr.ExpressionUtils;
*/ */
abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumberComparisonRowFilter { abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumberComparisonRowFilter {
final protected boolean _selectTime; final protected boolean _selectTime;
final protected boolean _selectNonTime; final protected boolean _selectNonTime;
public ExpressionTimeComparisonRowFilter( public ExpressionTimeComparisonRowFilter(
RowEvaluable rowEvaluable, RowEvaluable rowEvaluable,
boolean selectTime, boolean selectTime,
boolean selectNonTime, boolean selectNonTime,
boolean selectBlank, boolean selectBlank,
boolean selectError boolean selectError
) { ) {
super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError); super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError);
_selectTime = selectTime; _selectTime = selectTime;
_selectNonTime = selectNonTime; _selectNonTime = selectNonTime;
} }
@Override @Override
protected boolean checkValue(Object v) { protected boolean checkValue(Object v) {
if (ExpressionUtils.isError(v)) { if (ExpressionUtils.isError(v)) {
@ -80,7 +80,7 @@ abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumber
// not really needed for operation, just to make extending the abstract class possible // not really needed for operation, just to make extending the abstract class possible
@Override @Override
protected boolean checkValue(double d) { protected boolean checkValue(double d) {
return false; return false;
} }
abstract protected boolean checkValue(long d); abstract protected boolean checkValue(long d);

View File

@ -54,21 +54,21 @@ public class ConjunctiveFilteredRecords implements FilteredRecords {
@Override @Override
public void accept(Project project, RecordVisitor visitor) { public void accept(Project project, RecordVisitor visitor) {
try { try {
visitor.start(project); visitor.start(project);
int c = project.recordModel.getRecordCount(); int c = project.recordModel.getRecordCount();
for (int r = 0; r < c; r++) { for (int r = 0; r < c; r++) {
Record record = project.recordModel.getRecord(r); Record record = project.recordModel.getRecord(r);
if (matchRecord(project, record)) { if (matchRecord(project, record)) {
if (visitor.visit(project, record)) { if (visitor.visit(project, record)) {
return; return;
} }
} }
} }
} finally { } finally {
visitor.end(project); visitor.end(project);
} }
} }
protected boolean matchRecord(Project project, Record record) { protected boolean matchRecord(Project project, Record record) {

View File

@ -55,19 +55,19 @@ public class ConjunctiveFilteredRows implements FilteredRows {
@Override @Override
public void accept(Project project, RowVisitor visitor) { public void accept(Project project, RowVisitor visitor) {
try { try {
visitor.start(project); visitor.start(project);
int c = project.rows.size(); int c = project.rows.size();
for (int rowIndex = 0; rowIndex < c; rowIndex++) { for (int rowIndex = 0; rowIndex < c; rowIndex++) {
Row row = project.rows.get(rowIndex); Row row = project.rows.get(rowIndex);
if (matchRow(project, rowIndex, row)) { if (matchRow(project, rowIndex, row)) {
visitRow(project, visitor, rowIndex, row); visitRow(project, visitor, rowIndex, row);
} }
} }
} finally { } finally {
visitor.end(project); visitor.end(project);
} }
} }
protected void visitRow(Project project, RowVisitor visitor, int rowIndex, Row row) { protected void visitRow(Project project, RowVisitor visitor, int rowIndex, Row row) {

View File

@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
met: met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the in the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of Google Inc. nor the names of its * Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from contributors may be used to endorse or promote products derived from
this software without specific prior written permission. this software without specific prior written permission.
@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.google.refine.browsing.util; package com.google.refine.browsing.util;
@ -56,94 +56,94 @@ import com.google.refine.model.Row;
* from a given expression. * from a given expression.
*/ */
public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor { public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor {
static public class IndexedNominalFacetChoice extends NominalFacetChoice { static public class IndexedNominalFacetChoice extends NominalFacetChoice {
int _latestIndex; int _latestIndex;
public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) { public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) {
super(decoratedValue); super(decoratedValue);
_latestIndex = latestIndex; _latestIndex = latestIndex;
} }
} }
/* /*
* Configuration * Configuration
*/ */
final protected Evaluable _evaluable; final protected Evaluable _evaluable;
final protected String _columnName; final protected String _columnName;
final protected int _cellIndex; final protected int _cellIndex;
/* /*
* Computed results * Computed results
*/ */
final public Map<Object, IndexedNominalFacetChoice> choices = new HashMap<Object, IndexedNominalFacetChoice>(); final public Map<Object, IndexedNominalFacetChoice> choices = new HashMap<Object, IndexedNominalFacetChoice>();
public int blankCount = 0; public int blankCount = 0;
public int errorCount = 0; public int errorCount = 0;
/* /*
* Scratch pad variables * Scratch pad variables
*/ */
protected boolean hasBlank; protected boolean hasBlank;
protected boolean hasError; protected boolean hasError;
public ExpressionNominalValueGrouper(Evaluable evaluable, String columnName, int cellIndex) { public ExpressionNominalValueGrouper(Evaluable evaluable, String columnName, int cellIndex) {
_evaluable = evaluable; _evaluable = evaluable;
_columnName = columnName; _columnName = columnName;
_cellIndex = cellIndex; _cellIndex = cellIndex;
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
hasError = false; hasError = false;
hasBlank = false; hasBlank = false;
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
visitRow(project, rowIndex, row, bindings, rowIndex); visitRow(project, rowIndex, row, bindings, rowIndex);
if (hasError) { if (hasError) {
errorCount++; errorCount++;
} }
if (hasBlank) { if (hasBlank) {
blankCount++; blankCount++;
} }
return false; return false;
} }
@Override @Override
public boolean visit(Project project, Record record) { public boolean visit(Project project, Record record) {
hasError = false; hasError = false;
hasBlank = false; hasBlank = false;
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
Row row = project.rows.get(r); Row row = project.rows.get(r);
visitRow(project, r, row, bindings, record.recordIndex); visitRow(project, r, row, bindings, record.recordIndex);
} }
if (hasError) { if (hasError) {
errorCount++; errorCount++;
} }
if (hasBlank) { if (hasBlank) {
blankCount++; blankCount++;
} }
return false; return false;
} }
protected void visitRow(Project project, int rowIndex, Row row, Properties bindings, int index) { protected void visitRow(Project project, int rowIndex, Row row, Properties bindings, int index) {
Object value = evalRow(project, rowIndex, row, bindings); Object value = evalRow(project, rowIndex, row, bindings);
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
@ -155,83 +155,83 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor
processValue(v, rowIndex); processValue(v, rowIndex);
} }
} else { } else {
processValue(value, rowIndex); processValue(value, rowIndex);
} }
} else { } else {
processValue(value, rowIndex); processValue(value, rowIndex);
} }
} }
protected Object evalRow(Project project, int rowIndex, Row row, Properties bindings) { protected Object evalRow(Project project, int rowIndex, Row row, Properties bindings) {
Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex); Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex);
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
return _evaluable.evaluate(bindings); return _evaluable.evaluate(bindings);
} }
protected void processValue(Object value, int index) { protected void processValue(Object value, int index) {
if (ExpressionUtils.isError(value)) { if (ExpressionUtils.isError(value)) {
hasError = true; hasError = true;
} else if (ExpressionUtils.isNonBlankData(value)) { } else if (ExpressionUtils.isNonBlankData(value)) {
String valueString = value.toString(); String valueString = value.toString();
IndexedNominalFacetChoice facetChoice = choices.get(valueString); IndexedNominalFacetChoice facetChoice = choices.get(valueString);
if (facetChoice != null) { if (facetChoice != null) {
if (facetChoice._latestIndex < index) { if (facetChoice._latestIndex < index) {
facetChoice._latestIndex = index; facetChoice._latestIndex = index;
facetChoice.count++; facetChoice.count++;
} }
} else { } else {
String label = value.toString(); String label = value.toString();
DecoratedValue dValue = new DecoratedValue(value, label); DecoratedValue dValue = new DecoratedValue(value, label);
IndexedNominalFacetChoice choice = IndexedNominalFacetChoice choice =
new IndexedNominalFacetChoice(dValue, index); new IndexedNominalFacetChoice(dValue, index);
choice.count = 1; choice.count = 1;
choices.put(valueString, choice); choices.put(valueString, choice);
} }
} else { } else {
hasBlank = true; hasBlank = true;
} }
} }
public RowEvaluable getChoiceCountRowEvaluable() { public RowEvaluable getChoiceCountRowEvaluable() {
return new RowEvaluable() { return new RowEvaluable() {
@Override @Override
public Object eval(Project project, int rowIndex, Row row, Properties bindings) { public Object eval(Project project, int rowIndex, Row row, Properties bindings) {
Object value = evalRow(project, rowIndex, row, bindings); Object value = evalRow(project, rowIndex, row, bindings);
return getChoiceValueCountMultiple(value); return getChoiceValueCountMultiple(value);
} }
}; };
} }
public Object getChoiceValueCountMultiple(Object value) { public Object getChoiceValueCountMultiple(Object value) {
if (value != null) { if (value != null) {
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
Object[] choiceValues = (Object[]) value; Object[] choiceValues = (Object[]) value;
List<Integer> counts = new ArrayList<Integer>(choiceValues.length); List<Integer> counts = new ArrayList<Integer>(choiceValues.length);
for (int i = 0; i < choiceValues.length; i++) { for (int i = 0; i < choiceValues.length; i++) {
counts.add(getChoiceValueCount(choiceValues[i])); counts.add(getChoiceValueCount(choiceValues[i]));
} }
return counts; return counts;
} else if (value instanceof Collection<?>) { } else if (value instanceof Collection<?>) {
List<Object> choiceValues = ExpressionUtils.toObjectList(value); List<Object> choiceValues = ExpressionUtils.toObjectList(value);
List<Integer> counts = new ArrayList<Integer>(choiceValues.size()); List<Integer> counts = new ArrayList<Integer>(choiceValues.size());
int count = choiceValues.size(); int count = choiceValues.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
counts.add(getChoiceValueCount(choiceValues.get(i))); counts.add(getChoiceValueCount(choiceValues.get(i)));
} }
return counts; return counts;
} }
} }
return getChoiceValueCount(value); return getChoiceValueCount(value);
} }
public Integer getChoiceValueCount(Object choiceValue) { public Integer getChoiceValueCount(Object choiceValue) {
if (ExpressionUtils.isError(choiceValue)) { if (ExpressionUtils.isError(choiceValue)) {
return errorCount; return errorCount;

View File

@ -51,9 +51,9 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
/* /*
* Configuration * Configuration
*/ */
final protected RowEvaluable _rowEvaluable; final protected RowEvaluable _rowEvaluable;
final protected NumericBinIndex _index; // base bins final protected NumericBinIndex _index; // base bins
/* /*
* Computed results * Computed results
*/ */
@ -72,19 +72,19 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
protected boolean hasNonNumeric; protected boolean hasNonNumeric;
public ExpressionNumericValueBinner(RowEvaluable rowEvaluable, NumericBinIndex index) { public ExpressionNumericValueBinner(RowEvaluable rowEvaluable, NumericBinIndex index) {
_rowEvaluable = rowEvaluable; _rowEvaluable = rowEvaluable;
_index = index; _index = index;
bins = new int[_index.getBins().length]; bins = new int[_index.getBins().length];
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
@ -105,7 +105,7 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor {
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
processRow(project, r, project.rows.get(r), bindings); processRow(project, r, project.rows.get(r), bindings);
} }
updateCounts(); updateCounts();

View File

@ -50,13 +50,13 @@ import com.google.refine.model.Row;
* from a given expression. * from a given expression.
*/ */
public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor { public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
/* /*
* Configuration * Configuration
*/ */
final protected RowEvaluable _rowEvaluable; final protected RowEvaluable _rowEvaluable;
final protected TimeBinIndex _index; // base bins final protected TimeBinIndex _index; // base bins
/* /*
* Computed results * Computed results
*/ */
@ -75,19 +75,19 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
protected boolean hasNonTime; protected boolean hasNonTime;
public ExpressionTimeValueBinner(RowEvaluable rowEvaluable, TimeBinIndex index) { public ExpressionTimeValueBinner(RowEvaluable rowEvaluable, TimeBinIndex index) {
_rowEvaluable = rowEvaluable; _rowEvaluable = rowEvaluable;
_index = index; _index = index;
bins = new int[_index.getBins().length]; bins = new int[_index.getBins().length];
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
@ -108,7 +108,7 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor {
Properties bindings = ExpressionUtils.createBindings(project); Properties bindings = ExpressionUtils.createBindings(project);
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
processRow(project, r, project.rows.get(r), bindings); processRow(project, r, project.rows.get(r), bindings);
} }
updateCounts(); updateCounts();

View File

@ -74,17 +74,17 @@ abstract public class TimeBinIndex {
protected boolean _hasBlank = false; protected boolean _hasBlank = false;
protected long[] steps = { protected long[] steps = {
1, // msec 1, // msec
1000, // sec 1000, // sec
1000*60, // min 1000*60, // min
1000*60*60, // hour 1000*60*60, // hour
1000*60*60*24, // day 1000*60*60*24, // day
1000*60*60*24*7, // week 1000*60*60*24*7, // week
1000l*2629746l, // month (average Gregorian year / 12) 1000l*2629746l, // month (average Gregorian year / 12)
1000l*31556952l, // year (average Gregorian year) 1000l*31556952l, // year (average Gregorian year)
1000l*31556952l*10l, // decade 1000l*31556952l*10l, // decade
1000l*31556952l*100l, // century 1000l*31556952l*100l, // century
1000l*31556952l*1000l, // millennium 1000l*31556952l*1000l, // millennium
}; };
abstract protected void iterate(Project project, RowEvaluable rowEvaluable, List<Long> allValues); abstract protected void iterate(Project project, RowEvaluable rowEvaluable, List<Long> allValues);
@ -110,10 +110,10 @@ abstract public class TimeBinIndex {
long diff = _max - _min; long diff = _max - _min;
for (int i = 0; i < steps.length; i++) { for (int i = 0; i < steps.length; i++) {
_step = steps[i]; _step = steps[i];
if (diff / _step <= 100) break; if (diff / _step <= 100) break;
} }
_bins = new int[(int) (diff / _step) + 1]; _bins = new int[(int) (diff / _step) + 1];
for (long d : allValues) { for (long d : allValues) {
@ -180,7 +180,7 @@ abstract public class TimeBinIndex {
_hasError = true; _hasError = true;
} else if (ExpressionUtils.isNonBlankData(v)) { } else if (ExpressionUtils.isNonBlankData(v)) {
if (v instanceof Calendar) { if (v instanceof Calendar) {
v = ((Calendar) v).getTime(); v = ((Calendar) v).getTime();
} }
if (v instanceof Date) { if (v instanceof Date) {
@ -201,7 +201,7 @@ abstract public class TimeBinIndex {
_hasError = true; _hasError = true;
} else if (ExpressionUtils.isNonBlankData(v)) { } else if (ExpressionUtils.isNonBlankData(v)) {
if (v instanceof Calendar) { if (v instanceof Calendar) {
v = ((Calendar) v).getTime(); v = ((Calendar) v).getTime();
} }
if (v instanceof Date) { if (v instanceof Date) {
@ -218,7 +218,7 @@ abstract public class TimeBinIndex {
_totalValueCount++; _totalValueCount++;
if (value instanceof Calendar) { if (value instanceof Calendar) {
value = ((Calendar) value).getTime(); value = ((Calendar) value).getTime();
} }
if (value instanceof Date) { if (value instanceof Date) {

View File

@ -42,7 +42,7 @@ import com.google.refine.model.Record;
import com.google.refine.model.Row; import com.google.refine.model.Row;
public class TimeBinRecordIndex extends TimeBinIndex { public class TimeBinRecordIndex extends TimeBinIndex {
public TimeBinRecordIndex(Project project, RowEvaluable rowEvaluable) { public TimeBinRecordIndex(Project project, RowEvaluable rowEvaluable) {
super(project, rowEvaluable); super(project, rowEvaluable);
} }

View File

@ -42,7 +42,7 @@ import com.google.refine.model.Row;
public class TimeBinRowIndex extends TimeBinIndex { public class TimeBinRowIndex extends TimeBinIndex {
public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) { public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) {
super(project, rowEvaluable); super(project, rowEvaluable);
} }

View File

@ -103,12 +103,12 @@ public class BinningClusterer extends Clusterer {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -115,12 +115,12 @@ public class kNNClusterer extends Clusterer {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
@ -167,12 +167,12 @@ public class kNNClusterer extends Clusterer {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -57,14 +57,14 @@ public class OpenWorkspaceDirCommand extends Command {
File dir = ((FileProjectManager) ProjectManager.singleton).getWorkspaceDir(); File dir = ((FileProjectManager) ProjectManager.singleton).getWorkspaceDir();
if (Desktop.isDesktopSupported()) { if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop(); Desktop desktop = Desktop.getDesktop();
desktop.open(dir); desktop.open(dir);
} else /* if Mac */ { } else /* if Mac */ {
Runtime.getRuntime().exec( Runtime.getRuntime().exec(
"open .", "open .",
new String[] {}, new String[] {},
dir dir
); );
} }
respond(response, "{ \"code\" : \"ok\" }"); respond(response, "{ \"code\" : \"ok\" }");

View File

@ -51,10 +51,10 @@ import com.google.refine.model.Project;
import com.google.refine.preference.TopList; import com.google.refine.preference.TopList;
public class GetExpressionHistoryCommand extends Command { public class GetExpressionHistoryCommand extends Command {
static protected List<String> toExpressionList(Object o) { static protected List<String> toExpressionList(Object o) {
return o == null ? new ArrayList<String>() : ((TopList) o).getList(); return o == null ? new ArrayList<String>() : ((TopList) o).getList();
} }
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) public void doGet(HttpServletRequest request, HttpServletResponse response)

View File

@ -56,15 +56,15 @@ import com.google.refine.model.Project;
public class ExportRowsCommand extends Command { public class ExportRowsCommand extends Command {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static public Properties getRequestParameters(HttpServletRequest request) { static public Properties getRequestParameters(HttpServletRequest request) {
Properties options = new Properties(); Properties options = new Properties();
Enumeration<String> en = request.getParameterNames(); Enumeration<String> en = request.getParameterNames();
while (en.hasMoreElements()) { while (en.hasMoreElements()) {
String name = en.nextElement(); String name = en.nextElement();
options.put(name, request.getParameter(name)); options.put(name, request.getParameter(name));
} }
return options; return options;
} }
@Override @Override

View File

@ -50,16 +50,16 @@ public class ReorderRowsCommand extends EngineDependentCommand {
@Override @Override
protected AbstractOperation createOperation(Project project, protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception { HttpServletRequest request, JSONObject engineConfig) throws Exception {
String mode = request.getParameter("mode"); String mode = request.getParameter("mode");
JSONObject sorting = null; JSONObject sorting = null;
try{ try{
String json = request.getParameter("sorting"); String json = request.getParameter("sorting");
sorting = (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json); sorting = (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json);
} catch (JSONException e) { } catch (JSONException e) {
// ignore // ignore
} }
return new RowReorderOperation(Engine.stringToMode(mode), sorting); return new RowReorderOperation(Engine.stringToMode(mode), sorting);

View File

@ -48,7 +48,7 @@ import com.google.refine.model.Row;
public class HtmlTableExporter implements WriterExporter { public class HtmlTableExporter implements WriterExporter {
@Override @Override
public String getContentType() { public String getContentType() {
return "text/html"; return "text/html";
} }
@ -84,12 +84,12 @@ public class HtmlTableExporter implements WriterExporter {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -97,12 +97,12 @@ public class XlsExporter implements StreamExporter {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -77,10 +77,10 @@ public class WrappedRow implements HasFields {
} }
protected class WrappedRecord implements HasFields { protected class WrappedRecord implements HasFields {
final Record _record; final Record _record;
protected WrappedRecord(Record record) { protected WrappedRecord(Record record) {
_record = record; _record = record;
} }
@Override @Override

View File

@ -54,36 +54,36 @@ public class FacetCount implements Function {
@Override @Override
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) { if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) {
Object choiceValue = args[0]; // choice value to look up Object choiceValue = args[0]; // choice value to look up
String facetExpression = (String) args[1]; String facetExpression = (String) args[1];
String columnName = (String) args[2]; String columnName = (String) args[2];
Project project = (Project) bindings.get("project"); Project project = (Project) bindings.get("project");
Column column = project.columnModel.getColumnByName(columnName); Column column = project.columnModel.getColumnByName(columnName);
if (column == null) { if (column == null) {
return new EvalError("No such column named " + columnName); return new EvalError("No such column named " + columnName);
} }
String key = "nominal-bin:" + facetExpression; String key = "nominal-bin:" + facetExpression;
ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key); ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key);
if (grouper == null) { if (grouper == null) {
try { try {
Evaluable eval = MetaParser.parse(facetExpression); Evaluable eval = MetaParser.parse(facetExpression);
Engine engine = new Engine(project); Engine engine = new Engine(project);
grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex()); grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex());
engine.getAllRows().accept(project, grouper); engine.getAllRows().accept(project, grouper);
column.setPrecompute(key, grouper); column.setPrecompute(key, grouper);
} catch (ParsingException e) { } catch (ParsingException e) {
return new EvalError("Error parsing facet expression " + facetExpression); return new EvalError("Error parsing facet expression " + facetExpression);
} }
} }
return grouper.getChoiceValueCountMultiple(choiceValue); return grouper.getChoiceValueCountMultiple(choiceValue);
} }
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
" expects a choice value, an expression as a string, and a column name"); " expects a choice value, an expression as a string, and a column name");
} }
@Override @Override

View File

@ -49,15 +49,15 @@ public class Jsonize implements Function {
@Override @Override
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
if (args.length >= 1) { if (args.length >= 1) {
try { try {
Object o1 = args[0]; Object o1 = args[0];
if (o1 == null) { if (o1 == null) {
return "null"; return "null";
} else if (o1 instanceof Number) { } else if (o1 instanceof Number) {
return JSONObject.numberToString((Number) o1); return JSONObject.numberToString((Number) o1);
} else if (o1 instanceof Boolean) { } else if (o1 instanceof Boolean) {
return o1.toString(); return o1.toString();
} else if (o1 instanceof JSONObject) { } else if (o1 instanceof JSONObject) {
return ((JSONObject) o1).toString(); return ((JSONObject) o1).toString();
} else if (o1 instanceof JSONArray) { } else if (o1 instanceof JSONArray) {
return ((JSONArray) o1).toString(); return ((JSONArray) o1).toString();
@ -67,12 +67,12 @@ public class Jsonize implements Function {
return new JSONArray((Collection<?>) o1).toString(); return new JSONArray((Collection<?>) o1).toString();
} else if (o1.getClass().isArray()) { } else if (o1.getClass().isArray()) {
return new JSONArray(o1).toString(); return new JSONArray(o1).toString();
} else { } else {
return JSONObject.quote(o1.toString()); return JSONObject.quote(o1.toString());
} }
} catch (JSONException e) { } catch (JSONException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
return null; return null;
} }

View File

@ -44,7 +44,7 @@ public class ArgsToArray implements Function {
@Override @Override
public Object call(Properties bindings, Object[] args) { public Object call(Properties bindings, Object[] args) {
return args; return args;
} }
@Override @Override

View File

@ -232,7 +232,7 @@ public class ControlFunctionRegistry {
registerFunction("htmlAttr", new HtmlAttr()); registerFunction("htmlAttr", new HtmlAttr());
registerFunction("htmlText", new HtmlText()); registerFunction("htmlText", new HtmlText());
registerFunction("innerHtml", new InnerHtml()); registerFunction("innerHtml", new InnerHtml());
registerFunction("ownText", new OwnText()); registerFunction("ownText", new OwnText());
registerFunction("indexOf", new IndexOf()); registerFunction("indexOf", new IndexOf());
registerFunction("lastIndexOf", new LastIndexOf()); registerFunction("lastIndexOf", new LastIndexOf());

View File

@ -238,7 +238,7 @@ public class Parser {
throw makeException("Missing )"); throw makeException("Missing )");
} }
} else if (_token.type == TokenType.Delimiter && _token.text.equals("[")) { // [ ... ] array } else if (_token.type == TokenType.Delimiter && _token.text.equals("[")) { // [ ... ] array
next(true); // swallow [ next(true); // swallow [
List<Evaluable> args = parseExpressionList("]"); List<Evaluable> args = parseExpressionList("]");

View File

@ -117,7 +117,7 @@ public class Filter implements Control {
Object r = args[2].evaluate(bindings); Object r = args[2].evaluate(bindings);
if (r instanceof Boolean && ((Boolean) r).booleanValue()) { if (r instanceof Boolean && ((Boolean) r).booleanValue()) {
results.add(v); results.add(v);
} }
} }
} }

View File

@ -120,9 +120,9 @@ public class ForEachIndex implements Control {
results = new ArrayList<Object>(list.size()); results = new ArrayList<Object>(list.size());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Object v = list.get(i); Object v = list.get(i);
bindings.put(indexName, i); bindings.put(indexName, i);
bindings.put(elementName, v); bindings.put(elementName, v);
Object r = args[3].evaluate(bindings); Object r = args[3].evaluate(bindings);

View File

@ -87,7 +87,7 @@ public class ForRange implements Control {
double to = ((Number) toO).doubleValue(); double to = ((Number) toO).doubleValue();
while (from < to) { while (from < to) {
bindings.put(indexName, from); bindings.put(indexName, from);
Object r = args[4].evaluate(bindings); Object r = args[4].evaluate(bindings);
@ -101,7 +101,7 @@ public class ForRange implements Control {
double to = ((Number) toO).doubleValue(); double to = ((Number) toO).doubleValue();
while (from < to) { while (from < to) {
bindings.put(indexName, from); bindings.put(indexName, from);
Object r = args[4].evaluate(bindings); Object r = args[4].evaluate(bindings);
@ -124,13 +124,13 @@ public class ForRange implements Control {
} }
static private boolean isIntegral(Number o) { static private boolean isIntegral(Number o) {
if (o instanceof Integer || o instanceof Long) { if (o instanceof Integer || o instanceof Long) {
return true; return true;
} else { } else {
return (o.doubleValue() - o.longValue()) == 0; return (o.doubleValue() - o.longValue()) == 0;
} }
} }
@Override @Override
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {

View File

@ -34,25 +34,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.model; package com.google.refine.model;
public class ModelException extends Exception { public class ModelException extends Exception {
private static final long serialVersionUID = -168448967638065467L; private static final long serialVersionUID = -168448967638065467L;
public ModelException() { public ModelException() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public ModelException(String message) { public ModelException(String message) {
super(message); super(message);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public ModelException(Throwable cause) { public ModelException(Throwable cause) {
super(cause); super(cause);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public ModelException(String message, Throwable cause) { public ModelException(String message, Throwable cause) {
super(message, cause); super(message, cause);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
} }

View File

@ -34,17 +34,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.model; package com.google.refine.model;
public class Record { public class Record {
final public int fromRowIndex; final public int fromRowIndex;
final public int toRowIndex; final public int toRowIndex;
final public int recordIndex; final public int recordIndex;
public Record( public Record(
int fromRowIndex, int fromRowIndex,
int toRowIndex, int toRowIndex,
int recordIndex int recordIndex
) { ) {
this.fromRowIndex = fromRowIndex; this.fromRowIndex = fromRowIndex;
this.toRowIndex = toRowIndex; this.toRowIndex = toRowIndex;
this.recordIndex = recordIndex; this.recordIndex = recordIndex;
} }
} }

View File

@ -55,7 +55,7 @@ public class RecordModel implements Jsonizable {
this.cellIndex = cellIndex; this.cellIndex = cellIndex;
} }
} }
final static public class RowDependency { final static public class RowDependency {
public int recordIndex; public int recordIndex;
public CellDependency[] cellDependencies; public CellDependency[] cellDependencies;

View File

@ -161,12 +161,12 @@ public class Row implements HasFields, Jsonizable {
if (!"save".equals(options.getProperty("mode"))) { if (!"save".equals(options.getProperty("mode"))) {
if (options.containsKey("rowIndex")) { if (options.containsKey("rowIndex")) {
int rowIndex = (Integer) options.get("rowIndex"); int rowIndex = (Integer) options.get("rowIndex");
writer.key("i"); writer.value(rowIndex); writer.key("i"); writer.value(rowIndex);
if (options.containsKey("recordIndex")) { if (options.containsKey("recordIndex")) {
int recordIndex = (Integer) options.get("recordIndex"); int recordIndex = (Integer) options.get("recordIndex");
writer.key("j"); writer.value(recordIndex); writer.key("j"); writer.value(recordIndex);
} }
} }

View File

@ -55,15 +55,15 @@ public class RowReorderChange implements Change {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
synchronized (project) { synchronized (project) {
List<Row> oldRows = project.rows; List<Row> oldRows = project.rows;
List<Row> newRows = new ArrayList<Row>(oldRows.size()); List<Row> newRows = new ArrayList<Row>(oldRows.size());
for (Integer oldIndex : _rowIndices) { for (Integer oldIndex : _rowIndices) {
newRows.add(oldRows.get(oldIndex)); newRows.add(oldRows.get(oldIndex));
} }
project.rows.clear(); project.rows.clear();
project.rows.addAll(newRows); project.rows.addAll(newRows);
project.update(); project.update();
} }
} }
@ -71,23 +71,23 @@ public class RowReorderChange implements Change {
@Override @Override
public void revert(Project project) { public void revert(Project project) {
synchronized (project) { synchronized (project) {
int count = project.rows.size(); int count = project.rows.size();
List<Row> newRows = project.rows; List<Row> newRows = project.rows;
List<Row> oldRows = new ArrayList<Row>(count); List<Row> oldRows = new ArrayList<Row>(count);
for (int r = 0; r < count; r++) { for (int r = 0; r < count; r++) {
oldRows.add(null); oldRows.add(null);
} }
for (int newIndex = 0; newIndex < count; newIndex++) { for (int newIndex = 0; newIndex < count; newIndex++) {
int oldIndex = _rowIndices.get(newIndex); int oldIndex = _rowIndices.get(newIndex);
Row row = newRows.get(newIndex); Row row = newRows.get(newIndex);
oldRows.set(oldIndex, row); oldRows.set(oldIndex, row);
} }
project.rows.clear(); project.rows.clear();
project.rows.addAll(oldRows); project.rows.addAll(oldRows);
project.update(); project.update();
} }
} }

View File

@ -108,15 +108,15 @@ public class BlankDownOperation extends EngineDependentMassCellOperation {
this.cellChanges = cellChanges; this.cellChanges = cellChanges;
return this; return this;
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -111,12 +111,12 @@ public class FillDownOperation extends EngineDependentMassCellOperation {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -238,12 +238,12 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -161,29 +161,29 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
Cell newCell = null; Cell newCell = null;
Object oldValue = cell != null ? cell.value : null; Object oldValue = cell != null ? cell.value : null;
ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell);
Object o = eval.evaluate(bindings); Object o = eval.evaluate(bindings);
if (o == null) { if (o == null) {
if (oldValue != null) { if (oldValue != null) {
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, null); CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, null);
cellChanges.add(cellChange); cellChanges.add(cellChange);
} }
} else { } else {
if (o instanceof Cell) { if (o instanceof Cell) {
newCell = (Cell) o; newCell = (Cell) o;

View File

@ -180,12 +180,12 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -277,12 +277,12 @@ public class ColumnSplitOperation extends EngineDependentOperation {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -122,12 +122,12 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -125,12 +125,12 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -116,14 +116,14 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
if (cellIndex < row.cells.size()) { if (cellIndex < row.cells.size()) {

View File

@ -161,14 +161,14 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);

View File

@ -222,12 +222,12 @@ public class ReconOperation extends EngineDependentOperation {
filteredRows.accept(_project, new RowVisitor() { filteredRows.accept(_project, new RowVisitor() {
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -87,20 +87,20 @@ public void write(JSONWriter writer, Properties options)
RowDependency rd = project.recordModel.getRowDependency(r); RowDependency rd = project.recordModel.getRowDependency(r);
if (rd.cellDependencies != null) { if (rd.cellDependencies != null) {
newRow = oldRow.dup(); newRow = oldRow.dup();
for (int c = 0; c < rd.cellDependencies.length; c++) { for (int c = 0; c < rd.cellDependencies.length; c++) {
CellDependency cd = rd.cellDependencies[c]; CellDependency cd = rd.cellDependencies[c];
if (cd != null) { if (cd != null) {
int contextRowIndex = cd.rowIndex; int contextRowIndex = cd.rowIndex;
int contextCellIndex = cd.cellIndex; int contextCellIndex = cd.cellIndex;
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) { if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
Row contextRow = oldRows.get(contextRowIndex); Row contextRow = oldRows.get(contextRowIndex);
Cell contextCell = contextRow.getCell(contextCellIndex); Cell contextCell = contextRow.getCell(contextCellIndex);
newRow.setCell(contextCellIndex, contextCell); newRow.setCell(contextCellIndex, contextCell);
} }
} }
} }
} }

View File

@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -107,17 +107,17 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
this.rowIndices = rowIndices; this.rowIndices = rowIndices;
return this; return this;
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
rowIndices.add(rowIndex); rowIndices.add(rowIndex);

View File

@ -57,18 +57,18 @@ import com.google.refine.sorting.SortingRowVisitor;
public class RowReorderOperation extends AbstractOperation { public class RowReorderOperation extends AbstractOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
String mode = obj.getString("mode"); String mode = obj.getString("mode");
JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ? JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ?
obj.getJSONObject("sorting") : null; obj.getJSONObject("sorting") : null;
return new RowReorderOperation(Engine.stringToMode(mode), sorting); return new RowReorderOperation(Engine.stringToMode(mode), sorting);
} }
final protected Mode _mode; final protected Mode _mode;
final protected JSONObject _sorting; final protected JSONObject _sorting;
public RowReorderOperation(Mode mode, JSONObject sorting) { public RowReorderOperation(Mode mode, JSONObject sorting) {
_mode = mode; _mode = mode;
_sorting = sorting; _sorting = sorting;
} }
@ -98,65 +98,65 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
if (_mode == Mode.RowBased) { if (_mode == Mode.RowBased) {
RowVisitor visitor = new IndexingVisitor(rowIndices); RowVisitor visitor = new IndexingVisitor(rowIndices);
if (_sorting != null) { if (_sorting != null) {
SortingRowVisitor srv = new SortingRowVisitor(visitor); SortingRowVisitor srv = new SortingRowVisitor(visitor);
srv.initializeFromJSON(project, _sorting); srv.initializeFromJSON(project, _sorting);
if (srv.hasCriteria()) { if (srv.hasCriteria()) {
visitor = srv; visitor = srv;
} }
} }
engine.getAllRows().accept(project, visitor); engine.getAllRows().accept(project, visitor);
} else { } else {
RecordVisitor visitor = new IndexingVisitor(rowIndices); RecordVisitor visitor = new IndexingVisitor(rowIndices);
if (_sorting != null) { if (_sorting != null) {
SortingRecordVisitor srv = new SortingRecordVisitor(visitor); SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
srv.initializeFromJSON(project, _sorting); srv.initializeFromJSON(project, _sorting);
if (srv.hasCriteria()) { if (srv.hasCriteria()) {
visitor = srv; visitor = srv;
} }
} }
engine.getAllRecords().accept(project, visitor); engine.getAllRecords().accept(project, visitor);
} }
return new HistoryEntry( return new HistoryEntry(
historyEntryID, historyEntryID,
project, project,
"Reorder rows", "Reorder rows",
this, this,
new RowReorderChange(rowIndices) new RowReorderChange(rowIndices)
); );
} }
static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
List<Integer> _indices;
IndexingVisitor(List<Integer> indices) {
_indices = indices;
}
@Override
public void start(Project project) {
}
@Override static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
public void end(Project project) { List<Integer> _indices;
}
@Override IndexingVisitor(List<Integer> indices) {
public boolean visit(Project project, int rowIndex, Row row) { _indices = indices;
_indices.add(rowIndex); }
return false;
}
@Override @Override
public boolean visit(Project project, Record record) { public void start(Project project) {
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { }
_indices.add(r);
} @Override
return false; public void end(Project project) {
} }
}
@Override
public boolean visit(Project project, int rowIndex, Row row) {
_indices.add(rowIndex);
return false;
}
@Override
public boolean visit(Project project, Record record) {
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
_indices.add(r);
}
return false;
}
}
} }

View File

@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID)
@Override @Override
public void start(Project project) { public void start(Project project) {
// nothing to do // nothing to do
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
// nothing to do // nothing to do
} }
@Override @Override

View File

@ -44,130 +44,130 @@ import com.google.refine.model.Project;
import com.google.refine.sorting.Criterion.KeyMaker; import com.google.refine.sorting.Criterion.KeyMaker;
abstract public class BaseSorter { abstract public class BaseSorter {
protected Criterion[] _criteria; protected Criterion[] _criteria;
protected KeyMaker[] _keyMakers; protected KeyMaker[] _keyMakers;
protected ComparatorWrapper[] _comparatorWrappers; protected ComparatorWrapper[] _comparatorWrappers;
protected List<Object[]> _keys; protected List<Object[]> _keys;
public class ComparatorWrapper { public class ComparatorWrapper {
final public int criterionIndex; final public int criterionIndex;
final protected int multiplier; final protected int multiplier;
public ComparatorWrapper(int criterionIndex) { public ComparatorWrapper(int criterionIndex) {
this.criterionIndex = criterionIndex; this.criterionIndex = criterionIndex;
this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1; this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1;
} }
public Object getKey(Project project, Object o, int index) { public Object getKey(Project project, Object o, int index) {
while (index >= _keys.size()) { while (index >= _keys.size()) {
_keys.add(null); _keys.add(null);
} }
Object[] keys = _keys.get(index); Object[] keys = _keys.get(index);
if (keys == null) { if (keys == null) {
keys = makeKeys(project, o, index); keys = makeKeys(project, o, index);
_keys.set(index, keys); _keys.set(index, keys);
} }
return keys[criterionIndex]; return keys[criterionIndex];
} }
public int compare(Project project, Object o1, int i1, Object o2, int i2) { public int compare(Project project, Object o1, int i1, Object o2, int i2) {
Criterion c = _criteria[criterionIndex]; Criterion c = _criteria[criterionIndex];
Object key1 = getKey(project, o1, i1); Object key1 = getKey(project, o1, i1);
Object key2 = getKey(project, o2, i2); Object key2 = getKey(project, o2, i2);
if (key1 == null) { if (key1 == null) {
if (key2 == null) { if (key2 == null) {
return 0; return 0;
} else if (key2 instanceof EvalError) { } else if (key2 instanceof EvalError) {
return c.blankPosition - c.errorPosition; return c.blankPosition - c.errorPosition;
} else { } else {
return c.blankPosition; return c.blankPosition;
} }
} else if (key1 instanceof EvalError) { } else if (key1 instanceof EvalError) {
if (key2 == null) { if (key2 == null) {
return c.errorPosition - c.blankPosition; return c.errorPosition - c.blankPosition;
} else if (key2 instanceof EvalError) { } else if (key2 instanceof EvalError) {
return 0; return 0;
} else { } else {
return c.errorPosition; return c.errorPosition;
} }
} else { } else {
if (key2 == null) { if (key2 == null) {
return -c.blankPosition; return -c.blankPosition;
} else if (key2 instanceof EvalError) { } else if (key2 instanceof EvalError) {
return -c.errorPosition; return -c.errorPosition;
} else { } else {
return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier; return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier;
} }
} }
} }
} }
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
if (obj.has("criteria") && !obj.isNull("criteria")) { if (obj.has("criteria") && !obj.isNull("criteria")) {
JSONArray a = obj.getJSONArray("criteria"); JSONArray a = obj.getJSONArray("criteria");
int count = a.length(); int count = a.length();
_criteria = new Criterion[count]; _criteria = new Criterion[count];
_keyMakers = new KeyMaker[count]; _keyMakers = new KeyMaker[count];
_comparatorWrappers = new ComparatorWrapper[count]; _comparatorWrappers = new ComparatorWrapper[count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject obj2 = a.getJSONObject(i); JSONObject obj2 = a.getJSONObject(i);
_criteria[i] = createCriterionFromJSON(project, obj2); _criteria[i] = createCriterionFromJSON(project, obj2);
_keyMakers[i] = _criteria[i].createKeyMaker(); _keyMakers[i] = _criteria[i].createKeyMaker();
_comparatorWrappers[i] = new ComparatorWrapper(i); _comparatorWrappers[i] = new ComparatorWrapper(i);
} }
} else { } else {
_criteria = new Criterion[0]; _criteria = new Criterion[0];
_keyMakers = new KeyMaker[0]; _keyMakers = new KeyMaker[0];
_comparatorWrappers = new ComparatorWrapper[0]; _comparatorWrappers = new ComparatorWrapper[0];
} }
} }
public boolean hasCriteria() { public boolean hasCriteria() {
return _criteria != null && _criteria.length > 0; return _criteria != null && _criteria.length > 0;
} }
protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException { protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException {
String valueType = "string"; String valueType = "string";
if (obj.has("valueType") && !obj.isNull("valueType")) { if (obj.has("valueType") && !obj.isNull("valueType")) {
valueType = obj.getString("valueType"); valueType = obj.getString("valueType");
} }
Criterion c = null; Criterion c = null;
if ("boolean".equals(valueType)) { if ("boolean".equals(valueType)) {
c = new BooleanCriterion(); c = new BooleanCriterion();
} else if ("date".equals(valueType)) { } else if ("date".equals(valueType)) {
c = new DateCriterion(); c = new DateCriterion();
} else if ("number".equals(valueType)) { } else if ("number".equals(valueType)) {
c = new NumberCriterion(); c = new NumberCriterion();
} else { } else {
c = new StringCriterion(); c = new StringCriterion();
} }
c.initializeFromJSON(project, obj); c.initializeFromJSON(project, obj);
return c; return c;
} }
abstract protected Object makeKey( abstract protected Object makeKey(
Project project, KeyMaker keyMaker, Criterion c, Object o, int index); Project project, KeyMaker keyMaker, Criterion c, Object o, int index);
protected Object[] makeKeys(Project project, Object o, int index) { protected Object[] makeKeys(Project project, Object o, int index) {
Object[] keys = new Object[_keyMakers.length]; Object[] keys = new Object[_keyMakers.length];
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index); keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index);
} }
return keys; return keys;
} }
protected int compare(Project project, Object o1, int i1, Object o2, int i2) { protected int compare(Project project, Object o1, int i1, Object o2, int i2) {
int c = 0; int c = 0;
for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) { for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) {
c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2); c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2);
} }
return c; return c;
} }
} }

View File

@ -44,55 +44,55 @@ import com.google.refine.model.Record;
import com.google.refine.sorting.Criterion.KeyMaker; import com.google.refine.sorting.Criterion.KeyMaker;
public class SortingRecordVisitor extends BaseSorter implements RecordVisitor { public class SortingRecordVisitor extends BaseSorter implements RecordVisitor {
final protected RecordVisitor _visitor; final protected RecordVisitor _visitor;
protected List<Record> _records; protected List<Record> _records;
public SortingRecordVisitor(RecordVisitor visitor) {
_visitor = visitor;
}
@Override public SortingRecordVisitor(RecordVisitor visitor) {
public void start(Project project) { _visitor = visitor;
int count = project.recordModel.getRecordCount(); }
_records = new ArrayList<Record>(count);
_keys = new ArrayList<Object[]>(count);
}
@Override @Override
public void end(Project project) { public void start(Project project) {
_visitor.start(project); int count = project.recordModel.getRecordCount();
_records = new ArrayList<Record>(count);
Collections.sort(_records, new Comparator<Record>() { _keys = new ArrayList<Object[]>(count);
Project project; }
Comparator<Record> init(Project project) {
this.project = project;
return this;
}
@Override
public int compare(Record o1, Record o2) {
return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex);
}
}.init(project));
for (Record record : _records) {
_visitor.visit(project, record);
}
_visitor.end(project);
}
@Override @Override
public boolean visit(Project project, Record record) { public void end(Project project) {
_records.add(record); _visitor.start(project);
return false;
}
@Override Collections.sort(_records, new Comparator<Record>() {
protected Object makeKey( Project project;
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
Comparator<Record> init(Project project) {
return keyMaker.makeKey(project, (Record) o); this.project = project;
} return this;
}
@Override
public int compare(Record o1, Record o2) {
return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex);
}
}.init(project));
for (Record record : _records) {
_visitor.visit(project, record);
}
_visitor.end(project);
}
@Override
public boolean visit(Project project, Record record) {
_records.add(record);
return false;
}
@Override
protected Object makeKey(
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
return keyMaker.makeKey(project, (Record) o);
}
} }

View File

@ -44,65 +44,65 @@ import com.google.refine.model.Row;
import com.google.refine.sorting.Criterion.KeyMaker; import com.google.refine.sorting.Criterion.KeyMaker;
public class SortingRowVisitor extends BaseSorter implements RowVisitor { public class SortingRowVisitor extends BaseSorter implements RowVisitor {
final protected RowVisitor _visitor; final protected RowVisitor _visitor;
protected List<IndexedRow> _indexedRows; protected List<IndexedRow> _indexedRows;
static protected class IndexedRow {
final int index;
final Row row;
IndexedRow(int index, Row row) {
this.index = index;
this.row = row;
}
}
public SortingRowVisitor(RowVisitor visitor) {
_visitor = visitor;
}
@Override static protected class IndexedRow {
public void start(Project project) { final int index;
int count = project.rows.size(); final Row row;
_indexedRows = new ArrayList<IndexedRow>(count);
_keys = new ArrayList<Object[]>(count);
}
@Override IndexedRow(int index, Row row) {
public void end(Project project) { this.index = index;
_visitor.start(project); this.row = row;
}
Collections.sort(_indexedRows, new Comparator<IndexedRow>() { }
Project project;
Comparator<IndexedRow> init(Project project) {
this.project = project;
return this;
}
@Override
public int compare(IndexedRow o1, IndexedRow o2) {
return SortingRowVisitor.this.compare(project, o1.row, o1.index, o2.row, o2.index);
}
}.init(project));
for (IndexedRow indexedRow : _indexedRows) {
_visitor.visit(project, indexedRow.index, indexedRow.row);
}
_visitor.end(project);
}
@Override public SortingRowVisitor(RowVisitor visitor) {
public boolean visit(Project project, int rowIndex, Row row) { _visitor = visitor;
_indexedRows.add(new IndexedRow(rowIndex, row)); }
return false;
}
@Override @Override
protected Object makeKey( public void start(Project project) {
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { int count = project.rows.size();
_indexedRows = new ArrayList<IndexedRow>(count);
return keyMaker.makeKey(project, (Row) o, index); _keys = new ArrayList<Object[]>(count);
} }
@Override
public void end(Project project) {
_visitor.start(project);
Collections.sort(_indexedRows, new Comparator<IndexedRow>() {
Project project;
Comparator<IndexedRow> init(Project project) {
this.project = project;
return this;
}
@Override
public int compare(IndexedRow o1, IndexedRow o2) {
return SortingRowVisitor.this.compare(project, o1.row, o1.index, o2.row, o2.index);
}
}.init(project));
for (IndexedRow indexedRow : _indexedRows) {
_visitor.visit(project, indexedRow.index, indexedRow.row);
}
_visitor.end(project);
}
@Override
public boolean visit(Project project, int rowIndex, Row row) {
_indexedRows.add(new IndexedRow(rowIndex, row));
return false;
}
@Override
protected Object makeKey(
Project project, KeyMaker keyMaker, Criterion c, Object o, int index) {
return keyMaker.makeKey(project, (Row) o, index);
}
} }

View File

@ -36,9 +36,9 @@ package com.google.refine.templating;
import com.google.refine.expr.Evaluable; import com.google.refine.expr.Evaluable;
class DynamicFragment extends Fragment { class DynamicFragment extends Fragment {
final public Evaluable eval; final public Evaluable eval;
public DynamicFragment(Evaluable eval) { public DynamicFragment(Evaluable eval) {
this.eval = eval; this.eval = eval;
} }
} }

View File

@ -42,63 +42,63 @@ import com.google.refine.grel.ast.FieldAccessorExpr;
import com.google.refine.grel.ast.VariableExpr; import com.google.refine.grel.ast.VariableExpr;
public class Parser { public class Parser {
static public Template parse(String s) throws ParsingException { static public Template parse(String s) throws ParsingException {
List<Fragment> fragments = new ArrayList<Fragment>(); List<Fragment> fragments = new ArrayList<Fragment>();
int start = 0, current = 0;
while (current < s.length() - 1) {
char c = s.charAt(current);
if (c == '\\') {
current += 2;
continue;
}
char c2 = s.charAt(current + 1);
if (c == '$' && c2 == '{') {
int closeBrace = s.indexOf('}', current + 2);
if (closeBrace > current + 1) {
String columnName = s.substring(current + 2, closeBrace);
if (current > start) {
fragments.add(new StaticFragment(s.substring(start, current)));
}
start = current = closeBrace + 1;
fragments.add(
new DynamicFragment(
new FieldAccessorExpr(
new FieldAccessorExpr(
new VariableExpr("cells"),
columnName),
"value")));
continue;
}
} else if (c == '{' && c2 == '{') {
int closeBrace = s.indexOf('}', current + 2);
if (closeBrace > current + 1 && closeBrace < s.length() - 1 && s.charAt(closeBrace + 1) == '}') {
String expression = s.substring(current + 2, closeBrace);
if (current > start) {
fragments.add(new StaticFragment(s.substring(start, current)));
}
start = current = closeBrace + 2;
fragments.add(
new DynamicFragment(
MetaParser.parse(expression)));
continue; int start = 0, current = 0;
} while (current < s.length() - 1) {
} char c = s.charAt(current);
if (c == '\\') {
current++; current += 2;
} continue;
}
if (start < s.length()) {
fragments.add(new StaticFragment(s.substring(start))); char c2 = s.charAt(current + 1);
} if (c == '$' && c2 == '{') {
int closeBrace = s.indexOf('}', current + 2);
return new Template(fragments); if (closeBrace > current + 1) {
} String columnName = s.substring(current + 2, closeBrace);
if (current > start) {
fragments.add(new StaticFragment(s.substring(start, current)));
}
start = current = closeBrace + 1;
fragments.add(
new DynamicFragment(
new FieldAccessorExpr(
new FieldAccessorExpr(
new VariableExpr("cells"),
columnName),
"value")));
continue;
}
} else if (c == '{' && c2 == '{') {
int closeBrace = s.indexOf('}', current + 2);
if (closeBrace > current + 1 && closeBrace < s.length() - 1 && s.charAt(closeBrace + 1) == '}') {
String expression = s.substring(current + 2, closeBrace);
if (current > start) {
fragments.add(new StaticFragment(s.substring(start, current)));
}
start = current = closeBrace + 2;
fragments.add(
new DynamicFragment(
MetaParser.parse(expression)));
continue;
}
}
current++;
}
if (start < s.length()) {
fragments.add(new StaticFragment(s.substring(start)));
}
return new Template(fragments);
}
} }

View File

@ -34,9 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.templating; package com.google.refine.templating;
class StaticFragment extends Fragment { class StaticFragment extends Fragment {
final public String text; final public String text;
public StaticFragment(String text) { public StaticFragment(String text) {
this.text = text; this.text = text;
} }
} }

View File

@ -47,160 +47,160 @@ import com.google.refine.model.Record;
import com.google.refine.model.Row; import com.google.refine.model.Row;
public class Template { public class Template {
protected String _prefix; protected String _prefix;
protected String _suffix; protected String _suffix;
protected String _separator; protected String _separator;
protected List<Fragment> _fragments; protected List<Fragment> _fragments;
public Template(List<Fragment> fragments) { public Template(List<Fragment> fragments) {
_fragments = fragments; _fragments = fragments;
} }
public void setPrefix(String prefix) { public void setPrefix(String prefix) {
_prefix = prefix; _prefix = prefix;
} }
public void setSuffix(String suffix) { public void setSuffix(String suffix) {
_suffix = suffix; _suffix = suffix;
} }
public void setSeparator(String separator) { public void setSeparator(String separator) {
_separator = separator; _separator = separator;
} }
public RowVisitor getRowVisitor(Writer writer, int limit) { public RowVisitor getRowVisitor(Writer writer, int limit) {
return get(writer, limit); return get(writer, limit);
} }
public RecordVisitor getRecordVisitor(Writer writer, int limit) { public RecordVisitor getRecordVisitor(Writer writer, int limit) {
return get(writer, limit); return get(writer, limit);
} }
protected RowWritingVisitor get(Writer writer, int limit) { protected RowWritingVisitor get(Writer writer, int limit) {
return new RowWritingVisitor(writer, limit); return new RowWritingVisitor(writer, limit);
} }
protected class RowWritingVisitor implements RowVisitor, RecordVisitor { protected class RowWritingVisitor implements RowVisitor, RecordVisitor {
final protected int limit; final protected int limit;
final protected Writer writer; final protected Writer writer;
protected Properties bindings; protected Properties bindings;
public int total; public int total;
public RowWritingVisitor(Writer writer, int limit) { public RowWritingVisitor(Writer writer, int limit) {
this.limit = limit; this.limit = limit;
this.writer = writer; this.writer = writer;
} }
@Override @Override
public void start(Project project) { public void start(Project project) {
bindings = ExpressionUtils.createBindings(project); bindings = ExpressionUtils.createBindings(project);
try { try {
if (_prefix != null) { if (_prefix != null) {
writer.write(_prefix); writer.write(_prefix);
} }
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
} }
@Override @Override
public void end(Project project) { public void end(Project project) {
try { try {
if (_suffix != null) { if (_suffix != null) {
writer.write(_suffix); writer.write(_suffix);
} }
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
} }
@Override @Override
public boolean visit(Project project, int rowIndex, Row row) { public boolean visit(Project project, int rowIndex, Row row) {
if (limit <= 0 || total < limit) { if (limit <= 0 || total < limit) {
internalVisit(project, rowIndex, row); internalVisit(project, rowIndex, row);
} }
total++; total++;
return limit > 0 && total >= limit; return limit > 0 && total >= limit;
} }
@Override @Override
public boolean visit(Project project, Record record) { public boolean visit(Project project, Record record) {
if (limit <= 0 || total < limit) { if (limit <= 0 || total < limit) {
internalVisit(project, record); internalVisit(project, record);
} }
total++; total++;
return limit > 0 && total >= limit; return limit > 0 && total >= limit;
} }
protected void writeValue(Object v) throws IOException { protected void writeValue(Object v) throws IOException {
if (v == null) { if (v == null) {
writer.write("null"); writer.write("null");
} else if (ExpressionUtils.isError(v)) { } else if (ExpressionUtils.isError(v)) {
writer.write("null"); writer.write("null");
//writer.write("[Error: " + ((EvalError) v).message); //writer.write("[Error: " + ((EvalError) v).message);
} else if (v instanceof String) { } else if (v instanceof String) {
writer.write((String) v); writer.write((String) v);
} else { } else {
writer.write(v.toString()); writer.write(v.toString());
} }
} }
public boolean internalVisit(Project project, int rowIndex, Row row) { public boolean internalVisit(Project project, int rowIndex, Row row) {
try { try {
if (total > 0 && _separator != null) { if (total > 0 && _separator != null) {
writer.write(_separator); writer.write(_separator);
} }
ExpressionUtils.bind(bindings, row, rowIndex, null, null); ExpressionUtils.bind(bindings, row, rowIndex, null, null);
for (Fragment f : _fragments) { for (Fragment f : _fragments) {
if (f instanceof StaticFragment) { if (f instanceof StaticFragment) {
writer.write(((StaticFragment) f).text); writer.write(((StaticFragment) f).text);
} else { } else {
DynamicFragment df = (DynamicFragment) f; DynamicFragment df = (DynamicFragment) f;
Object value = df.eval.evaluate(bindings); Object value = df.eval.evaluate(bindings);
if (value != null && ExpressionUtils.isArrayOrCollection(value)) { if (value != null && ExpressionUtils.isArrayOrCollection(value)) {
if (ExpressionUtils.isArray(value)) { if (ExpressionUtils.isArray(value)) {
Object[] a = (Object[]) value; Object[] a = (Object[]) value;
for (Object v : a) { for (Object v : a) {
writeValue(v); writeValue(v);
} }
} else { } else {
Collection<Object> a = ExpressionUtils.toObjectCollection(value); Collection<Object> a = ExpressionUtils.toObjectCollection(value);
for (Object v : a) { for (Object v : a) {
writeValue(v); writeValue(v);
} }
} }
continue; continue;
} }
writeValue(value); writeValue(value);
} }
} }
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
return false; return false;
} }
protected boolean internalVisit(Project project, Record record) { protected boolean internalVisit(Project project, Record record) {
bindings.put("recordIndex", record.recordIndex); bindings.put("recordIndex", record.recordIndex);
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
Row row = project.rows.get(r); Row row = project.rows.get(r);
bindings.put("rowIndex", r); bindings.put("rowIndex", r);
internalVisit(project, r, row); internalVisit(project, r, row);
bindings.remove("recordIndex"); bindings.remove("recordIndex");
} }
return false; return false;
} }
} }

View File

@ -117,16 +117,16 @@ public class HtmlExporterTests extends RefineTest {
} }
Assert.assertEquals(writer.toString(), "<html>\n" + Assert.assertEquals(writer.toString(), "<html>\n" +
"<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" + "<head><title>" + TEST_PROJECT_NAME + "</title></head>\n" +
"<body>\n" + "<body>\n" +
"<table>\n" + "<table>\n" +
"<tr><th>column0</th><th>column1</th></tr>\n" + "<tr><th>column0</th><th>column1</th></tr>\n" +
"<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" + "<tr><td>row0cell0</td><td>row0cell1</td></tr>\n" +
"<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" + "<tr><td>row1cell0</td><td>row1cell1</td></tr>\n" +
"</table>\n" + "</table>\n" +
"</body>\n" + "</body>\n" +
"</html>\n"); "</html>\n");
} }
// TODO: This test fails because the HTML table exporter // TODO: This test fails because the HTML table exporter

View File

@ -51,7 +51,7 @@ import com.google.refine.importers.tree.TreeReader.Token;
import com.google.refine.model.Row; import com.google.refine.model.Row;
public class JsonImporterTests extends ImporterTest { public class JsonImporterTests extends ImporterTest {
@Override @Override
@BeforeTest @BeforeTest
public void init() { public void init() {
logger = LoggerFactory.getLogger(this.getClass()); logger = LoggerFactory.getLogger(this.getClass());
@ -270,8 +270,9 @@ public class JsonImporterTests extends ImporterTest {
sb.append("["); sb.append("[");
for(int i = 1; i < 7; i++){ for(int i = 1; i < 7; i++){
sb.append(getTypicalElement(i)); sb.append(getTypicalElement(i));
if(i < 6) if(i < 6) {
sb.append(","); sb.append(",");
}
} }
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
@ -282,12 +283,12 @@ public class JsonImporterTests extends ImporterTest {
sb.append("["); sb.append("[");
for(int i = 1; i < 7; i++){ for(int i = 1; i < 7; i++){
sb.append(getElementWithDuplicateSubElement(i)); sb.append(getElementWithDuplicateSubElement(i));
if(i < 6) if(i < 6) {
sb.append(","); sb.append(",");
}
} }
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} }
public static String getSampleWithLineBreak(){ public static String getSampleWithLineBreak(){
@ -336,8 +337,9 @@ public class JsonImporterTests extends ImporterTest {
"\"title\" : \"Book title " + i + "\"," + "\"title\" : \"Book title " + i + "\"," +
"\"publish_date\" : \"2010-05-26\"" + "\"publish_date\" : \"2010-05-26\"" +
"}"); "}");
if(i < 6) if(i < 6) {
sb.append(","); sb.append(",");
}
} }
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();