diff options
author | Denis Anisimov <denis@vaadin.com> | 2014-08-23 12:50:35 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-26 10:59:23 +0000 |
commit | 17a9993995cfd3434259cd8b0f729f76da36de12 (patch) | |
tree | f1e701e60e2f23c6a910436fa60584a7879c93d0 /server/src/com/vaadin/data/util | |
parent | 84ed6e6d1e13fcd6ab5cdfcd70b5be2dcee84b75 (diff) | |
download | vaadin-framework-17a9993995cfd3434259cd8b0f729f76da36de12.tar.gz vaadin-framework-17a9993995cfd3434259cd8b0f729f76da36de12.zip |
Handle cases when start/end date is not set for Between filter (#13354).
Change-Id: If75998b1bc87b0bd7d2fa83298e1f17d65a18745
Diffstat (limited to 'server/src/com/vaadin/data/util')
-rw-r--r-- | server/src/com/vaadin/data/util/filter/Between.java | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/server/src/com/vaadin/data/util/filter/Between.java b/server/src/com/vaadin/data/util/filter/Between.java index 48a610ed57..c50488c521 100644 --- a/server/src/com/vaadin/data/util/filter/Between.java +++ b/server/src/com/vaadin/data/util/filter/Between.java @@ -15,16 +15,20 @@ */ package com.vaadin.data.util.filter; +import java.util.Arrays; + import com.vaadin.data.Container.Filter; import com.vaadin.data.Item; +import com.vaadin.shared.util.SharedUtil; public class Between implements Filter { private final Object propertyId; - private final Comparable startValue; - private final Comparable endValue; + private final Comparable<?> startValue; + private final Comparable<?> endValue; - public Between(Object propertyId, Comparable startValue, Comparable endValue) { + public Between(Object propertyId, Comparable<?> startValue, + Comparable<?> endValue) { this.propertyId = propertyId; this.startValue = startValue; this.endValue = endValue; @@ -47,9 +51,11 @@ public class Between implements Filter { throws UnsupportedOperationException { Object value = item.getItemProperty(getPropertyId()).getValue(); if (value instanceof Comparable) { - Comparable cval = (Comparable) value; - return cval.compareTo(getStartValue()) >= 0 - && cval.compareTo(getEndValue()) <= 0; + Comparable comparable = (Comparable) value; + return isAfterStartValue(comparable) + && isBeforeEndValue(comparable); + } else if (value == null) { + return getStartValue() == null && getEndValue() == null; } return false; } @@ -61,8 +67,8 @@ public class Between implements Filter { @Override public int hashCode() { - return getPropertyId().hashCode() + getStartValue().hashCode() - + getEndValue().hashCode(); + return Arrays.hashCode(new Object[] { getPropertyId(), getStartValue(), + getEndValue() }); } @Override @@ -78,13 +84,23 @@ public class Between implements Filter { final Between o = (Between) obj; // Checks the properties one by one - boolean propertyIdEqual = (null != getPropertyId()) ? getPropertyId() - .equals(o.getPropertyId()) : null == o.getPropertyId(); - boolean startValueEqual = (null != getStartValue()) ? getStartValue() - .equals(o.getStartValue()) : null == o.getStartValue(); - boolean endValueEqual = (null != getEndValue()) ? getEndValue().equals( - o.getEndValue()) : null == o.getEndValue(); + boolean propertyIdEqual = SharedUtil.equals(getPropertyId(), + o.getPropertyId()); + boolean startValueEqual = SharedUtil.equals(getStartValue(), + o.getStartValue()); + boolean endValueEqual = SharedUtil.equals(getEndValue(), + o.getEndValue()); return propertyIdEqual && startValueEqual && endValueEqual; } + + private boolean isAfterStartValue(Comparable comparable) { + return getStartValue() == null + || comparable.compareTo(getStartValue()) >= 0; + } + + private boolean isBeforeEndValue(Comparable comparable) { + return getEndValue() == null + || comparable.compareTo(getEndValue()) <= 0; + } } |