use of com.vaadin.flow.internal.Range in project flow by vaadin.
the class DataCommunicator method collectKeysToFlush.
private List<String> collectKeysToFlush(final Range previousActive, final Range effectiveRequested) {
List<String> newActiveKeyOrder;
/*
* Collecting all items even though only some small sub range would
* actually be useful can be optimized away once we have some actual
* test coverage for the logic here.
*/
if (resendEntireRange) {
newActiveKeyOrder = activate(effectiveRequested);
} else {
Range[] partitionWith = effectiveRequested.partitionWith(previousActive);
newActiveKeyOrder = new ArrayList<>();
newActiveKeyOrder.addAll(activate(partitionWith[0]));
// Pick existing items from the current list
Range overlap = partitionWith[1].offsetBy(-activeStart);
newActiveKeyOrder.addAll(activeKeyOrder.subList(overlap.getStart(), overlap.getEnd()));
newActiveKeyOrder.addAll(activate(partitionWith[2]));
}
return newActiveKeyOrder;
}
use of com.vaadin.flow.internal.Range in project flow by vaadin.
the class RangeTest method splitTest.
@Test
public void splitTest() {
final Range startRange = Range.between(0, 10);
final Range[] splitRanges = startRange.splitAt(5);
assertEquals("[0..10[ split at 5, lower", Range.between(0, 5), splitRanges[0]);
assertEquals("[0..10[ split at 5, upper", Range.between(5, 10), splitRanges[1]);
}
use of com.vaadin.flow.internal.Range in project flow by vaadin.
the class RangeTest method subsetTest.
@Test
public void subsetTest() {
assertTrue("[5..10[ is subset of [0..20[", Range.between(5, 10).isSubsetOf(Range.between(0, 20)));
final Range range = Range.between(0, 10);
assertTrue("range is subset of self", range.isSubsetOf(range));
assertTrue("[0..10[ is not subset of [5..15[", !Range.between(0, 10).isSubsetOf(Range.between(5, 15)));
}
use of com.vaadin.flow.internal.Range in project flow by vaadin.
the class RangeTest method restrictTo_fullyInside.
@Test
public void restrictTo_fullyInside() {
Range r1 = Range.between(5, 10);
Range r2 = Range.between(4, 11);
Range r3 = r1.restrictTo(r2);
assertTrue(r1 == r3);
}
use of com.vaadin.flow.internal.Range in project flow by vaadin.
the class RangeTest method expand_negativeIllegal1.
@Test(expected = IllegalArgumentException.class)
public void expand_negativeIllegal1() {
Range r1 = Range.between(5, 10);
// Should throw because the start would contract beyond the end
r1.expand(-3, -3);
}