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);
cellIndex = column != null ? column.getCellIndex() : -1; 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("blankPosition") && !obj.isNull("blankPosition")) {
} blankPosition = obj.getInt("blankPosition");
if (obj.has("errorPosition") && !obj.isNull("errorPosition")) { }
errorPosition = obj.getInt("errorPosition"); if (obj.has("errorPosition") && !obj.isNull("errorPosition")) {
} errorPosition = obj.getInt("errorPosition");
}
if (obj.has("reverse") && !obj.isNull("reverse")) {
reverse = obj.getBoolean("reverse"); if (obj.has("reverse") && !obj.isNull("reverse")) {
} reverse = obj.getBoolean("reverse");
} }
}
abstract public class KeyMaker {
public Object makeKey(Project project, Record record) { abstract public class KeyMaker {
Object error = null; public Object makeKey(Project project, Record record) {
Object finalKey = null; Object error = null;
Object finalKey = null;
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
Object key = makeKey(project, project.rows.get(r), r); for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
if (ExpressionUtils.isError(key)) { Object key = makeKey(project, project.rows.get(r), r);
error = key; if (ExpressionUtils.isError(key)) {
} else if (ExpressionUtils.isNonBlankData(key)) { error = key;
if (finalKey == null) { } else if (ExpressionUtils.isNonBlankData(key)) {
finalKey = key; if (finalKey == null) {
} else { finalKey = key;
int c = compareKeys(finalKey, key); } else {
if (reverse) { int c = compareKeys(finalKey, key);
if (c < 0) { // key > finalKey if (reverse) {
finalKey = key; if (c < 0) { // key > finalKey
} finalKey = key;
} else { }
if (c > 0) { // key < finalKey } else {
finalKey = key; if (c > 0) { // key < finalKey
} finalKey = key;
} }
} }
} }
} }
}
if (finalKey != null) {
return finalKey; if (finalKey != null) {
} else if (error != null) { return finalKey;
return error; } else if (error != null) {
} else { return error;
return null; } else {
} return null;
} }
}
public Object makeKey(Project project, Row row, int rowIndex) {
if (cellIndex < 0) { public Object makeKey(Project project, Row row, int rowIndex) {
return null; if (cellIndex < 0) {
} else { return null;
Object value = row.getCellValue(cellIndex); } else {
return makeKey(value); Object value = row.getCellValue(cellIndex);
} 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);
} }
}; };
} }
} }