|
|
|
@ -17,8 +17,6 @@ package com.jayway.jsonpath;
|
|
|
|
|
import com.jayway.jsonpath.internal.Path; |
|
|
|
|
import com.jayway.jsonpath.internal.PathCompiler; |
|
|
|
|
import com.jayway.jsonpath.internal.token.PredicateContextImpl; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.Arrays; |
|
|
|
@ -37,8 +35,6 @@ import static com.jayway.jsonpath.internal.Utils.notNull;
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public class Criteria implements Predicate { |
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Criteria.class); |
|
|
|
|
|
|
|
|
|
private static final String[] OPERATORS = { |
|
|
|
|
CriteriaType.EQ.toString(), |
|
|
|
|
CriteriaType.GTE.toString(), |
|
|
|
@ -60,7 +56,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
@Override |
|
|
|
|
boolean eval(Object expected, Object model, PredicateContext ctx) { |
|
|
|
|
boolean res = (0 == safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -73,7 +68,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
@Override |
|
|
|
|
boolean eval(Object expected, Object model, PredicateContext ctx) { |
|
|
|
|
boolean res = (0 != safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -89,7 +83,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
boolean res = (0 > safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -105,7 +98,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
boolean res = (0 >= safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -121,7 +113,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
boolean res = (0 < safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -137,7 +128,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
boolean res = (0 <= safeCompare(expected, model)); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -157,7 +147,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", exps), res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -166,7 +155,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
boolean eval(Object expected, Object model, PredicateContext ctx) { |
|
|
|
|
Collection nexps = (Collection) expected; |
|
|
|
|
boolean res = !nexps.contains(model); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", nexps), res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -188,7 +176,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
res = ((String) model).contains((String)expected); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -211,11 +198,8 @@ public class Criteria implements Predicate {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (logger.isDebugEnabled()) |
|
|
|
|
logger.debug("[{}] {} [{}] => {}", join(", ", ctx.configuration().jsonProvider().toIterable(model)), name(), join(", ", exps), res); |
|
|
|
|
} else { |
|
|
|
|
res = false; |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", "<NOT AN ARRAY>", name(), join(", ", exps), res); |
|
|
|
|
} |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
@ -228,15 +212,11 @@ public class Criteria implements Predicate {
|
|
|
|
|
if (ctx.configuration().jsonProvider().isArray(model)) { |
|
|
|
|
int length = ctx.configuration().jsonProvider().length(model); |
|
|
|
|
res = (length == size); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("Array with size {} {} {} => {}", length, name(), size, res); |
|
|
|
|
} else if (model instanceof String) { |
|
|
|
|
int length = ((String) model).length(); |
|
|
|
|
res = length == size; |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("String with length {} {} {} => {}", length, name(), size, res); |
|
|
|
|
} else { |
|
|
|
|
res = false; |
|
|
|
|
if (logger.isDebugEnabled()) |
|
|
|
|
logger.debug("{} {} {} => {}", model == null ? "null" : model.getClass().getName(), name(), size, res); |
|
|
|
|
} |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
@ -275,8 +255,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
if (target != null) { |
|
|
|
|
res = pattern.matcher(target.toString()).matches(); |
|
|
|
|
} |
|
|
|
|
if (logger.isDebugEnabled()) |
|
|
|
|
logger.debug("[{}] {} [{}] => {}", model == null ? "null" : model.toString(), name(), expected == null ? "null" : expected.toString(), res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -301,11 +279,9 @@ public class Criteria implements Predicate {
|
|
|
|
|
if (ctx.configuration().jsonProvider().isArray(model)) { |
|
|
|
|
int len = ctx.configuration().jsonProvider().length(model); |
|
|
|
|
res = (0 != len); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("array length = {} {} => {}", len, name(), res); |
|
|
|
|
} else if (model instanceof String) { |
|
|
|
|
int len = ((String) model).length(); |
|
|
|
|
res = (0 != len); |
|
|
|
|
if (logger.isDebugEnabled()) logger.debug("string length = {} {} => {}", len, name(), res); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return res; |
|
|
|
@ -842,7 +818,6 @@ public class Criteria implements Predicate {
|
|
|
|
|
Boolean a = (Boolean) right; |
|
|
|
|
return e.compareTo(a); |
|
|
|
|
} else { |
|
|
|
|
logger.debug("Can not compare a {} with a {}", left.getClass().getName(), right.getClass().getName()); |
|
|
|
|
throw new ValueCompareException(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|