本文整理汇总了Java中com.vaadin.data.provider.Query.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Query.getOffset方法的具体用法?Java Query.getOffset怎么用?Java Query.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vaadin.data.provider.Query
的用法示例。
在下文中一共展示了Query.getOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchFromBackEnd
import com.vaadin.data.provider.Query; //导入方法依赖的package包/类
@Override
protected Stream<T> fetchFromBackEnd(Query<T, ExampleFilter<T>> query) {
int page = query.getOffset() / query.getLimit();
List<Sort.Order> sortOrders = query.getSortOrders().stream()
.map(sortOrder -> new Sort.Order(sortOrder.getDirection() == SortDirection.ASCENDING ? Sort.Direction.ASC
: Sort.Direction.DESC,
sortOrder.getSorted()))
.collect(Collectors.toList());
PageRequest pageRequest = new PageRequest(page, query.getLimit(), sortOrders.isEmpty() ? null : new Sort(sortOrders));
List<T> items = null;
if (query.getFilter().isPresent()) {
items = repository.findAll(query.getFilter().get().example, pageRequest).getContent();
}
else {
items = repository.findAll(pageRequest).getContent();
}
return items.subList(query.getOffset() % query.getLimit(), items.size()).stream(); // TODO: comment why this is done
}
示例2: testLimitProvidedByQuery
import com.vaadin.data.provider.Query; //导入方法依赖的package包/类
@Test
public void testLimitProvidedByQuery() {
Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery));
Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>(
implicitLimitQuery.getOffset(),
controls.getPageLength() - 1,
implicitLimitQuery.getSortOrders(),
implicitLimitQuery.getInMemorySorting(),
implicitLimitQuery.getFilter().orElse(null));
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());
controls.nextPage();
Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery));
Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count());
}
示例3: fromPageable
import com.vaadin.data.provider.Query; //导入方法依赖的package包/类
private <T> Stream<T> fromPageable(Page<T> result, Pageable pageable,
Query<T, ?> query) {
List<T> items = result.getContent();
int firstRequested = query.getOffset();
int nrRequested = query.getLimit();
int firstReturned = (int) pageable.getOffset();
int firstReal = firstRequested - firstReturned;
int afterLastReal = firstReal + nrRequested;
if (afterLastReal > items.size()) {
afterLastReal = items.size();
}
return items.subList(firstReal, afterLastReal).stream();
}
示例4: fetchFromBackEnd
import com.vaadin.data.provider.Query; //导入方法依赖的package包/类
@Override
protected Stream<T> fetchFromBackEnd(Query<T, String> query) {
// The index of the first item to load
int offset = query.getOffset();
// The number of items to load
int limit = query.getLimit();
List<Sort> sortOrders = new ArrayList<>();
if (!sortInMemory) {
query.getSortOrders().forEach(queryOrder -> {
Sort sort = service.createSort(
// The name of the sorted property
queryOrder.getSorted(),
// The sort direction for this property
queryOrder.getDirection() == SortDirection.DESCENDING);
sortOrders.add(sort);
});
}
List<T> list = new ArrayList<>();
if (StringUtils.isNoneBlank(filterProperty) && StringUtils.isNoneBlank(filterText)) {
list = service.findAllByLikePaged(filterProperty, filterText, offset, limit);
} else {
list = service.findAllPagedOrderBy(offset, limit, sortOrders);
}
Stream<T> stream = list.stream();
if (sortInMemory) {
Optional<Comparator<T>> comparing = Stream.of(query.getInMemorySorting()).filter(c -> c != null).reduce((c1, c2) -> c1.thenComparing(c2));
if (comparing.isPresent()) {
stream = stream.sorted(comparing.get());
}
}
return stream;
}