Replace tabs with spaces

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1934 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2010-11-27 01:38:32 +00:00
parent bc8637f638
commit 3d6458a0e5
2 changed files with 107 additions and 106 deletions

View File

@ -43,85 +43,86 @@ import com.google.refine.model.Record;
import com.google.refine.model.Row; import com.google.refine.model.Row;
abstract public class Criterion { abstract public class Criterion {
public String columnName; public String columnName;
protected int cellIndex; protected int cellIndex;
// These take on positive and negative values to indicate where blanks and errors // 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. // go relative to non-blank values. They are also relative to each another.
// Blanks and errors are not affected by the reverse flag. // Blanks and errors are not affected by the reverse flag.
public int blankPosition = 1; public int blankPosition = 1;
public int errorPosition = 2; public int errorPosition = 2;
public boolean reverse; public boolean reverse;
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException { public void initializeFromJSON(Project project, JSONObject obj)
if (obj.has("column") && !obj.isNull("column")) { throws JSONException {
columnName = obj.getString("column"); if (obj.has("column") && !obj.isNull("column")) {
columnName = obj.getString("column");
Column column = project.columnModel.getColumnByName(columnName); Column column = project.columnModel.getColumnByName(columnName);
cellIndex = column != null ? column.getCellIndex() : -1; cellIndex = column != null ? column.getCellIndex() : -1;
} }
if (obj.has("blankPosition") && !obj.isNull("blankPosition")) { if (obj.has("blankPosition") && !obj.isNull("blankPosition")) {
blankPosition = obj.getInt("blankPosition"); blankPosition = obj.getInt("blankPosition");
} }
if (obj.has("errorPosition") && !obj.isNull("errorPosition")) { if (obj.has("errorPosition") && !obj.isNull("errorPosition")) {
errorPosition = obj.getInt("errorPosition"); errorPosition = obj.getInt("errorPosition");
} }
if (obj.has("reverse") && !obj.isNull("reverse")) { if (obj.has("reverse") && !obj.isNull("reverse")) {
reverse = obj.getBoolean("reverse"); reverse = obj.getBoolean("reverse");
} }
} }
abstract public class KeyMaker { abstract public class KeyMaker {
public Object makeKey(Project project, Record record) { public Object makeKey(Project project, Record record) {
Object error = null; Object error = null;
Object finalKey = null; Object finalKey = null;
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
Object key = makeKey(project, project.rows.get(r), r); Object key = makeKey(project, project.rows.get(r), r);
if (ExpressionUtils.isError(key)) { if (ExpressionUtils.isError(key)) {
error = key; error = key;
} else if (ExpressionUtils.isNonBlankData(key)) { } else if (ExpressionUtils.isNonBlankData(key)) {
if (finalKey == null) { if (finalKey == null) {
finalKey = key; finalKey = key;
} else { } else {
int c = compareKeys(finalKey, key); int c = compareKeys(finalKey, key);
if (reverse) { if (reverse) {
if (c < 0) { // key > finalKey if (c < 0) { // key > finalKey
finalKey = key; finalKey = key;
} }
} else { } else {
if (c > 0) { // key < finalKey if (c > 0) { // key < finalKey
finalKey = key; finalKey = key;
} }
} }
} }
} }
} }
if (finalKey != null) { if (finalKey != null) {
return finalKey; return finalKey;
} else if (error != null) { } else if (error != null) {
return error; return error;
} else { } else {
return null; return null;
} }
} }
public Object makeKey(Project project, Row row, int rowIndex) { public Object makeKey(Project project, Row row, int rowIndex) {
if (cellIndex < 0) { if (cellIndex < 0) {
return null; return null;
} else { } else {
Object value = row.getCellValue(cellIndex); Object value = row.getCellValue(cellIndex);
return makeKey(value); return makeKey(value);
} }
} }
abstract public int compareKeys(Object key1, Object key2); abstract public int compareKeys(Object key1, Object key2);
abstract protected Object makeKey(Object value); abstract protected Object makeKey(Object value);
} }
abstract public KeyMaker createKeyMaker(); abstract public KeyMaker createKeyMaker();
} }

View File

@ -40,29 +40,29 @@ import com.google.refine.expr.EvalError;
import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.ExpressionUtils;
public class DateCriterion extends Criterion { public class DateCriterion extends Criterion {
final static protected EvalError s_error = new EvalError("Not a date"); final static protected EvalError s_error = new EvalError("Not a date");
@Override @Override
public KeyMaker createKeyMaker() { public KeyMaker createKeyMaker() {
return new KeyMaker() { return new KeyMaker() {
@Override @Override
protected Object makeKey(Object value) { protected Object makeKey(Object value) {
if (ExpressionUtils.isNonBlankData(value)) { if (ExpressionUtils.isNonBlankData(value)) {
if (value instanceof Date) { if (value instanceof Date) {
return value; return value;
} else if (value instanceof Calendar) { } else if (value instanceof Calendar) {
return ((Calendar) value).getTime(); return ((Calendar) value).getTime();
} else { } else {
return s_error; return s_error;
} }
} }
return null; return null;
} }
@Override @Override
public int compareKeys(Object key1, Object key2) { public int compareKeys(Object key1, Object key2) {
return ((Date) key1).compareTo((Date) key2); return ((Date) key1).compareTo((Date) key2);
} }
}; };
} }
} }