diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-19 09:01:23 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-19 08:06:37 +0000 |
commit | c1c3564717388708e34f7ec6e9beeb09e4c2d6a4 (patch) | |
tree | 1846ee2299d710e3062408046152c7145e851b75 /shared/src | |
parent | ab07a2ef324c13614cea34bf2efd84aee75edcd0 (diff) | |
download | vaadin-framework-c1c3564717388708e34f7ec6e9beeb09e4c2d6a4.tar.gz vaadin-framework-c1c3564717388708e34f7ec6e9beeb09e4c2d6a4.zip |
Fix Range.restrictTo to work with non-intersecting ranges(#13334)
Also adds a special case for isSubsetOf with two empty ranges.
Change-Id: I9b4c854051bd760bbac05c7a0bc2e5418371e90e
Diffstat (limited to 'shared/src')
-rw-r--r-- | shared/src/com/vaadin/shared/ui/grid/Range.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/shared/src/com/vaadin/shared/ui/grid/Range.java b/shared/src/com/vaadin/shared/ui/grid/Range.java index 2054845320..6be9e04cbc 100644 --- a/shared/src/com/vaadin/shared/ui/grid/Range.java +++ b/shared/src/com/vaadin/shared/ui/grid/Range.java @@ -177,6 +177,10 @@ public final class Range implements Serializable { * range */ public boolean isSubsetOf(final Range other) { + if (isEmpty() && other.isEmpty()) { + return true; + } + return other.getStart() <= getStart() && getEnd() <= other.getEnd(); } @@ -411,8 +415,10 @@ public final class Range implements Serializable { * @return a bounded range */ public Range restrictTo(Range bounds) { - boolean startWithin = getStart() >= bounds.getStart(); - boolean endWithin = getEnd() <= bounds.getEnd(); + boolean startWithin = bounds.contains(getStart()); + boolean endWithin = bounds.contains(getEnd()); + boolean boundsWithin = getStart() < bounds.getStart() + && getEnd() >= bounds.getEnd(); if (startWithin) { if (endWithin) { @@ -423,8 +429,10 @@ public final class Range implements Serializable { } else { if (endWithin) { return Range.between(bounds.getStart(), getEnd()); - } else { + } else if (boundsWithin) { return bounds; + } else { + return Range.withLength(getStart(), 0); } } } |