Browse Source

collection-based filtering for number-based filters

pull/16/head
Jochen Berger 12 years ago
parent
commit
79214e7c3f
  1. 42
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java

42
json-path/src/main/java/com/jayway/jsonpath/Criteria.java

@ -122,7 +122,7 @@ public class Criteria {
for (CriteriaType key : this.criteria.keySet()) { for (CriteriaType key : this.criteria.keySet()) {
Object actualVal = readSafely(this.key, map); Object actualVal = readSafely(this.key, map);
Object expectedVal = this.criteria.get(key); final Object expectedVal = this.criteria.get(key);
if (CriteriaType.GT.equals(key)) { if (CriteriaType.GT.equals(key)) {
@ -130,10 +130,14 @@ public class Criteria {
return false; return false;
} }
Number expectedNumber = (Number) expectedVal; final Number expectedNumber = (Number) expectedVal;
Number actualNumber = (Number) actualVal; return objectOrAnyCollectionItemMatches(actualVal, new Predicate<Number>() {
return (actualNumber.doubleValue() > expectedNumber.doubleValue()); @Override
public boolean accept(Number value) {
return (value.doubleValue() > expectedNumber.doubleValue());
}
});
} else if (CriteriaType.GTE.equals(key)) { } else if (CriteriaType.GTE.equals(key)) {
@ -141,10 +145,14 @@ public class Criteria {
return false; return false;
} }
Number expectedNumber = (Number) expectedVal; final Number expectedNumber = (Number) expectedVal;
Number actualNumber = (Number) actualVal; return objectOrAnyCollectionItemMatches(actualVal, new Predicate<Number>() {
return (actualNumber.doubleValue() >= expectedNumber.doubleValue()); @Override
public boolean accept(Number value) {
return (value.doubleValue() >= expectedNumber.doubleValue());
}
});
} else if (CriteriaType.LT.equals(key)) { } else if (CriteriaType.LT.equals(key)) {
@ -152,10 +160,14 @@ public class Criteria {
return false; return false;
} }
Number expectedNumber = (Number) expectedVal; final Number expectedNumber = (Number) expectedVal;
Number actualNumber = (Number) actualVal; return objectOrAnyCollectionItemMatches(actualVal, new Predicate<Number>() {
return (actualNumber.doubleValue() < expectedNumber.doubleValue()); @Override
public boolean accept(Number value) {
return (value.doubleValue() < expectedNumber.doubleValue());
}
});
} else if (CriteriaType.LTE.equals(key)) { } else if (CriteriaType.LTE.equals(key)) {
@ -163,10 +175,14 @@ public class Criteria {
return false; return false;
} }
Number expectedNumber = (Number) expectedVal; final Number expectedNumber = (Number) expectedVal;
Number actualNumber = (Number) actualVal; return objectOrAnyCollectionItemMatches(actualVal, new Predicate<Number>() {
return (actualNumber.doubleValue() <= expectedNumber.doubleValue()); @Override
public boolean accept(Number value) {
return (value.doubleValue() <= expectedNumber.doubleValue());
}
});
} else if (CriteriaType.NE.equals(key)) { } else if (CriteriaType.NE.equals(key)) {
if (expectedVal == null && actualVal == null) { if (expectedVal == null && actualVal == null) {

Loading…
Cancel
Save