From 3d6458a0e55f56facf93e66b170a1155274f0835 Mon Sep 17 00:00:00 2001 From: Tom Morris Date: Sat, 27 Nov 2010 01:38:32 +0000 Subject: [PATCH] Replace tabs with spaces git-svn-id: http://google-refine.googlecode.com/svn/trunk@1934 7d457c2a-affb-35e4-300a-418c747d4874 --- .../com/google/refine/sorting/Criterion.java | 163 +++++++++--------- .../google/refine/sorting/DateCriterion.java | 50 +++--- 2 files changed, 107 insertions(+), 106 deletions(-) diff --git a/main/src/com/google/refine/sorting/Criterion.java b/main/src/com/google/refine/sorting/Criterion.java index 4d8cddf89..544b9d84a 100644 --- a/main/src/com/google/refine/sorting/Criterion.java +++ b/main/src/com/google/refine/sorting/Criterion.java @@ -43,85 +43,86 @@ import com.google.refine.model.Record; import com.google.refine.model.Row; abstract public class Criterion { - public String columnName; - protected int cellIndex; - - // These take on positive and negative values to indicate where blanks and errors - // go relative to non-blank values. They are also relative to each another. - // Blanks and errors are not affected by the reverse flag. - public int blankPosition = 1; - public int errorPosition = 2; - - public boolean reverse; - - public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { - if (obj.has("column") && !obj.isNull("column")) { - columnName = obj.getString("column"); - - Column column = project.columnModel.getColumnByName(columnName); - cellIndex = column != null ? column.getCellIndex() : -1; - } - - if (obj.has("blankPosition") && !obj.isNull("blankPosition")) { - blankPosition = obj.getInt("blankPosition"); - } - if (obj.has("errorPosition") && !obj.isNull("errorPosition")) { - errorPosition = obj.getInt("errorPosition"); - } - - if (obj.has("reverse") && !obj.isNull("reverse")) { - reverse = obj.getBoolean("reverse"); - } - } - - abstract public class KeyMaker { - public Object makeKey(Project project, Record record) { - Object error = null; - Object finalKey = null; - - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - Object key = makeKey(project, project.rows.get(r), r); - if (ExpressionUtils.isError(key)) { - error = key; - } else if (ExpressionUtils.isNonBlankData(key)) { - if (finalKey == null) { - finalKey = key; - } else { - int c = compareKeys(finalKey, key); - if (reverse) { - if (c < 0) { // key > finalKey - finalKey = key; - } - } else { - if (c > 0) { // key < finalKey - finalKey = key; - } - } - } - } - } - - if (finalKey != null) { - return finalKey; - } else if (error != null) { - return error; - } else { - return null; - } - } - - public Object makeKey(Project project, Row row, int rowIndex) { - if (cellIndex < 0) { - return null; - } else { - Object value = row.getCellValue(cellIndex); - return makeKey(value); - } - } - - abstract public int compareKeys(Object key1, Object key2); - - abstract protected Object makeKey(Object value); - } - abstract public KeyMaker createKeyMaker(); + public String columnName; + protected int cellIndex; + + // These take on positive and negative values to indicate where blanks and errors + // go relative to non-blank values. They are also relative to each another. + // Blanks and errors are not affected by the reverse flag. + public int blankPosition = 1; + public int errorPosition = 2; + + public boolean reverse; + + public void initializeFromJSON(Project project, JSONObject obj) + throws JSONException { + if (obj.has("column") && !obj.isNull("column")) { + columnName = obj.getString("column"); + + Column column = project.columnModel.getColumnByName(columnName); + cellIndex = column != null ? column.getCellIndex() : -1; + } + + if (obj.has("blankPosition") && !obj.isNull("blankPosition")) { + blankPosition = obj.getInt("blankPosition"); + } + if (obj.has("errorPosition") && !obj.isNull("errorPosition")) { + errorPosition = obj.getInt("errorPosition"); + } + + if (obj.has("reverse") && !obj.isNull("reverse")) { + reverse = obj.getBoolean("reverse"); + } + } + + abstract public class KeyMaker { + public Object makeKey(Project project, Record record) { + Object error = null; + Object finalKey = null; + + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + Object key = makeKey(project, project.rows.get(r), r); + if (ExpressionUtils.isError(key)) { + error = key; + } else if (ExpressionUtils.isNonBlankData(key)) { + if (finalKey == null) { + finalKey = key; + } else { + int c = compareKeys(finalKey, key); + if (reverse) { + if (c < 0) { // key > finalKey + finalKey = key; + } + } else { + if (c > 0) { // key < finalKey + finalKey = key; + } + } + } + } + } + + if (finalKey != null) { + return finalKey; + } else if (error != null) { + return error; + } else { + return null; + } + } + + public Object makeKey(Project project, Row row, int rowIndex) { + if (cellIndex < 0) { + return null; + } else { + Object value = row.getCellValue(cellIndex); + return makeKey(value); + } + } + + abstract public int compareKeys(Object key1, Object key2); + + abstract protected Object makeKey(Object value); + } + abstract public KeyMaker createKeyMaker(); } diff --git a/main/src/com/google/refine/sorting/DateCriterion.java b/main/src/com/google/refine/sorting/DateCriterion.java index b3e47f46d..fcddee53e 100644 --- a/main/src/com/google/refine/sorting/DateCriterion.java +++ b/main/src/com/google/refine/sorting/DateCriterion.java @@ -40,29 +40,29 @@ import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; public class DateCriterion extends Criterion { - final static protected EvalError s_error = new EvalError("Not a date"); - - @Override - public KeyMaker createKeyMaker() { - return new KeyMaker() { - @Override - protected Object makeKey(Object value) { - if (ExpressionUtils.isNonBlankData(value)) { - if (value instanceof Date) { - return value; - } else if (value instanceof Calendar) { - return ((Calendar) value).getTime(); - } else { - return s_error; - } - } - return null; - } - - @Override - public int compareKeys(Object key1, Object key2) { - return ((Date) key1).compareTo((Date) key2); - } - }; - } + final static protected EvalError s_error = new EvalError("Not a date"); + + @Override + public KeyMaker createKeyMaker() { + return new KeyMaker() { + @Override + protected Object makeKey(Object value) { + if (ExpressionUtils.isNonBlankData(value)) { + if (value instanceof Date) { + return value; + } else if (value instanceof Calendar) { + return ((Calendar) value).getTime(); + } else { + return s_error; + } + } + return null; + } + + @Override + public int compareKeys(Object key1, Object key2) { + return ((Date) key1).compareTo((Date) key2); + } + }; + } }