diff --git a/broker/appengine/src/com/google/refine/broker/AppEngineRefineBrokerImpl.java b/broker/appengine/src/com/google/refine/broker/AppEngineRefineBrokerImpl.java index 3ae7ef319..79e1e3802 100644 --- a/broker/appengine/src/com/google/refine/broker/AppEngineRefineBrokerImpl.java +++ b/broker/appengine/src/com/google/refine/broker/AppEngineRefineBrokerImpl.java @@ -89,11 +89,11 @@ public class AppEngineRefineBrokerImpl extends RefineBroker { // --------------------------------------------------------------------------------- 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 transformations) throws Exception { - // TODO: implement + // TODO: implement } protected void expireLocks(HttpServletResponse response) throws Exception { @@ -133,7 +133,7 @@ public class AppEngineRefineBrokerImpl extends RefineBroker { PersistenceManager pm = pmfInstance.getPersistenceManager(); try { - // TODO: implement + // TODO: implement respond(response, lockToJSON(getLock(pm,pid))); } finally { 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 { PersistenceManager pm = pmfInstance.getPersistenceManager(); - // TODO: implement + // TODO: implement try { Lock lock = getLock(pm, pid); diff --git a/extensions/freebase/src/com/google/refine/freebase/ProtographTransposeExporter.java b/extensions/freebase/src/com/google/refine/freebase/ProtographTransposeExporter.java index 988ba1a60..495217fcd 100644 --- a/extensions/freebase/src/com/google/refine/freebase/ProtographTransposeExporter.java +++ b/extensions/freebase/src/com/google/refine/freebase/ProtographTransposeExporter.java @@ -48,12 +48,12 @@ import com.google.refine.freebase.protograph.transpose.Transposer; import com.google.refine.freebase.protograph.transpose.TripleLoaderTransposedNodeFactory; abstract public class ProtographTransposeExporter implements WriterExporter { - final protected String _contentType; - - public ProtographTransposeExporter(String contentType) { - _contentType = contentType; - } - + final protected String _contentType; + + public ProtographTransposeExporter(String contentType) { + _contentType = contentType; + } + @Override public String getContentType() { return "application/x-unknown"; @@ -86,25 +86,25 @@ abstract public class ProtographTransposeExporter implements WriterExporter { abstract protected TransposedNodeFactory createNodeFactory(Project project, Writer writer); static public class TripleLoaderExporter extends ProtographTransposeExporter { - public TripleLoaderExporter() { - super("application/x-unknown"); - } + public TripleLoaderExporter() { + super("application/x-unknown"); + } - @Override - protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { - return new TripleLoaderTransposedNodeFactory(project, writer); - } + @Override + protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { + return new TripleLoaderTransposedNodeFactory(project, writer); + } } static public class MqlwriteLikeExporter extends ProtographTransposeExporter { - public MqlwriteLikeExporter() { - super("application/x-unknown"); - } + public MqlwriteLikeExporter() { + super("application/x-unknown"); + } - @Override - protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { - return new MqlwriteLikeTransposedNodeFactory(writer); - } + @Override + protected TransposedNodeFactory createNodeFactory(Project project, Writer writer) { + return new MqlwriteLikeTransposedNodeFactory(writer); + } } } diff --git a/extensions/freebase/src/com/google/refine/freebase/model/changes/DataExtensionChange.java b/extensions/freebase/src/com/google/refine/freebase/model/changes/DataExtensionChange.java index 2c7b09166..8fbc7f58a 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/changes/DataExtensionChange.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/changes/DataExtensionChange.java @@ -208,13 +208,13 @@ public class DataExtensionChange implements Change { column.setReconStats(ReconStats.create(project, cellIndex)); try { - project.columnModel.addColumn(_columnInsertIndex + i, column, true); - - // the column might have been renamed to avoid collision - _columnNames.set(i, column.getName()); - } catch (ModelException e) { - // won't get here since we set the avoid collision flag - } + project.columnModel.addColumn(_columnInsertIndex + i, column, true); + + // the column might have been renamed to avoid collision + _columnNames.set(i, column.getName()); + } catch (ModelException e) { + // won't get here since we set the avoid collision flag + } } project.update(); diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java index 938fdcab5..057356174 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java @@ -137,7 +137,7 @@ public class GuidBasedReconConfig extends StrictReconConfig { jsonWriter.key("guid|="); jsonWriter.array(); for (ReconJob job : jobs) { - jsonWriter.value(((GuidBasedReconJob) job).guid); + jsonWriter.value(((GuidBasedReconJob) job).guid); } jsonWriter.endArray(); @@ -163,37 +163,37 @@ public class GuidBasedReconConfig extends StrictReconConfig { String s = ParsingUtilities.inputStreamToString(is); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); if (o.has("result")) { - JSONArray results = o.getJSONArray("result"); - int count = results.length(); - - for (int i = 0; i < count; i++) { - JSONObject result = results.getJSONObject(i); - - String guid = result.getString("guid"); - - JSONArray types = result.getJSONArray("type"); - String[] typeIDs = new String[types.length()]; - for (int j = 0; j < typeIDs.length; j++) { - typeIDs[j] = types.getString(j); - } - - ReconCandidate candidate = new ReconCandidate( - result.getString("id"), - result.getString("name"), - typeIDs, - 100 - ); - - Recon recon = Recon.makeFreebaseRecon(historyEntryID); - recon.addCandidate(candidate); - recon.service = "mql"; - recon.judgment = Judgment.Matched; - recon.judgmentAction = "auto"; - recon.match = candidate; - recon.matchRank = 0; - - guidToRecon.put(guid, recon); - } + JSONArray results = o.getJSONArray("result"); + int count = results.length(); + + for (int i = 0; i < count; i++) { + JSONObject result = results.getJSONObject(i); + + String guid = result.getString("guid"); + + JSONArray types = result.getJSONArray("type"); + String[] typeIDs = new String[types.length()]; + for (int j = 0; j < typeIDs.length; j++) { + typeIDs[j] = types.getString(j); + } + + ReconCandidate candidate = new ReconCandidate( + result.getString("id"), + result.getString("name"), + typeIDs, + 100 + ); + + Recon recon = Recon.makeFreebaseRecon(historyEntryID); + recon.addCandidate(candidate); + recon.service = "mql"; + recon.judgment = Judgment.Matched; + recon.judgmentAction = "auto"; + recon.match = candidate; + recon.matchRank = 0; + + guidToRecon.put(guid, recon); + } } } finally { is.close(); @@ -206,7 +206,7 @@ public class GuidBasedReconConfig extends StrictReconConfig { String guid = ((GuidBasedReconJob) job).guid; Recon recon = guidToRecon.get(guid); if (recon == null) { - recon = createNoMatchRecon(historyEntryID); + recon = createNoMatchRecon(historyEntryID); } recons.add(recon); } diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java index 2416b3a94..fc2e7ef81 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java @@ -167,50 +167,50 @@ public class IdBasedReconConfig extends StrictReconConfig { String s = ParsingUtilities.inputStreamToString(is); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); if (o.has("result")) { - JSONArray results = o.getJSONArray("result"); - int count = results.length(); - - for (int i = 0; i < count; i++) { - JSONObject result = results.getJSONObject(i); - - String id = result.getString("id"); - - JSONArray types = result.getJSONArray("type"); - String[] typeIDs = new String[types.length()]; - for (int j = 0; j < typeIDs.length; j++) { - typeIDs[j] = types.getString(j); - } - - ReconCandidate candidate = new ReconCandidate( - id, - result.getString("name"), - typeIDs, - 100 - ); - - Recon recon = Recon.makeFreebaseRecon(historyEntryID); - recon.addCandidate(candidate); - recon.service = "mql"; - recon.judgment = Judgment.Matched; - recon.judgmentAction = "auto"; - recon.match = candidate; - recon.matchRank = 0; - - idToRecon.put(id, recon); - } + JSONArray results = o.getJSONArray("result"); + int count = results.length(); + + for (int i = 0; i < count; i++) { + JSONObject result = results.getJSONObject(i); + + String id = result.getString("id"); + + JSONArray types = result.getJSONArray("type"); + String[] typeIDs = new String[types.length()]; + for (int j = 0; j < typeIDs.length; j++) { + typeIDs[j] = types.getString(j); + } + + ReconCandidate candidate = new ReconCandidate( + id, + result.getString("name"), + typeIDs, + 100 + ); + + Recon recon = Recon.makeFreebaseRecon(historyEntryID); + recon.addCandidate(candidate); + recon.service = "mql"; + recon.judgment = Judgment.Matched; + recon.judgmentAction = "auto"; + recon.match = candidate; + recon.matchRank = 0; + + idToRecon.put(id, recon); + } } } finally { - is.close(); + is.close(); } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } - + for (ReconJob job : jobs) { String id = ((IdBasedReconJob) job).id; Recon recon = idToRecon.get(id); if (recon == null) { - recon = createNoMatchRecon(historyEntryID); + recon = createNoMatchRecon(historyEntryID); } recons.add(recon); } diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java index 0fb58de1d..fc67b3e63 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java @@ -181,37 +181,37 @@ public class KeyBasedReconConfig extends StrictReconConfig { String s = ParsingUtilities.inputStreamToString(is); JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s); if (o.has("result")) { - JSONArray results = o.getJSONArray("result"); - int count = results.length(); - - for (int i = 0; i < count; i++) { - JSONObject result = results.getJSONObject(i); - - String key = result.getJSONArray("key").getJSONObject(0).getString("value"); - - JSONArray types = result.getJSONArray("type"); - String[] typeIDs = new String[types.length()]; - for (int j = 0; j < typeIDs.length; j++) { - typeIDs[j] = types.getString(j); - } - - ReconCandidate candidate = new ReconCandidate( - result.getString("id"), - result.getString("name"), - typeIDs, - 100 - ); - - Recon recon = Recon.makeFreebaseRecon(historyEntryID); - recon.addCandidate(candidate); - recon.service = "mql"; - recon.judgment = Judgment.Matched; - recon.judgmentAction = "auto"; - recon.match = candidate; - recon.matchRank = 0; - - keyToRecon.put(key, recon); - } + JSONArray results = o.getJSONArray("result"); + int count = results.length(); + + for (int i = 0; i < count; i++) { + JSONObject result = results.getJSONObject(i); + + String key = result.getJSONArray("key").getJSONObject(0).getString("value"); + + JSONArray types = result.getJSONArray("type"); + String[] typeIDs = new String[types.length()]; + for (int j = 0; j < typeIDs.length; j++) { + typeIDs[j] = types.getString(j); + } + + ReconCandidate candidate = new ReconCandidate( + result.getString("id"), + result.getString("name"), + typeIDs, + 100 + ); + + Recon recon = Recon.makeFreebaseRecon(historyEntryID); + recon.addCandidate(candidate); + recon.service = "mql"; + recon.judgment = Judgment.Matched; + recon.judgmentAction = "auto"; + recon.match = candidate; + recon.matchRank = 0; + + keyToRecon.put(key, recon); + } } } finally { is.close(); @@ -224,7 +224,7 @@ public class KeyBasedReconConfig extends StrictReconConfig { String key = ((KeyBasedReconJob) job).key; Recon recon = keyToRecon.get(key); if (recon == null) { - recon = createNoMatchRecon(historyEntryID); + recon = createNoMatchRecon(historyEntryID); } recons.add(recon); } diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java index 33370583e..3fe200a7e 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java @@ -60,10 +60,10 @@ abstract public class StrictReconConfig extends ReconConfig { } protected Recon createNoMatchRecon(long historyEntryID) { - Recon recon = createNewRecon(historyEntryID); - recon.service = "mql"; - recon.judgment = Judgment.None; - recon.matchRank = -1; - return recon; + Recon recon = createNewRecon(historyEntryID); + recon.service = "mql"; + recon.judgment = Judgment.None; + recon.matchRank = -1; + return recon; } } diff --git a/extensions/freebase/src/com/google/refine/freebase/operations/ExtendDataOperation.java b/extensions/freebase/src/com/google/refine/freebase/operations/ExtendDataOperation.java index 29e5284de..83c7960b7 100644 --- a/extensions/freebase/src/com/google/refine/freebase/operations/ExtendDataOperation.java +++ b/extensions/freebase/src/com/google/refine/freebase/operations/ExtendDataOperation.java @@ -188,15 +188,15 @@ public class ExtendDataOperation extends EngineDependentOperation { _rowIndices = rowIndices; return this; } - + @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java b/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java index 4bd7dc516..ff3ab6b08 100644 --- a/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java +++ b/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java @@ -266,7 +266,7 @@ public class FreebaseUtils { } static public String getFreeQUrl() { - String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq"); - return url != null ? url : FREEQ_URL; + String url = (String) ProjectManager.singleton.getPreferenceStore().get("freebase.freeq"); + return url != null ? url : FREEQ_URL; } } \ No newline at end of file diff --git a/main/src/com/google/refine/browsing/Engine.java b/main/src/com/google/refine/browsing/Engine.java index 8393b6428..7924dcd13 100644 --- a/main/src/com/google/refine/browsing/Engine.java +++ b/main/src/com/google/refine/browsing/Engine.java @@ -1,4 +1,4 @@ -/* +/** Copyright 2010, Google Inc. 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 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ package com.google.refine.browsing; @@ -59,104 +59,104 @@ import com.google.refine.model.Row; * Faceted browsing engine. */ public class Engine implements Jsonizable { - static public enum Mode { - RowBased, - RecordBased - } - + static public enum Mode { + RowBased, + RecordBased + } + public final static String INCLUDE_DEPENDENT = "includeDependent"; public final static String MODE = "mode"; public final static String MODE_ROW_BASED = "row-based"; public final static String MODE_RECORD_BASED = "record-based"; - - protected Project _project; - protected List _facets = new LinkedList(); - protected Mode _mode = Mode.RowBased; - + + protected Project _project; + protected List _facets = new LinkedList(); + protected Mode _mode = Mode.RowBased; + 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) { - return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased; + return MODE_ROW_BASED.equals(s) ? Mode.RowBased : Mode.RecordBased; } - + public Engine(Project project) { _project = project; } - + public Mode getMode() { - return _mode; + return _mode; } public void setMode(Mode mode) { - _mode = mode; + _mode = mode; } - + public FilteredRows getAllRows() { return new FilteredRows() { - @Override - public void accept(Project project, RowVisitor visitor) { - try { - visitor.start(project); - - int c = project.rows.size(); - for (int rowIndex = 0; rowIndex < c; rowIndex++) { - Row row = project.rows.get(rowIndex); - visitor.visit(project, rowIndex, row); - } - } finally { - visitor.end(project); - } - } + @Override + public void accept(Project project, RowVisitor visitor) { + try { + visitor.start(project); + + int c = project.rows.size(); + for (int rowIndex = 0; rowIndex < c; rowIndex++) { + Row row = project.rows.get(rowIndex); + visitor.visit(project, rowIndex, row); + } + } finally { + visitor.end(project); + } + } }; } - + public FilteredRows getAllFilteredRows() { return getFilteredRows(null); } public FilteredRows getFilteredRows(Facet except) { - if (_mode == Mode.RecordBased) { - return new FilteredRecordsAsFilteredRows(getFilteredRecords(except)); - } else if (_mode == Mode.RowBased) { - ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(); - for (Facet facet : _facets) { - if (facet != except) { - RowFilter rowFilter = facet.getRowFilter(_project); - if (rowFilter != null) { - cfr.add(rowFilter); - } - } - } - return cfr; - } - throw new InternalError("Unknown mode."); + if (_mode == Mode.RecordBased) { + return new FilteredRecordsAsFilteredRows(getFilteredRecords(except)); + } else if (_mode == Mode.RowBased) { + ConjunctiveFilteredRows cfr = new ConjunctiveFilteredRows(); + for (Facet facet : _facets) { + if (facet != except) { + RowFilter rowFilter = facet.getRowFilter(_project); + if (rowFilter != null) { + cfr.add(rowFilter); + } + } + } + return cfr; + } + throw new InternalError("Unknown mode."); } - + public FilteredRecords getAllRecords() { return new FilteredRecords() { - @Override - public void accept(Project project, RecordVisitor visitor) { - try { - visitor.start(project); - - int c = project.recordModel.getRecordCount(); - for (int r = 0; r < c; r++) { - visitor.visit(project, project.recordModel.getRecord(r)); - } - } finally { - visitor.end(project); - } - } + @Override + public void accept(Project project, RecordVisitor visitor) { + try { + visitor.start(project); + + int c = project.recordModel.getRecordCount(); + for (int r = 0; r < c; r++) { + visitor.visit(project, project.recordModel.getRecord(r)); + } + } finally { + visitor.end(project); + } + } }; } - + public FilteredRecords getFilteredRecords() { - return getFilteredRecords(null); + return getFilteredRecords(null); } - + public FilteredRecords getFilteredRecords(Facet except) { - if (_mode == Mode.RecordBased) { - ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords(); + if (_mode == Mode.RecordBased) { + ConjunctiveFilteredRecords cfr = new ConjunctiveFilteredRecords(); for (Facet facet : _facets) { if (facet != except) { RecordFilter recordFilter = facet.getRecordFilter(_project); @@ -166,23 +166,23 @@ public class Engine implements Jsonizable { } } 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 { if (o == null) { return; } - + if (o.has("facets") && !o.isNull("facets")) { JSONArray a = o.getJSONArray("facets"); int length = a.length(); - + for (int i = 0; i < length; i++) { JSONObject fo = a.getJSONObject(i); String type = fo.has("type") ? fo.getString("type") : "list"; - + Facet facet = null; if ("list".equals(type)) { facet = new ListFacet(); @@ -195,53 +195,53 @@ public class Engine implements Jsonizable { } else if ("text".equals(type)) { facet = new TextSearchFacet(); } - + if (facet != null) { facet.initializeFromJSON(_project, fo); _facets.add(facet); } } } - + // for backward compatibility if (o.has(INCLUDE_DEPENDENT) && !o.isNull(INCLUDE_DEPENDENT)) { _mode = o.getBoolean(INCLUDE_DEPENDENT) ? Mode.RecordBased : Mode.RowBased; } - + 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 { - if (_mode == Mode.RowBased) { - for (Facet facet : _facets) { - FilteredRows filteredRows = getFilteredRows(facet); - - facet.computeChoices(_project, filteredRows); - } - } else if (_mode == Mode.RecordBased) { - for (Facet facet : _facets) { - FilteredRecords filteredRecords = getFilteredRecords(facet); - - facet.computeChoices(_project, filteredRecords); - } - } else { - throw new InternalError("Unknown mode."); - } + if (_mode == Mode.RowBased) { + for (Facet facet : _facets) { + FilteredRows filteredRows = getFilteredRows(facet); + + facet.computeChoices(_project, filteredRows); + } + } else if (_mode == Mode.RecordBased) { + for (Facet facet : _facets) { + FilteredRecords filteredRecords = getFilteredRecords(facet); + + facet.computeChoices(_project, filteredRecords); + } + } else { + throw new InternalError("Unknown mode."); + } } - + @Override public void write(JSONWriter writer, Properties options) - throws JSONException { - + throws JSONException { + writer.object(); writer.key("facets"); - writer.array(); - for (Facet facet : _facets) { - facet.write(writer, options); - } - writer.endArray(); + writer.array(); + for (Facet facet : _facets) { + facet.write(writer, options); + } + writer.endArray(); writer.key(MODE); writer.value(_mode == Mode.RowBased ? MODE_ROW_BASED : MODE_RECORD_BASED); writer.endObject(); } diff --git a/main/src/com/google/refine/browsing/RecordVisitor.java b/main/src/com/google/refine/browsing/RecordVisitor.java index ec19b1e41..6c7a8a13b 100644 --- a/main/src/com/google/refine/browsing/RecordVisitor.java +++ b/main/src/com/google/refine/browsing/RecordVisitor.java @@ -41,12 +41,12 @@ import com.google.refine.model.Record; * particular criteria, such as facets' constraints. */ 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( - Project project, - Record record + Project project, + Record record ); - - public void end(Project project); // called after all visit() calls + + public void end(Project project); // called after all visit() calls } diff --git a/main/src/com/google/refine/browsing/RowVisitor.java b/main/src/com/google/refine/browsing/RowVisitor.java index c4eeed5e0..8e6b4601a 100644 --- a/main/src/com/google/refine/browsing/RowVisitor.java +++ b/main/src/com/google/refine/browsing/RowVisitor.java @@ -41,13 +41,13 @@ import com.google.refine.model.Row; * particular criteria, such as facets' constraints. */ 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( - Project project, - int rowIndex, // zero-based row index - Row row + Project project, + int rowIndex, // zero-based row index + Row row ); - - public void end(Project project); // called after all visit() calls + + public void end(Project project); // called after all visit() calls } diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index 635699f25..6c6a2e34f 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -218,11 +218,11 @@ public class ListFacet implements Facet { @Override public RecordFilter getRecordFilter(Project project) { - RowFilter rowFilter = getRowFilter(project); - return rowFilter == null ? null : - (_invert ? - new AllRowsRecordFilter(rowFilter) : - new AnyRowRecordFilter(rowFilter)); + RowFilter rowFilter = getRowFilter(project); + return rowFilter == null ? null : + (_invert ? + new AllRowsRecordFilter(rowFilter) : + new AnyRowRecordFilter(rowFilter)); } @Override diff --git a/main/src/com/google/refine/browsing/facets/RangeFacet.java b/main/src/com/google/refine/browsing/facets/RangeFacet.java index ca7d7ff91..bd6906def 100644 --- a/main/src/com/google/refine/browsing/facets/RangeFacet.java +++ b/main/src/com/google/refine/browsing/facets/RangeFacet.java @@ -201,8 +201,8 @@ public class RangeFacet implements Facet { public RowFilter getRowFilter(Project project) { if (_eval != null && _errorMessage == null && _selected) { return new ExpressionNumberComparisonRowFilter( - getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) { - + getRowEvaluable(project), _selectNumeric, _selectNonNumeric, _selectBlank, _selectError) { + @Override protected boolean checkValue(double d) { return d >= _from && d < _to; @@ -215,8 +215,8 @@ public class RangeFacet implements Facet { @Override public RecordFilter getRecordFilter(Project project) { - RowFilter rowFilter = getRowFilter(project); - return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); + RowFilter rowFilter = getRowFilter(project); + return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); } @Override @@ -267,7 +267,7 @@ public class RangeFacet implements Facet { } protected RowEvaluable getRowEvaluable(Project project) { - return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval); + return new ExpressionBasedRowEvaluable(_columnName, _cellIndex, _eval); } protected void retrieveDataFromBaseBinIndex(NumericBinIndex index) { diff --git a/main/src/com/google/refine/browsing/facets/ScatterplotDrawingRowVisitor.java b/main/src/com/google/refine/browsing/facets/ScatterplotDrawingRowVisitor.java index 4d34332fa..169995bf1 100644 --- a/main/src/com/google/refine/browsing/facets/ScatterplotDrawingRowVisitor.java +++ b/main/src/com/google/refine/browsing/facets/ScatterplotDrawingRowVisitor.java @@ -122,12 +122,12 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override @@ -153,10 +153,10 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor { @Override public boolean visit(Project project, Record record) { - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - visit(project, r, project.rows.get(r)); - } - return false; + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + visit(project, r, project.rows.get(r)); + } + return false; } public RenderedImage getImage() { diff --git a/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java b/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java index 1a36f8913..178dbbe0c 100644 --- a/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java +++ b/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java @@ -315,8 +315,8 @@ public class ScatterplotFacet implements Facet { @Override public RecordFilter getRecordFilter(Project project) { - RowFilter rowFilter = getRowFilter(project); - return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); + RowFilter rowFilter = getRowFilter(project); + return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); } @Override @@ -414,7 +414,7 @@ public class ScatterplotFacet implements Facet { } 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) { @@ -429,10 +429,10 @@ public class ScatterplotFacet implements Facet { NumericBinIndex index = (NumericBinIndex) column.getPrecompute(key); if (index == null) { index = "row-based".equals(mode) ? - new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) : - new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)); - - column.setPrecompute(key, index); + new NumericBinRowIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)) : + new NumericBinRecordIndex(project, new ExpressionBasedRowEvaluable(column.getName(), column.getCellIndex(), eval)); + + column.setPrecompute(key, index); } return index; } diff --git a/main/src/com/google/refine/browsing/facets/TextSearchFacet.java b/main/src/com/google/refine/browsing/facets/TextSearchFacet.java index 19a2c6186..48c74201e 100644 --- a/main/src/com/google/refine/browsing/facets/TextSearchFacet.java +++ b/main/src/com/google/refine/browsing/facets/TextSearchFacet.java @@ -101,13 +101,13 @@ public class TextSearchFacet implements Facet { if ("regex".equals(_mode)) { try { _pattern = Pattern.compile( - _query, - _caseSensitive ? 0 : Pattern.CASE_INSENSITIVE); + _query, + _caseSensitive ? 0 : Pattern.CASE_INSENSITIVE); } catch (java.util.regex.PatternSyntaxException e) { e.printStackTrace(); } } else if (!_caseSensitive) { - _query = _query.toLowerCase(); + _query = _query.toLowerCase(); } } } @@ -141,17 +141,17 @@ public class TextSearchFacet implements Facet { @Override public RecordFilter getRecordFilter(Project project) { - RowFilter rowFilter = getRowFilter(project); - return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); + RowFilter rowFilter = getRowFilter(project); + return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); } @Override public void computeChoices(Project project, FilteredRows filteredRows) { // nothing to do } - + @Override public void computeChoices(Project project, FilteredRecords filteredRecords) { - // nothing to do + // nothing to do } } diff --git a/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java b/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java index d930d9835..7957672c6 100644 --- a/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java +++ b/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java @@ -55,7 +55,7 @@ import com.google.refine.model.Project; import com.google.refine.util.JSONUtilities; public class TimeRangeFacet extends RangeFacet { - + protected boolean _selectTime; // whether the time selection applies, default true protected boolean _selectNonTime; @@ -153,7 +153,7 @@ public class TimeRangeFacet extends RangeFacet { public RowFilter getRowFilter(Project project) { if (_eval != null && _errorMessage == null && _selected) { return new ExpressionTimeComparisonRowFilter( - getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) { + getRowEvaluable(project), _selectTime, _selectNonTime, _selectBlank, _selectError) { @Override protected boolean checkValue(long t) { diff --git a/main/src/com/google/refine/browsing/filters/AllRowsRecordFilter.java b/main/src/com/google/refine/browsing/filters/AllRowsRecordFilter.java index 2aab0cf69..61a2a7a82 100644 --- a/main/src/com/google/refine/browsing/filters/AllRowsRecordFilter.java +++ b/main/src/com/google/refine/browsing/filters/AllRowsRecordFilter.java @@ -39,19 +39,19 @@ import com.google.refine.model.Project; import com.google.refine.model.Record; public class AllRowsRecordFilter implements RecordFilter { - final protected RowFilter _rowFilter; - - public AllRowsRecordFilter(RowFilter rowFilter) { - _rowFilter = rowFilter; - } + final protected RowFilter _rowFilter; - @Override - public boolean filterRecord(Project project, Record record) { - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - if (!_rowFilter.filterRow(project, r, project.rows.get(r))) { - return false; - } - } - return true; - } + public AllRowsRecordFilter(RowFilter rowFilter) { + _rowFilter = rowFilter; + } + + @Override + public boolean filterRecord(Project project, Record record) { + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + if (!_rowFilter.filterRow(project, r, project.rows.get(r))) { + return false; + } + } + return true; + } } diff --git a/main/src/com/google/refine/browsing/filters/AnyRowRecordFilter.java b/main/src/com/google/refine/browsing/filters/AnyRowRecordFilter.java index 6aee8b476..cf0381c65 100644 --- a/main/src/com/google/refine/browsing/filters/AnyRowRecordFilter.java +++ b/main/src/com/google/refine/browsing/filters/AnyRowRecordFilter.java @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are 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. - * 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 in the documentation and/or other materials provided with the 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 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 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ package com.google.refine.browsing.filters; @@ -39,19 +39,19 @@ import com.google.refine.model.Project; import com.google.refine.model.Record; public class AnyRowRecordFilter implements RecordFilter { - final protected RowFilter _rowFilter; - - public AnyRowRecordFilter(RowFilter rowFilter) { - _rowFilter = rowFilter; - } + final protected RowFilter _rowFilter; - @Override - public boolean filterRecord(Project project, Record record) { - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - if (_rowFilter.filterRow(project, r, project.rows.get(r))) { - return true; - } - } - return false; - } + public AnyRowRecordFilter(RowFilter rowFilter) { + _rowFilter = rowFilter; + } + + @Override + public boolean filterRecord(Project project, Record record) { + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + if (_rowFilter.filterRow(project, r, project.rows.get(r))) { + return true; + } + } + return false; + } } diff --git a/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java b/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java index 1a3462017..fbb0684a8 100644 --- a/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java +++ b/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java @@ -52,20 +52,20 @@ import com.google.refine.model.Row; * values. */ abstract public class ExpressionNumberComparisonRowFilter implements RowFilter { - final protected RowEvaluable _rowEvaluable; - final protected boolean _selectNumeric; - final protected boolean _selectNonNumeric; - final protected boolean _selectBlank; - final protected boolean _selectError; - + final protected RowEvaluable _rowEvaluable; + final protected boolean _selectNumeric; + final protected boolean _selectNonNumeric; + final protected boolean _selectBlank; + final protected boolean _selectError; + public ExpressionNumberComparisonRowFilter( - RowEvaluable rowEvaluable, - boolean selectNumeric, - boolean selectNonNumeric, - boolean selectBlank, - boolean selectError + RowEvaluable rowEvaluable, + boolean selectNumeric, + boolean selectNonNumeric, + boolean selectBlank, + boolean selectError ) { - _rowEvaluable = rowEvaluable; + _rowEvaluable = rowEvaluable; _selectNumeric = selectNumeric; _selectNonNumeric = selectNonNumeric; _selectBlank = selectBlank; diff --git a/main/src/com/google/refine/browsing/filters/ExpressionTimeComparisonRowFilter.java b/main/src/com/google/refine/browsing/filters/ExpressionTimeComparisonRowFilter.java index a2e3cdae5..61285ebd2 100644 --- a/main/src/com/google/refine/browsing/filters/ExpressionTimeComparisonRowFilter.java +++ b/main/src/com/google/refine/browsing/filters/ExpressionTimeComparisonRowFilter.java @@ -46,21 +46,21 @@ import com.google.refine.expr.ExpressionUtils; */ abstract public class ExpressionTimeComparisonRowFilter extends ExpressionNumberComparisonRowFilter { - final protected boolean _selectTime; - final protected boolean _selectNonTime; + final protected boolean _selectTime; + final protected boolean _selectNonTime; public ExpressionTimeComparisonRowFilter( - RowEvaluable rowEvaluable, - boolean selectTime, - boolean selectNonTime, - boolean selectBlank, - boolean selectError + RowEvaluable rowEvaluable, + boolean selectTime, + boolean selectNonTime, + boolean selectBlank, + boolean selectError ) { - super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError); - _selectTime = selectTime; - _selectNonTime = selectNonTime; + super(rowEvaluable, selectTime, selectNonTime, selectBlank, selectError); + _selectTime = selectTime; + _selectNonTime = selectNonTime; } - + @Override protected boolean checkValue(Object 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 @Override protected boolean checkValue(double d) { - return false; + return false; } abstract protected boolean checkValue(long d); diff --git a/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRecords.java b/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRecords.java index 48ce81afd..635aa8043 100644 --- a/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRecords.java +++ b/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRecords.java @@ -54,21 +54,21 @@ public class ConjunctiveFilteredRecords implements FilteredRecords { @Override public void accept(Project project, RecordVisitor visitor) { - try { - visitor.start(project); - - int c = project.recordModel.getRecordCount(); - for (int r = 0; r < c; r++) { - Record record = project.recordModel.getRecord(r); - if (matchRecord(project, record)) { - if (visitor.visit(project, record)) { - return; - } - } - } - } finally { - visitor.end(project); - } + try { + visitor.start(project); + + int c = project.recordModel.getRecordCount(); + for (int r = 0; r < c; r++) { + Record record = project.recordModel.getRecord(r); + if (matchRecord(project, record)) { + if (visitor.visit(project, record)) { + return; + } + } + } + } finally { + visitor.end(project); + } } protected boolean matchRecord(Project project, Record record) { diff --git a/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRows.java b/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRows.java index 756110377..344e0dcfb 100644 --- a/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRows.java +++ b/main/src/com/google/refine/browsing/util/ConjunctiveFilteredRows.java @@ -55,19 +55,19 @@ public class ConjunctiveFilteredRows implements FilteredRows { @Override public void accept(Project project, RowVisitor visitor) { - try { - visitor.start(project); - - int c = project.rows.size(); - for (int rowIndex = 0; rowIndex < c; rowIndex++) { - Row row = project.rows.get(rowIndex); - if (matchRow(project, rowIndex, row)) { - visitRow(project, visitor, rowIndex, row); - } - } - } finally { - visitor.end(project); - } + try { + visitor.start(project); + + int c = project.rows.size(); + for (int rowIndex = 0; rowIndex < c; rowIndex++) { + Row row = project.rows.get(rowIndex); + if (matchRow(project, rowIndex, row)) { + visitRow(project, visitor, rowIndex, row); + } + } + } finally { + visitor.end(project); + } } protected void visitRow(Project project, RowVisitor visitor, int rowIndex, Row row) { diff --git a/main/src/com/google/refine/browsing/util/ExpressionNominalValueGrouper.java b/main/src/com/google/refine/browsing/util/ExpressionNominalValueGrouper.java index 19511f029..a6d3dbdc9 100644 --- a/main/src/com/google/refine/browsing/util/ExpressionNominalValueGrouper.java +++ b/main/src/com/google/refine/browsing/util/ExpressionNominalValueGrouper.java @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are 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. - * 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 in the documentation and/or other materials provided with the 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 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 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ package com.google.refine.browsing.util; @@ -56,94 +56,94 @@ import com.google.refine.model.Row; * from a given expression. */ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor { - static public class IndexedNominalFacetChoice extends NominalFacetChoice { - int _latestIndex; - - public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) { - super(decoratedValue); - _latestIndex = latestIndex; - } - } - + static public class IndexedNominalFacetChoice extends NominalFacetChoice { + int _latestIndex; + + public IndexedNominalFacetChoice(DecoratedValue decoratedValue, int latestIndex) { + super(decoratedValue); + _latestIndex = latestIndex; + } + } + /* * Configuration */ final protected Evaluable _evaluable; final protected String _columnName; final protected int _cellIndex; - + /* * Computed results */ final public Map choices = new HashMap(); public int blankCount = 0; public int errorCount = 0; - + /* * Scratch pad variables */ protected boolean hasBlank; protected boolean hasError; - + public ExpressionNominalValueGrouper(Evaluable evaluable, String columnName, int cellIndex) { _evaluable = evaluable; _columnName = columnName; _cellIndex = cellIndex; } - + @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } - + @Override public boolean visit(Project project, int rowIndex, Row row) { - hasError = false; - hasBlank = false; - + hasError = false; + hasBlank = false; + Properties bindings = ExpressionUtils.createBindings(project); - + visitRow(project, rowIndex, row, bindings, rowIndex); - + if (hasError) { - errorCount++; + errorCount++; } if (hasBlank) { - blankCount++; + blankCount++; } - + return false; } - + @Override public boolean visit(Project project, Record record) { - hasError = false; - hasBlank = false; - + hasError = false; + hasBlank = false; + Properties bindings = ExpressionUtils.createBindings(project); - + 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); } - + if (hasError) { - errorCount++; + errorCount++; } if (hasBlank) { - blankCount++; + blankCount++; } - + return false; } - + 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.getClass().isArray()) { Object[] a = (Object[]) value; @@ -155,83 +155,83 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor processValue(v, rowIndex); } } else { - processValue(value, rowIndex); + processValue(value, rowIndex); } } else { - processValue(value, rowIndex); + processValue(value, rowIndex); } } - + protected Object evalRow(Project project, int rowIndex, Row row, Properties bindings) { - Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex); - - ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); - - return _evaluable.evaluate(bindings); + Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex); + + ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); + + return _evaluable.evaluate(bindings); } - + protected void processValue(Object value, int index) { if (ExpressionUtils.isError(value)) { hasError = true; } else if (ExpressionUtils.isNonBlankData(value)) { String valueString = value.toString(); IndexedNominalFacetChoice facetChoice = choices.get(valueString); - + if (facetChoice != null) { - if (facetChoice._latestIndex < index) { - facetChoice._latestIndex = index; - facetChoice.count++; - } + if (facetChoice._latestIndex < index) { + facetChoice._latestIndex = index; + facetChoice.count++; + } } else { - String label = value.toString(); - DecoratedValue dValue = new DecoratedValue(value, label); - IndexedNominalFacetChoice choice = - new IndexedNominalFacetChoice(dValue, index); - + String label = value.toString(); + DecoratedValue dValue = new DecoratedValue(value, label); + IndexedNominalFacetChoice choice = + new IndexedNominalFacetChoice(dValue, index); + choice.count = 1; choices.put(valueString, choice); } } else { - hasBlank = true; + hasBlank = true; } } - + public RowEvaluable getChoiceCountRowEvaluable() { - return new RowEvaluable() { - @Override - public Object eval(Project project, int rowIndex, Row row, Properties bindings) { - Object value = evalRow(project, rowIndex, row, bindings); - return getChoiceValueCountMultiple(value); - } - - }; + return new RowEvaluable() { + @Override + public Object eval(Project project, int rowIndex, Row row, Properties bindings) { + Object value = evalRow(project, rowIndex, row, bindings); + return getChoiceValueCountMultiple(value); + } + + }; } - + public Object getChoiceValueCountMultiple(Object value) { if (value != null) { - if (value.getClass().isArray()) { + if (value.getClass().isArray()) { Object[] choiceValues = (Object[]) value; List counts = new ArrayList(choiceValues.length); - + for (int i = 0; i < choiceValues.length; i++) { - counts.add(getChoiceValueCount(choiceValues[i])); + counts.add(getChoiceValueCount(choiceValues[i])); } return counts; } else if (value instanceof Collection) { - List choiceValues = ExpressionUtils.toObjectList(value); + List choiceValues = ExpressionUtils.toObjectList(value); List counts = new ArrayList(choiceValues.size()); - - int count = choiceValues.size(); + + int count = choiceValues.size(); for (int i = 0; i < count; i++) { - counts.add(getChoiceValueCount(choiceValues.get(i))); + counts.add(getChoiceValueCount(choiceValues.get(i))); } return counts; } } - + return getChoiceValueCount(value); } - + public Integer getChoiceValueCount(Object choiceValue) { if (ExpressionUtils.isError(choiceValue)) { return errorCount; diff --git a/main/src/com/google/refine/browsing/util/ExpressionNumericValueBinner.java b/main/src/com/google/refine/browsing/util/ExpressionNumericValueBinner.java index ac339e89f..e576bb163 100644 --- a/main/src/com/google/refine/browsing/util/ExpressionNumericValueBinner.java +++ b/main/src/com/google/refine/browsing/util/ExpressionNumericValueBinner.java @@ -51,9 +51,9 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { /* * Configuration */ - final protected RowEvaluable _rowEvaluable; - final protected NumericBinIndex _index; // base bins - + final protected RowEvaluable _rowEvaluable; + final protected NumericBinIndex _index; // base bins + /* * Computed results */ @@ -72,19 +72,19 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { protected boolean hasNonNumeric; public ExpressionNumericValueBinner(RowEvaluable rowEvaluable, NumericBinIndex index) { - _rowEvaluable = rowEvaluable; + _rowEvaluable = rowEvaluable; _index = index; bins = new int[_index.getBins().length]; } @Override public void start(Project project) { - // nothing to do + // nothing to do } @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override @@ -105,7 +105,7 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { Properties bindings = ExpressionUtils.createBindings(project); 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(); diff --git a/main/src/com/google/refine/browsing/util/ExpressionTimeValueBinner.java b/main/src/com/google/refine/browsing/util/ExpressionTimeValueBinner.java index 6f2bb4b45..6bcf4ebbb 100644 --- a/main/src/com/google/refine/browsing/util/ExpressionTimeValueBinner.java +++ b/main/src/com/google/refine/browsing/util/ExpressionTimeValueBinner.java @@ -50,13 +50,13 @@ import com.google.refine.model.Row; * from a given expression. */ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor { - + /* * Configuration */ - final protected RowEvaluable _rowEvaluable; - final protected TimeBinIndex _index; // base bins - + final protected RowEvaluable _rowEvaluable; + final protected TimeBinIndex _index; // base bins + /* * Computed results */ @@ -75,19 +75,19 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor { protected boolean hasNonTime; public ExpressionTimeValueBinner(RowEvaluable rowEvaluable, TimeBinIndex index) { - _rowEvaluable = rowEvaluable; + _rowEvaluable = rowEvaluable; _index = index; bins = new int[_index.getBins().length]; } - + @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override @@ -108,7 +108,7 @@ public class ExpressionTimeValueBinner implements RowVisitor, RecordVisitor { Properties bindings = ExpressionUtils.createBindings(project); 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(); diff --git a/main/src/com/google/refine/browsing/util/TimeBinIndex.java b/main/src/com/google/refine/browsing/util/TimeBinIndex.java index 6ef830277..00a08fa0b 100644 --- a/main/src/com/google/refine/browsing/util/TimeBinIndex.java +++ b/main/src/com/google/refine/browsing/util/TimeBinIndex.java @@ -74,17 +74,17 @@ abstract public class TimeBinIndex { protected boolean _hasBlank = false; protected long[] steps = { - 1, // msec - 1000, // sec - 1000*60, // min - 1000*60*60, // hour - 1000*60*60*24, // day - 1000*60*60*24*7, // week - 1000l*2629746l, // month (average Gregorian year / 12) - 1000l*31556952l, // year (average Gregorian year) - 1000l*31556952l*10l, // decade - 1000l*31556952l*100l, // century - 1000l*31556952l*1000l, // millennium + 1, // msec + 1000, // sec + 1000*60, // min + 1000*60*60, // hour + 1000*60*60*24, // day + 1000*60*60*24*7, // week + 1000l*2629746l, // month (average Gregorian year / 12) + 1000l*31556952l, // year (average Gregorian year) + 1000l*31556952l*10l, // decade + 1000l*31556952l*100l, // century + 1000l*31556952l*1000l, // millennium }; abstract protected void iterate(Project project, RowEvaluable rowEvaluable, List allValues); @@ -110,10 +110,10 @@ abstract public class TimeBinIndex { long diff = _max - _min; - for (int i = 0; i < steps.length; i++) { - _step = steps[i]; - if (diff / _step <= 100) break; - } + for (int i = 0; i < steps.length; i++) { + _step = steps[i]; + if (diff / _step <= 100) break; + } _bins = new int[(int) (diff / _step) + 1]; for (long d : allValues) { @@ -180,7 +180,7 @@ abstract public class TimeBinIndex { _hasError = true; } else if (ExpressionUtils.isNonBlankData(v)) { if (v instanceof Calendar) { - v = ((Calendar) v).getTime(); + v = ((Calendar) v).getTime(); } if (v instanceof Date) { @@ -201,7 +201,7 @@ abstract public class TimeBinIndex { _hasError = true; } else if (ExpressionUtils.isNonBlankData(v)) { if (v instanceof Calendar) { - v = ((Calendar) v).getTime(); + v = ((Calendar) v).getTime(); } if (v instanceof Date) { @@ -218,7 +218,7 @@ abstract public class TimeBinIndex { _totalValueCount++; if (value instanceof Calendar) { - value = ((Calendar) value).getTime(); + value = ((Calendar) value).getTime(); } if (value instanceof Date) { diff --git a/main/src/com/google/refine/browsing/util/TimeBinRecordIndex.java b/main/src/com/google/refine/browsing/util/TimeBinRecordIndex.java index 8cfa6a1d8..e727bd6e5 100644 --- a/main/src/com/google/refine/browsing/util/TimeBinRecordIndex.java +++ b/main/src/com/google/refine/browsing/util/TimeBinRecordIndex.java @@ -42,7 +42,7 @@ import com.google.refine.model.Record; import com.google.refine.model.Row; public class TimeBinRecordIndex extends TimeBinIndex { - + public TimeBinRecordIndex(Project project, RowEvaluable rowEvaluable) { super(project, rowEvaluable); } diff --git a/main/src/com/google/refine/browsing/util/TimeBinRowIndex.java b/main/src/com/google/refine/browsing/util/TimeBinRowIndex.java index 0f34a8de6..863fe71d3 100644 --- a/main/src/com/google/refine/browsing/util/TimeBinRowIndex.java +++ b/main/src/com/google/refine/browsing/util/TimeBinRowIndex.java @@ -42,7 +42,7 @@ import com.google.refine.model.Row; public class TimeBinRowIndex extends TimeBinIndex { - public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) { + public TimeBinRowIndex(Project project, RowEvaluable rowEvaluable) { super(project, rowEvaluable); } diff --git a/main/src/com/google/refine/clustering/binning/BinningClusterer.java b/main/src/com/google/refine/clustering/binning/BinningClusterer.java index 4b34ed8de..8a796ab18 100644 --- a/main/src/com/google/refine/clustering/binning/BinningClusterer.java +++ b/main/src/com/google/refine/clustering/binning/BinningClusterer.java @@ -103,12 +103,12 @@ public class BinningClusterer extends Clusterer { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/clustering/knn/kNNClusterer.java b/main/src/com/google/refine/clustering/knn/kNNClusterer.java index a909d5561..b9db33b85 100644 --- a/main/src/com/google/refine/clustering/knn/kNNClusterer.java +++ b/main/src/com/google/refine/clustering/knn/kNNClusterer.java @@ -115,12 +115,12 @@ public class kNNClusterer extends Clusterer { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override @@ -167,12 +167,12 @@ public class kNNClusterer extends Clusterer { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java b/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java index 4f73bbea9..ab91fec28 100644 --- a/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java +++ b/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java @@ -57,14 +57,14 @@ public class OpenWorkspaceDirCommand extends Command { File dir = ((FileProjectManager) ProjectManager.singleton).getWorkspaceDir(); if (Desktop.isDesktopSupported()) { - Desktop desktop = Desktop.getDesktop(); - desktop.open(dir); + Desktop desktop = Desktop.getDesktop(); + desktop.open(dir); } else /* if Mac */ { - Runtime.getRuntime().exec( - "open .", - new String[] {}, - dir - ); + Runtime.getRuntime().exec( + "open .", + new String[] {}, + dir + ); } respond(response, "{ \"code\" : \"ok\" }"); diff --git a/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java b/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java index a2078be05..a76a37fd0 100644 --- a/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java +++ b/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java @@ -51,10 +51,10 @@ import com.google.refine.model.Project; import com.google.refine.preference.TopList; public class GetExpressionHistoryCommand extends Command { - - static protected List toExpressionList(Object o) { + + static protected List toExpressionList(Object o) { return o == null ? new ArrayList() : ((TopList) o).getList(); - } + } @Override public void doGet(HttpServletRequest request, HttpServletResponse response) diff --git a/main/src/com/google/refine/commands/project/ExportRowsCommand.java b/main/src/com/google/refine/commands/project/ExportRowsCommand.java index c2fb1c55b..d781d5da1 100644 --- a/main/src/com/google/refine/commands/project/ExportRowsCommand.java +++ b/main/src/com/google/refine/commands/project/ExportRowsCommand.java @@ -56,15 +56,15 @@ import com.google.refine.model.Project; public class ExportRowsCommand extends Command { @SuppressWarnings("unchecked") - static public Properties getRequestParameters(HttpServletRequest request) { + static public Properties getRequestParameters(HttpServletRequest request) { Properties options = new Properties(); - + Enumeration en = request.getParameterNames(); while (en.hasMoreElements()) { - String name = en.nextElement(); - options.put(name, request.getParameter(name)); + String name = en.nextElement(); + options.put(name, request.getParameter(name)); } - return options; + return options; } @Override diff --git a/main/src/com/google/refine/commands/row/ReorderRowsCommand.java b/main/src/com/google/refine/commands/row/ReorderRowsCommand.java index 3bbb424db..d1c7813b6 100644 --- a/main/src/com/google/refine/commands/row/ReorderRowsCommand.java +++ b/main/src/com/google/refine/commands/row/ReorderRowsCommand.java @@ -50,16 +50,16 @@ public class ReorderRowsCommand extends EngineDependentCommand { @Override protected AbstractOperation createOperation(Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception { - - String mode = request.getParameter("mode"); - JSONObject sorting = null; - + + String mode = request.getParameter("mode"); + JSONObject sorting = null; + try{ String json = request.getParameter("sorting"); - + sorting = (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json); } catch (JSONException e) { - // ignore + // ignore } return new RowReorderOperation(Engine.stringToMode(mode), sorting); diff --git a/main/src/com/google/refine/exporters/HtmlTableExporter.java b/main/src/com/google/refine/exporters/HtmlTableExporter.java index 3e99391be..2dfe98b86 100644 --- a/main/src/com/google/refine/exporters/HtmlTableExporter.java +++ b/main/src/com/google/refine/exporters/HtmlTableExporter.java @@ -48,7 +48,7 @@ import com.google.refine.model.Row; public class HtmlTableExporter implements WriterExporter { - @Override + @Override public String getContentType() { return "text/html"; } @@ -84,12 +84,12 @@ public class HtmlTableExporter implements WriterExporter { @Override public void start(Project project) { - // nothing to do + // nothing to do } @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/exporters/XlsExporter.java b/main/src/com/google/refine/exporters/XlsExporter.java index cafe14095..f53c0c037 100644 --- a/main/src/com/google/refine/exporters/XlsExporter.java +++ b/main/src/com/google/refine/exporters/XlsExporter.java @@ -97,12 +97,12 @@ public class XlsExporter implements StreamExporter { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/expr/WrappedRow.java b/main/src/com/google/refine/expr/WrappedRow.java index 81b6529e6..559dd8561 100644 --- a/main/src/com/google/refine/expr/WrappedRow.java +++ b/main/src/com/google/refine/expr/WrappedRow.java @@ -77,10 +77,10 @@ public class WrappedRow implements HasFields { } protected class WrappedRecord implements HasFields { - final Record _record; - + final Record _record; + protected WrappedRecord(Record record) { - _record = record; + _record = record; } @Override diff --git a/main/src/com/google/refine/expr/functions/FacetCount.java b/main/src/com/google/refine/expr/functions/FacetCount.java index 3fe874f11..42e172265 100644 --- a/main/src/com/google/refine/expr/functions/FacetCount.java +++ b/main/src/com/google/refine/expr/functions/FacetCount.java @@ -54,36 +54,36 @@ public class FacetCount implements Function { @Override public Object call(Properties bindings, Object[] args) { if (args.length == 3 && args[1] instanceof String && args[2] instanceof String) { - Object choiceValue = args[0]; // choice value to look up - String facetExpression = (String) args[1]; - String columnName = (String) args[2]; - - Project project = (Project) bindings.get("project"); + Object choiceValue = args[0]; // choice value to look up + String facetExpression = (String) args[1]; + String columnName = (String) args[2]; + + Project project = (Project) bindings.get("project"); Column column = project.columnModel.getColumnByName(columnName); if (column == null) { return new EvalError("No such column named " + columnName); } - + String key = "nominal-bin:" + facetExpression; ExpressionNominalValueGrouper grouper = (ExpressionNominalValueGrouper) column.getPrecompute(key); if (grouper == null) { - try { - Evaluable eval = MetaParser.parse(facetExpression); - Engine engine = new Engine(project); - - grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex()); - engine.getAllRows().accept(project, grouper); - - column.setPrecompute(key, grouper); - } catch (ParsingException e) { - return new EvalError("Error parsing facet expression " + facetExpression); - } + try { + Evaluable eval = MetaParser.parse(facetExpression); + Engine engine = new Engine(project); + + grouper = new ExpressionNominalValueGrouper(eval, columnName, column.getCellIndex()); + engine.getAllRows().accept(project, grouper); + + column.setPrecompute(key, grouper); + } catch (ParsingException e) { + return new EvalError("Error parsing facet expression " + facetExpression); + } } - + return grouper.getChoiceValueCountMultiple(choiceValue); } 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 diff --git a/main/src/com/google/refine/expr/functions/Jsonize.java b/main/src/com/google/refine/expr/functions/Jsonize.java index 02d4c5f8e..ab0bc9567 100644 --- a/main/src/com/google/refine/expr/functions/Jsonize.java +++ b/main/src/com/google/refine/expr/functions/Jsonize.java @@ -49,15 +49,15 @@ public class Jsonize implements Function { @Override public Object call(Properties bindings, Object[] args) { if (args.length >= 1) { - try { - Object o1 = args[0]; - if (o1 == null) { - return "null"; - } else if (o1 instanceof Number) { - return JSONObject.numberToString((Number) o1); - } else if (o1 instanceof Boolean) { - return o1.toString(); - } else if (o1 instanceof JSONObject) { + try { + Object o1 = args[0]; + if (o1 == null) { + return "null"; + } else if (o1 instanceof Number) { + return JSONObject.numberToString((Number) o1); + } else if (o1 instanceof Boolean) { + return o1.toString(); + } else if (o1 instanceof JSONObject) { return ((JSONObject) o1).toString(); } else if (o1 instanceof JSONArray) { return ((JSONArray) o1).toString(); @@ -67,12 +67,12 @@ public class Jsonize implements Function { return new JSONArray((Collection) o1).toString(); } else if (o1.getClass().isArray()) { return new JSONArray(o1).toString(); - } else { - return JSONObject.quote(o1.toString()); - } - } catch (JSONException e) { - throw new RuntimeException(e); - } + } else { + return JSONObject.quote(o1.toString()); + } + } catch (JSONException e) { + throw new RuntimeException(e); + } } return null; } diff --git a/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java b/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java index d4eff6781..d0090cfa2 100644 --- a/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java +++ b/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java @@ -44,7 +44,7 @@ public class ArgsToArray implements Function { @Override public Object call(Properties bindings, Object[] args) { - return args; + return args; } @Override diff --git a/main/src/com/google/refine/grel/ControlFunctionRegistry.java b/main/src/com/google/refine/grel/ControlFunctionRegistry.java index 26affe98a..66fc1e87f 100644 --- a/main/src/com/google/refine/grel/ControlFunctionRegistry.java +++ b/main/src/com/google/refine/grel/ControlFunctionRegistry.java @@ -232,7 +232,7 @@ public class ControlFunctionRegistry { registerFunction("htmlAttr", new HtmlAttr()); registerFunction("htmlText", new HtmlText()); registerFunction("innerHtml", new InnerHtml()); - registerFunction("ownText", new OwnText()); + registerFunction("ownText", new OwnText()); registerFunction("indexOf", new IndexOf()); registerFunction("lastIndexOf", new LastIndexOf()); diff --git a/main/src/com/google/refine/grel/Parser.java b/main/src/com/google/refine/grel/Parser.java index 7dd7c15f5..bff82130b 100644 --- a/main/src/com/google/refine/grel/Parser.java +++ b/main/src/com/google/refine/grel/Parser.java @@ -238,7 +238,7 @@ public class Parser { throw makeException("Missing )"); } } else if (_token.type == TokenType.Delimiter && _token.text.equals("[")) { // [ ... ] array - next(true); // swallow [ + next(true); // swallow [ List args = parseExpressionList("]"); diff --git a/main/src/com/google/refine/grel/controls/Filter.java b/main/src/com/google/refine/grel/controls/Filter.java index 4b993aa6b..d41e7b8db 100644 --- a/main/src/com/google/refine/grel/controls/Filter.java +++ b/main/src/com/google/refine/grel/controls/Filter.java @@ -117,7 +117,7 @@ public class Filter implements Control { Object r = args[2].evaluate(bindings); if (r instanceof Boolean && ((Boolean) r).booleanValue()) { - results.add(v); + results.add(v); } } } diff --git a/main/src/com/google/refine/grel/controls/ForEachIndex.java b/main/src/com/google/refine/grel/controls/ForEachIndex.java index e7620c2b5..7abe1a912 100644 --- a/main/src/com/google/refine/grel/controls/ForEachIndex.java +++ b/main/src/com/google/refine/grel/controls/ForEachIndex.java @@ -120,9 +120,9 @@ public class ForEachIndex implements Control { results = new ArrayList(list.size()); for (int i = 0; i < list.size(); i++) { - Object v = list.get(i); - - bindings.put(indexName, i); + Object v = list.get(i); + + bindings.put(indexName, i); bindings.put(elementName, v); Object r = args[3].evaluate(bindings); diff --git a/main/src/com/google/refine/grel/controls/ForRange.java b/main/src/com/google/refine/grel/controls/ForRange.java index 5a37a28af..f1a009fe9 100644 --- a/main/src/com/google/refine/grel/controls/ForRange.java +++ b/main/src/com/google/refine/grel/controls/ForRange.java @@ -87,7 +87,7 @@ public class ForRange implements Control { double to = ((Number) toO).doubleValue(); while (from < to) { - bindings.put(indexName, from); + bindings.put(indexName, from); Object r = args[4].evaluate(bindings); @@ -101,7 +101,7 @@ public class ForRange implements Control { double to = ((Number) toO).doubleValue(); while (from < to) { - bindings.put(indexName, from); + bindings.put(indexName, from); Object r = args[4].evaluate(bindings); @@ -124,13 +124,13 @@ public class ForRange implements Control { } static private boolean isIntegral(Number o) { - if (o instanceof Integer || o instanceof Long) { - return true; - } else { - return (o.doubleValue() - o.longValue()) == 0; - } + if (o instanceof Integer || o instanceof Long) { + return true; + } else { + return (o.doubleValue() - o.longValue()) == 0; + } } - + @Override public void write(JSONWriter writer, Properties options) throws JSONException { diff --git a/main/src/com/google/refine/model/ModelException.java b/main/src/com/google/refine/model/ModelException.java index dbee0a7e3..e65a1963b 100644 --- a/main/src/com/google/refine/model/ModelException.java +++ b/main/src/com/google/refine/model/ModelException.java @@ -34,25 +34,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; public class ModelException extends Exception { - private static final long serialVersionUID = -168448967638065467L; + private static final long serialVersionUID = -168448967638065467L; - public ModelException() { - // TODO Auto-generated constructor stub - } + public ModelException() { + // TODO Auto-generated constructor stub + } - public ModelException(String message) { - super(message); - // TODO Auto-generated constructor stub - } + public ModelException(String message) { + super(message); + // TODO Auto-generated constructor stub + } - public ModelException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } + public ModelException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } - public ModelException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } + public ModelException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } } diff --git a/main/src/com/google/refine/model/Record.java b/main/src/com/google/refine/model/Record.java index 283d18cae..e5185121c 100644 --- a/main/src/com/google/refine/model/Record.java +++ b/main/src/com/google/refine/model/Record.java @@ -34,17 +34,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; public class Record { - final public int fromRowIndex; - final public int toRowIndex; - final public int recordIndex; - - public Record( - int fromRowIndex, - int toRowIndex, - int recordIndex - ) { - this.fromRowIndex = fromRowIndex; - this.toRowIndex = toRowIndex; - this.recordIndex = recordIndex; - } + final public int fromRowIndex; + final public int toRowIndex; + final public int recordIndex; + + public Record( + int fromRowIndex, + int toRowIndex, + int recordIndex + ) { + this.fromRowIndex = fromRowIndex; + this.toRowIndex = toRowIndex; + this.recordIndex = recordIndex; + } } diff --git a/main/src/com/google/refine/model/RecordModel.java b/main/src/com/google/refine/model/RecordModel.java index 1eca769cb..3364cbae8 100644 --- a/main/src/com/google/refine/model/RecordModel.java +++ b/main/src/com/google/refine/model/RecordModel.java @@ -55,7 +55,7 @@ public class RecordModel implements Jsonizable { this.cellIndex = cellIndex; } } - + final static public class RowDependency { public int recordIndex; public CellDependency[] cellDependencies; diff --git a/main/src/com/google/refine/model/Row.java b/main/src/com/google/refine/model/Row.java index 4b5db9d7c..5284954c2 100644 --- a/main/src/com/google/refine/model/Row.java +++ b/main/src/com/google/refine/model/Row.java @@ -161,12 +161,12 @@ public class Row implements HasFields, Jsonizable { if (!"save".equals(options.getProperty("mode"))) { if (options.containsKey("rowIndex")) { - int rowIndex = (Integer) options.get("rowIndex"); + int rowIndex = (Integer) options.get("rowIndex"); writer.key("i"); writer.value(rowIndex); - + if (options.containsKey("recordIndex")) { - int recordIndex = (Integer) options.get("recordIndex"); - + int recordIndex = (Integer) options.get("recordIndex"); + writer.key("j"); writer.value(recordIndex); } } diff --git a/main/src/com/google/refine/model/changes/RowReorderChange.java b/main/src/com/google/refine/model/changes/RowReorderChange.java index c77fb2b4c..0a837f9e1 100644 --- a/main/src/com/google/refine/model/changes/RowReorderChange.java +++ b/main/src/com/google/refine/model/changes/RowReorderChange.java @@ -55,15 +55,15 @@ public class RowReorderChange implements Change { @Override public void apply(Project project) { synchronized (project) { - List oldRows = project.rows; - List newRows = new ArrayList(oldRows.size()); - - for (Integer oldIndex : _rowIndices) { - newRows.add(oldRows.get(oldIndex)); - } - - project.rows.clear(); - project.rows.addAll(newRows); + List oldRows = project.rows; + List newRows = new ArrayList(oldRows.size()); + + for (Integer oldIndex : _rowIndices) { + newRows.add(oldRows.get(oldIndex)); + } + + project.rows.clear(); + project.rows.addAll(newRows); project.update(); } } @@ -71,23 +71,23 @@ public class RowReorderChange implements Change { @Override public void revert(Project project) { synchronized (project) { - int count = project.rows.size(); - - List newRows = project.rows; - List oldRows = new ArrayList(count); - - for (int r = 0; r < count; r++) { - oldRows.add(null); - } - - for (int newIndex = 0; newIndex < count; newIndex++) { - int oldIndex = _rowIndices.get(newIndex); - Row row = newRows.get(newIndex); - oldRows.set(oldIndex, row); - } - - project.rows.clear(); - project.rows.addAll(oldRows); + int count = project.rows.size(); + + List newRows = project.rows; + List oldRows = new ArrayList(count); + + for (int r = 0; r < count; r++) { + oldRows.add(null); + } + + for (int newIndex = 0; newIndex < count; newIndex++) { + int oldIndex = _rowIndices.get(newIndex); + Row row = newRows.get(newIndex); + oldRows.set(oldIndex, row); + } + + project.rows.clear(); + project.rows.addAll(oldRows); project.update(); } } diff --git a/main/src/com/google/refine/operations/cell/BlankDownOperation.java b/main/src/com/google/refine/operations/cell/BlankDownOperation.java index bde30c22b..3828cd9cb 100644 --- a/main/src/com/google/refine/operations/cell/BlankDownOperation.java +++ b/main/src/com/google/refine/operations/cell/BlankDownOperation.java @@ -108,15 +108,15 @@ public class BlankDownOperation extends EngineDependentMassCellOperation { this.cellChanges = cellChanges; return this; } - + @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/cell/FillDownOperation.java b/main/src/com/google/refine/operations/cell/FillDownOperation.java index 88c87e773..b6b7bd1b5 100644 --- a/main/src/com/google/refine/operations/cell/FillDownOperation.java +++ b/main/src/com/google/refine/operations/cell/FillDownOperation.java @@ -111,12 +111,12 @@ public class FillDownOperation extends EngineDependentMassCellOperation { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/cell/MassEditOperation.java b/main/src/com/google/refine/operations/cell/MassEditOperation.java index 03e976d3c..a5ef0e84c 100644 --- a/main/src/com/google/refine/operations/cell/MassEditOperation.java +++ b/main/src/com/google/refine/operations/cell/MassEditOperation.java @@ -238,12 +238,12 @@ public class MassEditOperation extends EngineDependentMassCellOperation { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/cell/TextTransformOperation.java b/main/src/com/google/refine/operations/cell/TextTransformOperation.java index 262e7c4f8..c1939b9bd 100644 --- a/main/src/com/google/refine/operations/cell/TextTransformOperation.java +++ b/main/src/com/google/refine/operations/cell/TextTransformOperation.java @@ -161,29 +161,29 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } - + @Override public boolean visit(Project project, int rowIndex, Row row) { Cell cell = row.getCell(cellIndex); Cell newCell = null; - + Object oldValue = cell != null ? cell.value : null; ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); - + Object o = eval.evaluate(bindings); if (o == null) { - if (oldValue != null) { + if (oldValue != null) { CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, null); cellChanges.add(cellChange); - } + } } else { if (o instanceof Cell) { newCell = (Cell) o; diff --git a/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java b/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java index 9b0182b01..9451c61d5 100644 --- a/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java @@ -180,12 +180,12 @@ public class ColumnAdditionOperation extends EngineDependentOperation { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/column/ColumnSplitOperation.java b/main/src/com/google/refine/operations/column/ColumnSplitOperation.java index 9d4aaadbc..4200fc8ee 100644 --- a/main/src/com/google/refine/operations/column/ColumnSplitOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnSplitOperation.java @@ -277,12 +277,12 @@ public class ColumnSplitOperation extends EngineDependentOperation { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java b/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java index cb36ad2ad..fe455a322 100644 --- a/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java @@ -122,12 +122,12 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java b/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java index 1f2071b61..fba72ba4e 100644 --- a/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java @@ -125,12 +125,12 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java b/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java index e149cffe2..84dbae15c 100644 --- a/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java @@ -116,14 +116,14 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } - + @Override public boolean visit(Project project, int rowIndex, Row row) { if (cellIndex < row.cells.size()) { diff --git a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java index 75270aa6b..ecb94d33d 100644 --- a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java @@ -161,14 +161,14 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } - + @Override public boolean visit(Project project, int rowIndex, Row row) { Cell cell = row.getCell(cellIndex); diff --git a/main/src/com/google/refine/operations/recon/ReconOperation.java b/main/src/com/google/refine/operations/recon/ReconOperation.java index f0bb18c7f..102043516 100644 --- a/main/src/com/google/refine/operations/recon/ReconOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconOperation.java @@ -222,12 +222,12 @@ public class ReconOperation extends EngineDependentOperation { filteredRows.accept(_project, new RowVisitor() { @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/row/DenormalizeOperation.java b/main/src/com/google/refine/operations/row/DenormalizeOperation.java index 67aa297d7..c43e3cdef 100644 --- a/main/src/com/google/refine/operations/row/DenormalizeOperation.java +++ b/main/src/com/google/refine/operations/row/DenormalizeOperation.java @@ -87,20 +87,20 @@ public void write(JSONWriter writer, Properties options) RowDependency rd = project.recordModel.getRowDependency(r); if (rd.cellDependencies != null) { newRow = oldRow.dup(); - + for (int c = 0; c < rd.cellDependencies.length; c++) { - CellDependency cd = rd.cellDependencies[c]; - if (cd != null) { - int contextRowIndex = cd.rowIndex; - int contextCellIndex = cd.cellIndex; - - if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) { - Row contextRow = oldRows.get(contextRowIndex); - Cell contextCell = contextRow.getCell(contextCellIndex); - - newRow.setCell(contextCellIndex, contextCell); - } - } + CellDependency cd = rd.cellDependencies[c]; + if (cd != null) { + int contextRowIndex = cd.rowIndex; + int contextCellIndex = cd.cellIndex; + + if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) { + Row contextRow = oldRows.get(contextRowIndex); + Cell contextCell = contextRow.getCell(contextCellIndex); + + newRow.setCell(contextCellIndex, contextCell); + } + } } } diff --git a/main/src/com/google/refine/operations/row/RowFlagOperation.java b/main/src/com/google/refine/operations/row/RowFlagOperation.java index 2628abf04..860197daf 100644 --- a/main/src/com/google/refine/operations/row/RowFlagOperation.java +++ b/main/src/com/google/refine/operations/row/RowFlagOperation.java @@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/operations/row/RowRemovalOperation.java b/main/src/com/google/refine/operations/row/RowRemovalOperation.java index f41ecf3af..aea4e0b48 100644 --- a/main/src/com/google/refine/operations/row/RowRemovalOperation.java +++ b/main/src/com/google/refine/operations/row/RowRemovalOperation.java @@ -107,17 +107,17 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) this.rowIndices = rowIndices; return this; } - + @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } - + @Override public boolean visit(Project project, int rowIndex, Row row) { rowIndices.add(rowIndex); diff --git a/main/src/com/google/refine/operations/row/RowReorderOperation.java b/main/src/com/google/refine/operations/row/RowReorderOperation.java index bc65d18e7..aa521bdd4 100644 --- a/main/src/com/google/refine/operations/row/RowReorderOperation.java +++ b/main/src/com/google/refine/operations/row/RowReorderOperation.java @@ -57,18 +57,18 @@ import com.google.refine.sorting.SortingRowVisitor; public class RowReorderOperation extends AbstractOperation { 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") ? - obj.getJSONObject("sorting") : null; - - return new RowReorderOperation(Engine.stringToMode(mode), sorting); + obj.getJSONObject("sorting") : null; + + return new RowReorderOperation(Engine.stringToMode(mode), sorting); } - - final protected Mode _mode; + + final protected Mode _mode; final protected JSONObject _sorting; - + public RowReorderOperation(Mode mode, JSONObject sorting) { - _mode = mode; + _mode = mode; _sorting = sorting; } @@ -98,65 +98,65 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) if (_mode == Mode.RowBased) { RowVisitor visitor = new IndexingVisitor(rowIndices); if (_sorting != null) { - SortingRowVisitor srv = new SortingRowVisitor(visitor); - - srv.initializeFromJSON(project, _sorting); - if (srv.hasCriteria()) { - visitor = srv; - } + SortingRowVisitor srv = new SortingRowVisitor(visitor); + + srv.initializeFromJSON(project, _sorting); + if (srv.hasCriteria()) { + visitor = srv; + } } - - engine.getAllRows().accept(project, visitor); + + engine.getAllRows().accept(project, visitor); } else { RecordVisitor visitor = new IndexingVisitor(rowIndices); if (_sorting != null) { - SortingRecordVisitor srv = new SortingRecordVisitor(visitor); - - srv.initializeFromJSON(project, _sorting); - if (srv.hasCriteria()) { - visitor = srv; - } + SortingRecordVisitor srv = new SortingRecordVisitor(visitor); + + srv.initializeFromJSON(project, _sorting); + if (srv.hasCriteria()) { + visitor = srv; + } } - engine.getAllRecords().accept(project, visitor); + engine.getAllRecords().accept(project, visitor); } return new HistoryEntry( - historyEntryID, - project, - "Reorder rows", - this, - new RowReorderChange(rowIndices) + historyEntryID, + project, + "Reorder rows", + this, + new RowReorderChange(rowIndices) ); - } - - static protected class IndexingVisitor implements RowVisitor, RecordVisitor { - List _indices; - - IndexingVisitor(List indices) { - _indices = indices; - } - - @Override - public void start(Project project) { - } + } - @Override - public void end(Project project) { - } + static protected class IndexingVisitor implements RowVisitor, RecordVisitor { + List _indices; - @Override - public boolean visit(Project project, int rowIndex, Row row) { - _indices.add(rowIndex); - return false; - } + IndexingVisitor(List indices) { + _indices = indices; + } - @Override - public boolean visit(Project project, Record record) { - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - _indices.add(r); - } - return false; - } - } + @Override + public void start(Project project) { + } + + @Override + 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; + } + } } diff --git a/main/src/com/google/refine/operations/row/RowStarOperation.java b/main/src/com/google/refine/operations/row/RowStarOperation.java index f293f95a5..cef3132b9 100644 --- a/main/src/com/google/refine/operations/row/RowStarOperation.java +++ b/main/src/com/google/refine/operations/row/RowStarOperation.java @@ -118,12 +118,12 @@ protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) @Override public void start(Project project) { - // nothing to do + // nothing to do } - + @Override public void end(Project project) { - // nothing to do + // nothing to do } @Override diff --git a/main/src/com/google/refine/sorting/BaseSorter.java b/main/src/com/google/refine/sorting/BaseSorter.java index 6a89b935e..403a049eb 100644 --- a/main/src/com/google/refine/sorting/BaseSorter.java +++ b/main/src/com/google/refine/sorting/BaseSorter.java @@ -44,130 +44,130 @@ import com.google.refine.model.Project; import com.google.refine.sorting.Criterion.KeyMaker; abstract public class BaseSorter { - protected Criterion[] _criteria; - protected KeyMaker[] _keyMakers; - protected ComparatorWrapper[] _comparatorWrappers; - protected List _keys; - - public class ComparatorWrapper { - final public int criterionIndex; - final protected int multiplier; - - public ComparatorWrapper(int criterionIndex) { - this.criterionIndex = criterionIndex; - this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1; - } - - public Object getKey(Project project, Object o, int index) { - while (index >= _keys.size()) { - _keys.add(null); - } - - Object[] keys = _keys.get(index); - if (keys == null) { - keys = makeKeys(project, o, index); - _keys.set(index, keys); - } - return keys[criterionIndex]; - } - - public int compare(Project project, Object o1, int i1, Object o2, int i2) { - Criterion c = _criteria[criterionIndex]; - Object key1 = getKey(project, o1, i1); - Object key2 = getKey(project, o2, i2); - - if (key1 == null) { - if (key2 == null) { - return 0; - } else if (key2 instanceof EvalError) { - return c.blankPosition - c.errorPosition; - } else { - return c.blankPosition; - } - } else if (key1 instanceof EvalError) { - if (key2 == null) { - return c.errorPosition - c.blankPosition; - } else if (key2 instanceof EvalError) { - return 0; - } else { - return c.errorPosition; - } - } else { - if (key2 == null) { - return -c.blankPosition; - } else if (key2 instanceof EvalError) { - return -c.errorPosition; - } else { - return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier; - } - } - } - } - - public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { - if (obj.has("criteria") && !obj.isNull("criteria")) { - JSONArray a = obj.getJSONArray("criteria"); - int count = a.length(); - - _criteria = new Criterion[count]; - _keyMakers = new KeyMaker[count]; - _comparatorWrappers = new ComparatorWrapper[count]; - - for (int i = 0; i < count; i++) { - JSONObject obj2 = a.getJSONObject(i); - - _criteria[i] = createCriterionFromJSON(project, obj2); - _keyMakers[i] = _criteria[i].createKeyMaker(); - _comparatorWrappers[i] = new ComparatorWrapper(i); - } - } else { - _criteria = new Criterion[0]; - _keyMakers = new KeyMaker[0]; - _comparatorWrappers = new ComparatorWrapper[0]; - } - } - - public boolean hasCriteria() { - return _criteria != null && _criteria.length > 0; - } - - protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException { - String valueType = "string"; - if (obj.has("valueType") && !obj.isNull("valueType")) { - valueType = obj.getString("valueType"); - } - - Criterion c = null; - if ("boolean".equals(valueType)) { - c = new BooleanCriterion(); - } else if ("date".equals(valueType)) { - c = new DateCriterion(); - } else if ("number".equals(valueType)) { - c = new NumberCriterion(); - } else { - c = new StringCriterion(); - } - - c.initializeFromJSON(project, obj); - return c; - } - - abstract protected Object makeKey( - Project project, KeyMaker keyMaker, Criterion c, Object o, int index); - - protected Object[] makeKeys(Project project, Object o, int index) { - Object[] keys = new Object[_keyMakers.length]; - for (int i = 0; i < keys.length; i++) { - keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index); - } - return keys; - } - - protected int compare(Project project, Object o1, int i1, Object o2, int i2) { - int c = 0; - for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) { - c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2); - } - return c; - } + protected Criterion[] _criteria; + protected KeyMaker[] _keyMakers; + protected ComparatorWrapper[] _comparatorWrappers; + protected List _keys; + + public class ComparatorWrapper { + final public int criterionIndex; + final protected int multiplier; + + public ComparatorWrapper(int criterionIndex) { + this.criterionIndex = criterionIndex; + this.multiplier = _criteria[criterionIndex].reverse ? -1 : 1; + } + + public Object getKey(Project project, Object o, int index) { + while (index >= _keys.size()) { + _keys.add(null); + } + + Object[] keys = _keys.get(index); + if (keys == null) { + keys = makeKeys(project, o, index); + _keys.set(index, keys); + } + return keys[criterionIndex]; + } + + public int compare(Project project, Object o1, int i1, Object o2, int i2) { + Criterion c = _criteria[criterionIndex]; + Object key1 = getKey(project, o1, i1); + Object key2 = getKey(project, o2, i2); + + if (key1 == null) { + if (key2 == null) { + return 0; + } else if (key2 instanceof EvalError) { + return c.blankPosition - c.errorPosition; + } else { + return c.blankPosition; + } + } else if (key1 instanceof EvalError) { + if (key2 == null) { + return c.errorPosition - c.blankPosition; + } else if (key2 instanceof EvalError) { + return 0; + } else { + return c.errorPosition; + } + } else { + if (key2 == null) { + return -c.blankPosition; + } else if (key2 instanceof EvalError) { + return -c.errorPosition; + } else { + return _keyMakers[criterionIndex].compareKeys(key1, key2) * multiplier; + } + } + } + } + + public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { + if (obj.has("criteria") && !obj.isNull("criteria")) { + JSONArray a = obj.getJSONArray("criteria"); + int count = a.length(); + + _criteria = new Criterion[count]; + _keyMakers = new KeyMaker[count]; + _comparatorWrappers = new ComparatorWrapper[count]; + + for (int i = 0; i < count; i++) { + JSONObject obj2 = a.getJSONObject(i); + + _criteria[i] = createCriterionFromJSON(project, obj2); + _keyMakers[i] = _criteria[i].createKeyMaker(); + _comparatorWrappers[i] = new ComparatorWrapper(i); + } + } else { + _criteria = new Criterion[0]; + _keyMakers = new KeyMaker[0]; + _comparatorWrappers = new ComparatorWrapper[0]; + } + } + + public boolean hasCriteria() { + return _criteria != null && _criteria.length > 0; + } + + protected Criterion createCriterionFromJSON(Project project, JSONObject obj) throws JSONException { + String valueType = "string"; + if (obj.has("valueType") && !obj.isNull("valueType")) { + valueType = obj.getString("valueType"); + } + + Criterion c = null; + if ("boolean".equals(valueType)) { + c = new BooleanCriterion(); + } else if ("date".equals(valueType)) { + c = new DateCriterion(); + } else if ("number".equals(valueType)) { + c = new NumberCriterion(); + } else { + c = new StringCriterion(); + } + + c.initializeFromJSON(project, obj); + return c; + } + + abstract protected Object makeKey( + Project project, KeyMaker keyMaker, Criterion c, Object o, int index); + + protected Object[] makeKeys(Project project, Object o, int index) { + Object[] keys = new Object[_keyMakers.length]; + for (int i = 0; i < keys.length; i++) { + keys[i] = makeKey(project, _keyMakers[i], _criteria[i], o, index); + } + return keys; + } + + protected int compare(Project project, Object o1, int i1, Object o2, int i2) { + int c = 0; + for (int i = 0; c == 0 && i < _comparatorWrappers.length; i++) { + c = _comparatorWrappers[i].compare(project, o1, i1, o2, i2); + } + return c; + } } diff --git a/main/src/com/google/refine/sorting/SortingRecordVisitor.java b/main/src/com/google/refine/sorting/SortingRecordVisitor.java index c57e0cfbf..7999a06d7 100644 --- a/main/src/com/google/refine/sorting/SortingRecordVisitor.java +++ b/main/src/com/google/refine/sorting/SortingRecordVisitor.java @@ -44,55 +44,55 @@ import com.google.refine.model.Record; import com.google.refine.sorting.Criterion.KeyMaker; public class SortingRecordVisitor extends BaseSorter implements RecordVisitor { - final protected RecordVisitor _visitor; - protected List _records; - - public SortingRecordVisitor(RecordVisitor visitor) { - _visitor = visitor; - } + final protected RecordVisitor _visitor; + protected List _records; - @Override - public void start(Project project) { - int count = project.recordModel.getRecordCount(); - _records = new ArrayList(count); - _keys = new ArrayList(count); - } + public SortingRecordVisitor(RecordVisitor visitor) { + _visitor = visitor; + } - @Override - public void end(Project project) { - _visitor.start(project); - - Collections.sort(_records, new Comparator() { - Project project; - - Comparator 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 + public void start(Project project) { + int count = project.recordModel.getRecordCount(); + _records = new ArrayList(count); + _keys = new ArrayList(count); + } - @Override - public boolean visit(Project project, Record record) { - _records.add(record); - return false; - } + @Override + public void end(Project project) { + _visitor.start(project); - @Override - protected Object makeKey( - Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { - - return keyMaker.makeKey(project, (Record) o); - } + Collections.sort(_records, new Comparator() { + Project project; + + Comparator 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 + 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); + } } diff --git a/main/src/com/google/refine/sorting/SortingRowVisitor.java b/main/src/com/google/refine/sorting/SortingRowVisitor.java index 5c84a82f3..caa2dcfb2 100644 --- a/main/src/com/google/refine/sorting/SortingRowVisitor.java +++ b/main/src/com/google/refine/sorting/SortingRowVisitor.java @@ -44,65 +44,65 @@ import com.google.refine.model.Row; import com.google.refine.sorting.Criterion.KeyMaker; public class SortingRowVisitor extends BaseSorter implements RowVisitor { - final protected RowVisitor _visitor; - protected List _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; - } + final protected RowVisitor _visitor; + protected List _indexedRows; - @Override - public void start(Project project) { - int count = project.rows.size(); - _indexedRows = new ArrayList(count); - _keys = new ArrayList(count); - } + static protected class IndexedRow { + final int index; + final Row row; - @Override - public void end(Project project) { - _visitor.start(project); - - Collections.sort(_indexedRows, new Comparator() { - Project project; - - Comparator 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); - } + IndexedRow(int index, Row row) { + this.index = index; + this.row = row; + } + } - @Override - public boolean visit(Project project, int rowIndex, Row row) { - _indexedRows.add(new IndexedRow(rowIndex, row)); - return false; - } + public SortingRowVisitor(RowVisitor visitor) { + _visitor = visitor; + } - @Override - protected Object makeKey( - Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { - - return keyMaker.makeKey(project, (Row) o, index); - } + @Override + public void start(Project project) { + int count = project.rows.size(); + _indexedRows = new ArrayList(count); + _keys = new ArrayList(count); + } + + @Override + public void end(Project project) { + _visitor.start(project); + + Collections.sort(_indexedRows, new Comparator() { + Project project; + + Comparator 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); + } } diff --git a/main/src/com/google/refine/templating/DynamicFragment.java b/main/src/com/google/refine/templating/DynamicFragment.java index 4ca3c32db..8c8a25926 100644 --- a/main/src/com/google/refine/templating/DynamicFragment.java +++ b/main/src/com/google/refine/templating/DynamicFragment.java @@ -36,9 +36,9 @@ package com.google.refine.templating; import com.google.refine.expr.Evaluable; class DynamicFragment extends Fragment { - final public Evaluable eval; - - public DynamicFragment(Evaluable eval) { - this.eval = eval; - } + final public Evaluable eval; + + public DynamicFragment(Evaluable eval) { + this.eval = eval; + } } diff --git a/main/src/com/google/refine/templating/Parser.java b/main/src/com/google/refine/templating/Parser.java index 980a71dd6..c47996be4 100644 --- a/main/src/com/google/refine/templating/Parser.java +++ b/main/src/com/google/refine/templating/Parser.java @@ -42,63 +42,63 @@ import com.google.refine.grel.ast.FieldAccessorExpr; import com.google.refine.grel.ast.VariableExpr; public class Parser { - static public Template parse(String s) throws ParsingException { - List fragments = new ArrayList(); - - 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))); + static public Template parse(String s) throws ParsingException { + List fragments = new ArrayList(); - continue; - } - } - - current++; - } - - if (start < s.length()) { - fragments.add(new StaticFragment(s.substring(start))); - } - - return new Template(fragments); - } + 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; + } + } + + current++; + } + + if (start < s.length()) { + fragments.add(new StaticFragment(s.substring(start))); + } + + return new Template(fragments); + } } diff --git a/main/src/com/google/refine/templating/StaticFragment.java b/main/src/com/google/refine/templating/StaticFragment.java index 08109a182..c151d9e32 100644 --- a/main/src/com/google/refine/templating/StaticFragment.java +++ b/main/src/com/google/refine/templating/StaticFragment.java @@ -34,9 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.templating; class StaticFragment extends Fragment { - final public String text; - - public StaticFragment(String text) { - this.text = text; - } + final public String text; + + public StaticFragment(String text) { + this.text = text; + } } diff --git a/main/src/com/google/refine/templating/Template.java b/main/src/com/google/refine/templating/Template.java index 44ef2731e..8e9f40073 100644 --- a/main/src/com/google/refine/templating/Template.java +++ b/main/src/com/google/refine/templating/Template.java @@ -47,160 +47,160 @@ import com.google.refine.model.Record; import com.google.refine.model.Row; public class Template { - protected String _prefix; - protected String _suffix; - protected String _separator; - - protected List _fragments; - - public Template(List fragments) { - _fragments = fragments; - } - - public void setPrefix(String prefix) { - _prefix = prefix; - } - - public void setSuffix(String suffix) { - _suffix = suffix; - } - - public void setSeparator(String separator) { - _separator = separator; - } - - public RowVisitor getRowVisitor(Writer writer, int limit) { - return get(writer, limit); - } - - public RecordVisitor getRecordVisitor(Writer writer, int limit) { - return get(writer, limit); - } - - protected RowWritingVisitor get(Writer writer, int limit) { - return new RowWritingVisitor(writer, limit); - } - + protected String _prefix; + protected String _suffix; + protected String _separator; + + protected List _fragments; + + public Template(List fragments) { + _fragments = fragments; + } + + public void setPrefix(String prefix) { + _prefix = prefix; + } + + public void setSuffix(String suffix) { + _suffix = suffix; + } + + public void setSeparator(String separator) { + _separator = separator; + } + + public RowVisitor getRowVisitor(Writer writer, int limit) { + return get(writer, limit); + } + + public RecordVisitor getRecordVisitor(Writer writer, int limit) { + return get(writer, limit); + } + + protected RowWritingVisitor get(Writer writer, int limit) { + return new RowWritingVisitor(writer, limit); + } + protected class RowWritingVisitor implements RowVisitor, RecordVisitor { - final protected int limit; - final protected Writer writer; - protected Properties bindings; - + final protected int limit; + final protected Writer writer; + protected Properties bindings; + public int total; - + public RowWritingVisitor(Writer writer, int limit) { this.limit = limit; this.writer = writer; } - + @Override public void start(Project project) { - bindings = ExpressionUtils.createBindings(project); - - try { - if (_prefix != null) { - writer.write(_prefix); - } - } catch (IOException e) { - // ignore + bindings = ExpressionUtils.createBindings(project); + + try { + if (_prefix != null) { + writer.write(_prefix); + } + } catch (IOException e) { + // ignore } } - + @Override public void end(Project project) { - try { - if (_suffix != null) { - writer.write(_suffix); - } - } catch (IOException e) { - // ignore + try { + if (_suffix != null) { + writer.write(_suffix); + } + } catch (IOException e) { + // ignore } } - + @Override public boolean visit(Project project, int rowIndex, Row row) { if (limit <= 0 || total < limit) { internalVisit(project, rowIndex, row); } - total++; - + total++; + return limit > 0 && total >= limit; } - + @Override public boolean visit(Project project, Record record) { if (limit <= 0 || total < limit) { internalVisit(project, record); } - total++; - + total++; + return limit > 0 && total >= limit; } - + protected void writeValue(Object v) throws IOException { - if (v == null) { - writer.write("null"); - } else if (ExpressionUtils.isError(v)) { - writer.write("null"); - //writer.write("[Error: " + ((EvalError) v).message); - } else if (v instanceof String) { - writer.write((String) v); - } else { - writer.write(v.toString()); - } + if (v == null) { + writer.write("null"); + } else if (ExpressionUtils.isError(v)) { + writer.write("null"); + //writer.write("[Error: " + ((EvalError) v).message); + } else if (v instanceof String) { + writer.write((String) v); + } else { + writer.write(v.toString()); + } } - + public boolean internalVisit(Project project, int rowIndex, Row row) { - try { - if (total > 0 && _separator != null) { - writer.write(_separator); - } - - ExpressionUtils.bind(bindings, row, rowIndex, null, null); - for (Fragment f : _fragments) { - if (f instanceof StaticFragment) { - writer.write(((StaticFragment) f).text); - } else { - DynamicFragment df = (DynamicFragment) f; - Object value = df.eval.evaluate(bindings); - - if (value != null && ExpressionUtils.isArrayOrCollection(value)) { - if (ExpressionUtils.isArray(value)) { - Object[] a = (Object[]) value; - for (Object v : a) { - writeValue(v); - } - } else { - Collection a = ExpressionUtils.toObjectCollection(value); - for (Object v : a) { - writeValue(v); - } - } - continue; - } - - writeValue(value); - } - } - } catch (IOException e) { - // ignore - } + try { + if (total > 0 && _separator != null) { + writer.write(_separator); + } + + ExpressionUtils.bind(bindings, row, rowIndex, null, null); + for (Fragment f : _fragments) { + if (f instanceof StaticFragment) { + writer.write(((StaticFragment) f).text); + } else { + DynamicFragment df = (DynamicFragment) f; + Object value = df.eval.evaluate(bindings); + + if (value != null && ExpressionUtils.isArrayOrCollection(value)) { + if (ExpressionUtils.isArray(value)) { + Object[] a = (Object[]) value; + for (Object v : a) { + writeValue(v); + } + } else { + Collection a = ExpressionUtils.toObjectCollection(value); + for (Object v : a) { + writeValue(v); + } + } + continue; + } + + writeValue(value); + } + } + } catch (IOException e) { + // ignore + } return false; } - + protected boolean internalVisit(Project project, Record record) { bindings.put("recordIndex", record.recordIndex); - - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - Row row = project.rows.get(r); - + + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + Row row = project.rows.get(r); + bindings.put("rowIndex", r); - + internalVisit(project, r, row); - + bindings.remove("recordIndex"); - } - return false; + } + return false; } } diff --git a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java index f98901862..94e9f4660 100644 --- a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java @@ -117,16 +117,16 @@ public class HtmlExporterTests extends RefineTest { } Assert.assertEquals(writer.toString(), "\n" + - "" + TEST_PROJECT_NAME + "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "
column0column1
row0cell0row0cell1
row1cell0row1cell1
\n" + - "\n" + - "\n"); - + "" + TEST_PROJECT_NAME + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
column0column1
row0cell0row0cell1
row1cell0row1cell1
\n" + + "\n" + + "\n"); + } // TODO: This test fails because the HTML table exporter diff --git a/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java b/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java index 7db788fe6..536792ed7 100644 --- a/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java @@ -51,7 +51,7 @@ import com.google.refine.importers.tree.TreeReader.Token; import com.google.refine.model.Row; public class JsonImporterTests extends ImporterTest { - @Override + @Override @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); @@ -270,8 +270,9 @@ public class JsonImporterTests extends ImporterTest { sb.append("["); for(int i = 1; i < 7; i++){ sb.append(getTypicalElement(i)); - if(i < 6) - sb.append(","); + if(i < 6) { + sb.append(","); + } } sb.append("]"); return sb.toString(); @@ -282,12 +283,12 @@ public class JsonImporterTests extends ImporterTest { sb.append("["); for(int i = 1; i < 7; i++){ sb.append(getElementWithDuplicateSubElement(i)); - if(i < 6) - sb.append(","); + if(i < 6) { + sb.append(","); + } } sb.append("]"); return sb.toString(); - } public static String getSampleWithLineBreak(){ @@ -336,8 +337,9 @@ public class JsonImporterTests extends ImporterTest { "\"title\" : \"Book title " + i + "\"," + "\"publish_date\" : \"2010-05-26\"" + "}"); - if(i < 6) - sb.append(","); + if(i < 6) { + sb.append(","); + } } sb.append("]"); return sb.toString();