Commit 9a861ab5 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '12-bugs-in-filters' into 'master'

Resolve "Bugs in Filters"

Closes #12

See merge request !12
parents 8ba68ee5 e710e47b
...@@ -43,6 +43,11 @@ public class DateFilter { ...@@ -43,6 +43,11 @@ public class DateFilter {
// < // <
public Date lt; public Date lt;
/**
* Between is array of two values [a, b]
*/
public Date[] between;
public Predicate buildQuery(final TemporalExpression<Date> date) { public Predicate buildQuery(final TemporalExpression<Date> date) {
final BooleanBuilder and = new BooleanBuilder(); final BooleanBuilder and = new BooleanBuilder();
if (ge != null) { if (ge != null) {
...@@ -57,6 +62,9 @@ public class DateFilter { ...@@ -57,6 +62,9 @@ public class DateFilter {
if (lt != null) { if (lt != null) {
and.and(date.lt(lt)); and.and(date.lt(lt));
} }
if (between != null && between.length == 2) {
and.and(date.between(between[0], between[1]));
}
return and; return and;
} }
...@@ -75,6 +83,9 @@ public class DateFilter { ...@@ -75,6 +83,9 @@ public class DateFilter {
if (lt != null) { if (lt != null) {
str.append(" date < ").append(lt).append(" "); str.append(" date < ").append(lt).append(" ");
} }
if (between != null) {
str.append(" date between ").append(between[0]).append(" and ").append(between[1]);
}
return str.toString().replaceAll("\\s{2,}", " "); return str.toString().replaceAll("\\s{2,}", " ");
} }
......
...@@ -21,33 +21,38 @@ import com.querydsl.core.types.dsl.NumberPath; ...@@ -21,33 +21,38 @@ import com.querydsl.core.types.dsl.NumberPath;
/** /**
* Utility filtering for numeric types. Matches all constraints. * Utility filtering for numeric types. Matches all constraints.
*/ */
public class NumberFilter { public class NumberFilter<T extends Number & Comparable<?>> {
/** /**
* Equal * Equal
*/ */
public Double eq; public T eq;
/** /**
* Greater than * Greater than
*/ */
public Double gt; public T gt;
/** /**
* Greater than or equal * Greater than or equal
*/ */
public Double ge; public T ge;
/** /**
* Less than * Less than
*/ */
public Double lt; public T lt;
/** /**
* Less than or equal * Less than or equal
*/ */
public Double le; public T le;
public BooleanBuilder buildQuery(final NumberPath<Double> val) { /**
* Between is array of two values [a, b]
*/
public T[] between;
public BooleanBuilder buildQuery(final NumberPath<T> val) {
final BooleanBuilder and = new BooleanBuilder(); final BooleanBuilder and = new BooleanBuilder();
if (eq != null) { if (eq != null) {
and.and(val.eq(eq)); and.and(val.eq(eq));
...@@ -59,13 +64,13 @@ public class NumberFilter { ...@@ -59,13 +64,13 @@ public class NumberFilter {
and.and(val.goe(ge)); and.and(val.goe(ge));
} }
if (lt != null) { if (lt != null) {
and.and(val.lt(gt)); and.and(val.lt(lt));
} }
if (le != null) { if (le != null) {
and.and(val.loe(le)); and.and(val.loe(le));
} }
if (gt != null) { if (between != null && between.length == 2) {
and.and(val.gt(gt)); and.and(val.between(between[0], between[1]));
} }
return and; return and;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment