Migrate RowFilters to Jackson

This commit is contained in:
Antonin Delpeuch 2018-11-19 16:34:29 +00:00
parent 2c5607b9fa
commit f3f6a2846b
3 changed files with 26 additions and 45 deletions

View File

@ -38,12 +38,11 @@ import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.browsing.RowFilter;
import com.google.refine.expr.Evaluable;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.expr.util.JsonValueConverter;
import com.google.refine.model.Cell;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
@ -122,18 +121,14 @@ public class ExpressionEqualRowFilter implements RowFilter {
}
}
return false;
} else if (value instanceof JSONArray) {
JSONArray a = (JSONArray) value;
int l = a.length();
} else if (value instanceof ArrayNode) {
ArrayNode a = (ArrayNode) value;
int l = a.size();
for (int i = 0; i < l; i++) {
try {
if (testValue(a.get(i))) {
if (testValue(JsonValueConverter.convert(a.get(i)))) {
return true;
}
} catch (JSONException e) {
// ignore
}
}
return false;
} // else, fall through
@ -165,18 +160,14 @@ public class ExpressionEqualRowFilter implements RowFilter {
}
}
return true;
} else if (value instanceof JSONArray) {
JSONArray a = (JSONArray) value;
int l = a.length();
} else if (value instanceof ArrayNode) {
ArrayNode a = (ArrayNode) value;
int l = a.size();
for (int i = 0; i < l; i++) {
try {
if (testValue(a.get(i))) {
if (testValue(JsonValueConverter.convert(a.get(i)))) {
return false;
}
} catch (JSONException e) {
// ignore
}
}
return true;
} // else, fall through

View File

@ -36,12 +36,11 @@ package com.google.refine.browsing.filters;
import java.util.Collection;
import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.browsing.RowFilter;
import com.google.refine.browsing.util.RowEvaluable;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.expr.util.JsonValueConverter;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
@ -93,18 +92,14 @@ abstract public class ExpressionNumberComparisonRowFilter implements RowFilter {
}
}
return false;
} else if (value instanceof JSONArray) {
JSONArray a = (JSONArray) value;
int l = a.length();
} else if (value instanceof ArrayNode) {
ArrayNode a = (ArrayNode) value;
int l = a.size();
for (int i = 0; i < l; i++) {
try {
if (checkValue(a.get(i))) {
if (checkValue(JsonValueConverter.convert(a.get(i)))) {
return true;
}
} catch (JSONException e) {
// ignore
}
}
return false;
} // else, fall through

View File

@ -36,12 +36,11 @@ package com.google.refine.browsing.filters;
import java.util.Collection;
import java.util.Properties;
import org.json.JSONArray;
import org.json.JSONException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.browsing.RowFilter;
import com.google.refine.expr.Evaluable;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.expr.util.JsonValueConverter;
import com.google.refine.model.Cell;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
@ -86,18 +85,14 @@ abstract public class ExpressionStringComparisonRowFilter implements RowFilter {
}
}
return invert;
} else if (value instanceof JSONArray) {
JSONArray a = (JSONArray) value;
int l = a.length();
} else if (value instanceof ArrayNode) {
ArrayNode a = (ArrayNode) value;
int l = a.size();
for (int i = 0; i < l; i++) {
try {
if (checkValue(a.get(i).toString())) {
if (checkValue(JsonValueConverter.convert(a.get(i)).toString())) {
return !invert;
}
} catch (JSONException e) {
// ignore
}
}
return invert;
} else {