Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content, Pageable pageable, long total) 

Source Link

Document

Constructor of PageImpl .

Usage

From source file:curly.commons.web.hateoas.PageProcessor.java

public static <T> Page<T> toPage(Collection<T> list, PageMetadata metadata) {
    Assert.notNull(list, "List content must be not null");
    return new PageImpl<T>(new ArrayList<>(list),
            new PageRequest((int) metadata.getNumber(), (int) metadata.getSize()), metadata.getTotalElements());
}

From source file:com.pamarin.income.model.SelectionModel.java

public static <T> Page<SelectionModel<T>> toSelection(Page<T> page, Pageable pageable) {
    return new PageImpl(toSelection(page.getContent()), pageable, page.getTotalElements());
}

From source file:com.trenako.results.PaginatedLists.java

/**
 * Returns a values page according the provided {@code Pageable}.
 *
 * @param values   the values to be paginated
 * @param paging the paging information/*w  w  w . j  ava  2  s.c om*/
 * @return a {@code Page}
 */
public static <T> Page<T> paginate(List<T> values, Pageable paging) {
    Assert.notNull(values, "Values list must be not null");

    int total = values.size();
    int offset = paging.getOffset();

    if (offset > total) {
        return failbackPage();
    }

    int sIndex = start(total, offset);
    int eIndex = end(total, offset, paging.getPageSize());

    List<T> content = values.subList(sIndex, eIndex);
    return new PageImpl<>(content, paging, total);
}

From source file:net.eusashead.hateoas.response.impl.CustomerRepository.java

public Page<Customer> listCustomers(Pageable page) {
    List<Customer> orders = new ArrayList<Customer>();
    for (int i = 0; i < page.getPageSize(); i++) {
        orders.add(new Customer(i, BigDecimal.valueOf(Math.random() * 100),
                new Date(Math.round(123456789l * Math.random()))));
    }//from w  ww.  ja v  a  2s.co  m
    return new PageImpl<Customer>(orders, page, 95);
}

From source file:io.github.howiefh.jeews.modules.oauth2.service.ClientService.java

public Page<Client> findPageBy(Pageable pageable, Client client) {
    List<Client> clients = (List<Client>) clientDao.findPageBy(pageable, client);
    long count = clientDao.countBy(client);
    return new PageImpl<Client>(clients, pageable, count);
}

From source file:org.terasoluna.tourreservation.domain.repository.tourinfo.TourInfoRepositoryImpl.java

@Override
@Transactional/*from   ww w.  j a  v a2  s.  c o  m*/
public Page<TourInfo> findPageBySearchCriteria(TourInfoSearchCriteria criteria, Pageable pageable) {

    List<TourInfo> content = findTourInfo(criteria, pageable);
    long total = countSearchTourInfo(criteria);

    Page<TourInfo> page = new PageImpl<TourInfo>(content, pageable, total);
    return page;
}

From source file:io.kahu.hawaii.util.pagination.PaginationHelper.java

public Page<E> fetchPage(final NamedParameterJdbcOperations jt, final String sqlCountRows,
        final String sqlFetchRows, final Map<String, Object> paramMap, final Pageable pageable,
        final RowMapper<E> rowMapper) {

    // first execute select count (needed for paging metadata)
    final int rowCount = jt.queryForObject(sqlCountRows, paramMap, Integer.class);

    if (maxRows != null && (rowCount > maxRows)) {
        // Threshold defined and total number of records is higher
        return new PageImpl<E>(new ArrayList<>(), new PageRequest(0, 1), rowCount);
    }// w w  w . j av  a  2 s  .  c  o m
    // now fetch the actual objects (content)
    final List<E> pageItems = jt.query(sqlFetchRows, paramMap, (resultSet, rowNum) -> {
        return rowMapper.mapRow(resultSet, rowNum);
    });

    // return the page
    return new PageImpl<E>(pageItems, pageable, rowCount);
}

From source file:com.davidmogar.alsa.services.bus.internal.BusManagerServiceImpl.java

@Override
public Page<BusDto> findAll(int pageIndex) {
    Pageable pageable = createPageable(pageIndex);
    Page<Bus> page = busDataService.findAll(pageable);

    List<BusDto> users = page.getContent().stream().map(BusDto::new).collect(Collectors.toList());

    return new PageImpl<>(users, pageable, page.getTotalElements());
}

From source file:com.example.session.domain.service.goods.GoodsService.java

/**
 * ??????/* w  w w  .ja  v a2s. com*/
 * 
 * @param categoryId
 * @param pageable
 * @return
 */
public Page<Goods> findByCategoryId(Integer categoryId, Pageable pageable) {

    long total = goodsRepository.countByCategoryId(categoryId);

    List<Goods> goodsList = Collections.emptyList();
    if (total > 0) {
        RowBounds rowBounds = new RowBounds((int) pageable.getOffset(), pageable.getPageSize());
        goodsList = goodsRepository.findPageByCategoryId(categoryId, rowBounds);
    }

    return new PageImpl<Goods>(goodsList, pageable, total);
}

From source file:org.terasoluna.tourreservation.domain.service.tourinfo.TourInfoServiceImpl.java

@Override
public Page<TourInfo> searchTour(TourInfoSearchCriteria criteria, Pageable pageable) {

    long total = tourInfoRepository.countBySearchCriteria(criteria);
    List<TourInfo> content;
    if (0 < total) {
        content = tourInfoRepository.findPageBySearchCriteria(criteria, pageable);
    } else {/*from w w  w  . ja  v a 2 s.  c o  m*/
        content = Collections.emptyList();
    }

    Page<TourInfo> page = new PageImpl<TourInfo>(content, pageable, total);
    return page;
}