Replace tabs with spaces. No functional change.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1947 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2010-12-05 20:50:03 +00:00
parent a560cb56df
commit 9aaa1c9919
3 changed files with 95 additions and 95 deletions

View File

@ -37,29 +37,29 @@ import com.google.refine.expr.EvalError;
import com.google.refine.expr.ExpressionUtils;
public class BooleanCriterion extends Criterion {
final static protected EvalError s_error = new EvalError("Not a boolean");
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
if (ExpressionUtils.isNonBlankData(value)) {
if (value instanceof Boolean) {
return value;
} else if (value instanceof String) {
return Boolean.parseBoolean((String) value);
} else {
return s_error;
}
}
return value;
}
@Override
public int compareKeys(Object key1, Object key2) {
return ((Boolean) key1).compareTo((Boolean) key2);
}
};
}
final static protected EvalError s_error = new EvalError("Not a boolean");
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
if (ExpressionUtils.isNonBlankData(value)) {
if (value instanceof Boolean) {
return value;
} else if (value instanceof String) {
return Boolean.parseBoolean((String) value);
} else {
return s_error;
}
}
return value;
}
@Override
public int compareKeys(Object key1, Object key2) {
return ((Boolean) key1).compareTo((Boolean) key2);
}
};
}
}

View File

@ -40,44 +40,44 @@ import com.google.refine.expr.EvalError;
import com.google.refine.expr.ExpressionUtils;
public class NumberCriterion extends Criterion {
final static protected EvalError s_error = new EvalError("Not a number");
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
if (ExpressionUtils.isNonBlankData(value)) {
if (value instanceof Number) {
return value;
} else if (value instanceof Boolean) {
return ((Boolean) value).booleanValue() ? 1 : 0;
} else if (value instanceof Date) {
return ((Date) value).getTime();
} else if (value instanceof Calendar) {
return ((Calendar) value).getTime().getTime();
} else if (value instanceof String) {
try {
double d = Double.parseDouble((String) value);
if (!Double.isNaN(d)) {
return d;
}
} catch (NumberFormatException e) {
// fall through
}
}
return s_error;
}
return value;
}
@Override
public int compareKeys(Object key1, Object key2) {
double d1 = ((Number) key1).doubleValue();
double d2 = ((Number) key2).doubleValue();
return d1 < d2 ? -1 : (d1 > d2 ? 1 : 0);
}
};
}
final static protected EvalError s_error = new EvalError("Not a number");
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
if (ExpressionUtils.isNonBlankData(value)) {
if (value instanceof Number) {
return value;
} else if (value instanceof Boolean) {
return ((Boolean) value).booleanValue() ? 1 : 0;
} else if (value instanceof Date) {
return ((Date) value).getTime();
} else if (value instanceof Calendar) {
return ((Calendar) value).getTime().getTime();
} else if (value instanceof String) {
try {
double d = Double.parseDouble((String) value);
if (!Double.isNaN(d)) {
return d;
}
} catch (NumberFormatException e) {
// fall through
}
}
return s_error;
}
return value;
}
@Override
public int compareKeys(Object key1, Object key2) {
double d1 = ((Number) key1).doubleValue();
double d2 = ((Number) key2).doubleValue();
return d1 < d2 ? -1 : (d1 > d2 ? 1 : 0);
}
};
}
}

View File

@ -40,34 +40,34 @@ import com.google.refine.expr.ExpressionUtils;
import com.google.refine.model.Project;
public class StringCriterion extends Criterion {
public boolean caseSensitive;
@Override
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
super.initializeFromJSON(project, obj);
if (obj.has("caseSensitive") && !obj.isNull("caseSensitive")) {
caseSensitive = obj.getBoolean("caseSensitive");
}
}
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
return (ExpressionUtils.isNonBlankData(value) && !(value instanceof String)) ?
value.toString() : value;
}
@Override
public int compareKeys(Object key1, Object key2) {
if (StringCriterion.this.caseSensitive) {
return ((String) key1).compareTo((String) key2);
} else {
return ((String) key1).compareToIgnoreCase((String) key2);
}
}
};
}
public boolean caseSensitive;
@Override
public void initializeFromJSON(Project project, JSONObject obj) throws JSONException {
super.initializeFromJSON(project, obj);
if (obj.has("caseSensitive") && !obj.isNull("caseSensitive")) {
caseSensitive = obj.getBoolean("caseSensitive");
}
}
@Override
public KeyMaker createKeyMaker() {
return new KeyMaker() {
@Override
protected Object makeKey(Object value) {
return (ExpressionUtils.isNonBlankData(value) && !(value instanceof String)) ?
value.toString() : value;
}
@Override
public int compareKeys(Object key1, Object key2) {
if (StringCriterion.this.caseSensitive) {
return ((String) key1).compareTo((String) key2);
} else {
return ((String) key1).compareToIgnoreCase((String) key2);
}
}
};
}
}