From f3f6a2846be2f369a32aa0f65af62ec8cd025603 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Mon, 19 Nov 2018 16:34:29 +0000 Subject: [PATCH] Migrate RowFilters to Jackson --- .../filters/ExpressionEqualRowFilter.java | 33 +++++++------------ .../ExpressionNumberComparisonRowFilter.java | 19 ++++------- .../ExpressionStringComparisonRowFilter.java | 19 ++++------- 3 files changed, 26 insertions(+), 45 deletions(-) diff --git a/main/src/com/google/refine/browsing/filters/ExpressionEqualRowFilter.java b/main/src/com/google/refine/browsing/filters/ExpressionEqualRowFilter.java index 30ec6b7e0..c97861c81 100644 --- a/main/src/com/google/refine/browsing/filters/ExpressionEqualRowFilter.java +++ b/main/src/com/google/refine/browsing/filters/ExpressionEqualRowFilter.java @@ -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,17 +121,13 @@ 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))) { - return true; - } - } catch (JSONException e) { - // ignore + if (testValue(JsonValueConverter.convert(a.get(i)))) { + return true; } } return false; @@ -165,17 +160,13 @@ 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))) { - return false; - } - } catch (JSONException e) { - // ignore + if (testValue(JsonValueConverter.convert(a.get(i)))) { + return false; } } return true; diff --git a/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java b/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java index fbb0684a8..bd236229a 100644 --- a/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java +++ b/main/src/com/google/refine/browsing/filters/ExpressionNumberComparisonRowFilter.java @@ -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,17 +92,13 @@ 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))) { - return true; - } - } catch (JSONException e) { - // ignore + if (checkValue(JsonValueConverter.convert(a.get(i)))) { + return true; } } return false; diff --git a/main/src/com/google/refine/browsing/filters/ExpressionStringComparisonRowFilter.java b/main/src/com/google/refine/browsing/filters/ExpressionStringComparisonRowFilter.java index 498534ec4..1bfc70c96 100644 --- a/main/src/com/google/refine/browsing/filters/ExpressionStringComparisonRowFilter.java +++ b/main/src/com/google/refine/browsing/filters/ExpressionStringComparisonRowFilter.java @@ -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,17 +85,13 @@ 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())) { - return !invert; - } - } catch (JSONException e) { - // ignore + if (checkValue(JsonValueConverter.convert(a.get(i)).toString())) { + return !invert; } } return invert;