当前位置: 首页>>代码示例>>Java>>正文


Java Query.getOffset方法代码示例

本文整理汇总了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
}
 
开发者ID:waschmittel,项目名称:springentityprovider,代码行数:21,代码来源:SpringEntityProvider.java

示例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());
}
 
开发者ID:tsuoanttila,项目名称:GridExtensionPack,代码行数:19,代码来源:PagedDataProviderTest.java

示例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();
}
 
开发者ID:vaadin,项目名称:trippy,代码行数:15,代码来源:PageableDataProvider.java

示例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;
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:41,代码来源:CrudDataProvider.java


注:本文中的com.vaadin.data.provider.Query.getOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。