#1634 - ENH: Add convenience expressions "greater than or null" gtOrNull(), ltOrNull() and inRangeWith()

This commit is contained in:
rob bygrave
2019-02-09 00:30:55 +13:00
parent 25b6d2a5a0
commit 829dfcb013
7 changed files with 170 additions and 6 deletions
@@ -221,6 +221,11 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
return new InRangeExpression(propertyName, value1, value2);
}
@Override
public Expression inRangeWith(String lowProperty, String highProperty, Object value) {
return and(le(lowProperty, value), gtOrNull(highProperty, value));
}
/**
* Between - property between the two given values.
*/
@@ -245,6 +250,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
return new SimpleExpression(propertyName, Op.GT, value);
}
/**
* Greater Than or null - property greater than the given value or null.
*/
@Override
public Expression gtOrNull(String propertyName, Object value) {
return or(gt(propertyName, value), isNull(propertyName));
}
/**
* Greater Than or Equal to - property greater than or equal to the given
* value.
@@ -254,6 +267,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
return new SimpleExpression(propertyName, Op.GT_EQ, value);
}
/**
* Less Than or null - property less than the given value or null.
*/
@Override
public Expression ltOrNull(String propertyName, Object value) {
return or(lt(propertyName, value), isNull(propertyName));
}
/**
* Less Than - property less than the given value.
*/
@@ -794,6 +794,12 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return this;
}
@Override
public ExpressionList<T> inRangeWith(String lowProperty, String highProperty, Object value) {
add(expr.inRangeWith(lowProperty, highProperty, value));
return this;
}
@Override
public ExpressionList<T> inRange(String propertyName, Object value1, Object value2) {
add(expr.inRange(propertyName, value1, value2));
@@ -836,6 +842,12 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return this;
}
@Override
public ExpressionList<T> gtOrNull(String propertyName, Object value) {
add(expr.gtOrNull(propertyName, value));
return this;
}
@Override
public ExpressionList<T> icontains(String propertyName, String value) {
add(expr.icontains(propertyName, value));
@@ -990,6 +1002,12 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return this;
}
@Override
public ExpressionList<T> ltOrNull(String propertyName, Object value) {
add(expr.ltOrNull(propertyName, value));
return this;
}
@Override
public ExpressionList<T> not(Expression exp) {
add(expr.not(exp));
@@ -280,6 +280,11 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
return exprList.and(expOne, expTwo);
}
@Override
public ExpressionList<T> inRangeWith(String lowProperty, String highProperty, Object value) {
return exprList.inRangeWith(lowProperty, highProperty, value);
}
@Override
public ExpressionList<T> inRange(String propertyName, Object value1, Object value2) {
return exprList.inRange(propertyName, value1, value2);
@@ -597,6 +602,11 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
return exprList.gt(propertyName, value);
}
@Override
public ExpressionList<T> gtOrNull(String propertyName, Object value) {
return exprList.gtOrNull(propertyName, value);
}
@Override
public ExpressionList<T> having() {
throw new IllegalStateException("having() not allowed on Junction expression list");
@@ -732,6 +742,11 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
return exprList.lt(propertyName, value);
}
@Override
public ExpressionList<T> ltOrNull(String propertyName, Object value) {
return exprList.ltOrNull(propertyName, value);
}
@Override
public ExpressionList<T> ne(String propertyName, Object value) {
return exprList.ne(propertyName, value);