diff options
author | Artur Signell <artur@vaadin.com> | 2012-11-20 18:06:57 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-22 11:41:13 +0000 |
commit | 8e7e4fddec6cc26c67abf8dc10adad2af6eb988a (patch) | |
tree | 5a9e8f0d4dcda9214fd467f26231c9f3d1ee4bd9 /server/src/com/vaadin | |
parent | 595a3254a983c989c6fce1eb10a620202ec4d969 (diff) | |
download | vaadin-framework-8e7e4fddec6cc26c67abf8dc10adad2af6eb988a.tar.gz vaadin-framework-8e7e4fddec6cc26c67abf8dc10adad2af6eb988a.zip |
Use compare for Comparable when determining equals for filtering (#10310)
Change-Id: Ie6e12b1d606d6ed06ae94527427049621b515eed
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r-- | server/src/com/vaadin/data/util/filter/Compare.java | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/server/src/com/vaadin/data/util/filter/Compare.java b/server/src/com/vaadin/data/util/filter/Compare.java index 7730bace6b..a13a5bfaa7 100644 --- a/server/src/com/vaadin/data/util/filter/Compare.java +++ b/server/src/com/vaadin/data/util/filter/Compare.java @@ -47,7 +47,8 @@ public abstract class Compare implements Filter { * A {@link Compare} filter that accepts items for which the identified * property value is equal to <code>value</code>. * - * For in-memory filters, equals() is used for the comparison. For other + * For in-memory filters, {@link Comparable#compareTo(Object)} or, if not + * Comparable, {@link #equals(Object)} is used for the comparison. For other * containers, the comparison implementation is container dependent and may * use e.g. database comparison operations. * @@ -248,8 +249,7 @@ public abstract class Compare implements Filter { Object value = p.getValue(); switch (getOperation()) { case EQUAL: - return (null == this.value) ? (null == value) : this.value - .equals(value); + return compareEquals(value); case GREATER: return compareValue(value) > 0; case LESS: @@ -263,6 +263,29 @@ public abstract class Compare implements Filter { return false; } + /** + * Checks if the this value equals the given value. Favors Comparable over + * equals to better support e.g. BigDecimal where equals is stricter than + * compareTo. + * + * @param otherValue + * The value to compare to + * @return true if the values are equal, false otherwise + */ + private boolean compareEquals(Object otherValue) { + if (value == null || otherValue == null) { + return (otherValue == value); + } else if (value == otherValue) { + return true; + } else if (value instanceof Comparable + && otherValue.getClass() + .isAssignableFrom(getValue().getClass())) { + return ((Comparable) value).compareTo(otherValue) == 0; + } else { + return value.equals(otherValue); + } + } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected int compareValue(Object value1) { if (null == value) { |