diff options
author | Pontus Boström <pontus@vaadin.com> | 2016-07-26 12:26:54 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-08-01 07:53:34 +0000 |
commit | 6688e6617275120bfc39cd31c464fd9b2a594a79 (patch) | |
tree | 0d641b719161bb79386223e479ce26f0f93dd5f7 /server/src/main/java | |
parent | 77ad774461cb7a609878515172605787631a1b15 (diff) | |
download | vaadin-framework-6688e6617275120bfc39cd31c464fd9b2a594a79.tar.gz vaadin-framework-6688e6617275120bfc39cd31c464fd9b2a594a79.zip |
Fixed the compare filter to handle subclasses (#17169)
Earlier the comparision worked only if the item value was a subclass of
the value in comparator, but not in the other way around. Now the
compairision works if the one is a subclass of the other and both
implements Comparable.
Change-Id: I1bcbba94f1263915f838e948ed9d8b68a14aefd0
Diffstat (limited to 'server/src/main/java')
-rw-r--r-- | server/src/main/java/com/vaadin/data/util/filter/Compare.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/util/filter/Compare.java b/server/src/main/java/com/vaadin/data/util/filter/Compare.java index 1fcbe85580..60523f2d42 100644 --- a/server/src/main/java/com/vaadin/data/util/filter/Compare.java +++ b/server/src/main/java/com/vaadin/data/util/filter/Compare.java @@ -292,9 +292,15 @@ public abstract class Compare implements Filter { return null == value1 ? 0 : -1; } else if (null == value1) { return 1; - } else if (getValue() instanceof Comparable - && value1.getClass().isAssignableFrom(getValue().getClass())) { - return -((Comparable) getValue()).compareTo(value1); + } else if (getValue() instanceof Comparable) { + if (value1.getClass().isInstance(getValue())) { + return -((Comparable) getValue()).compareTo(value1); + } else if (getValue().getClass().isInstance(value1)) { + // isInstance returns true if value1 is a sub-type of + // getValue(), i.e. value1 must here be Comparable + return ((Comparable) value1).compareTo(getValue()); + } + } throw new IllegalArgumentException("Could not compare the arguments: " + value1 + ", " + getValue()); |