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;
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();
}

View File

@ -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);
}
};
}
}