Example usage for org.springframework.data.domain Page hasNext

List of usage examples for org.springframework.data.domain Page hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns if there is a next Slice .

Usage

From source file:de.olivergierke.deepdive.ProductRepositoryIntegrationTest.java

/**
 * @since Step 6.2/* w ww.  j av a2 s  .c  o  m*/
 */
@Test
public void findsAllAppleProductPaged() {

    Page<Product> products = repository.findByDescriptionContaining("Apple", new PageRequest(0, 1));

    assertThat(products.isFirst(), is(true));
    assertThat(products.hasNext(), is(true));
    assertThat(products, Matchers.<Product>hasItem(hasProperty("name", is("iPad"))));
    assertThat(products, not(Matchers.<Product>hasItem(hasProperty("name", is("Dock")))));
}

From source file:demo.ProductRepositoryIntegrationTest.java

/**
 * @since Step 6.2/*from w ww . jav a2s .c om*/
 */
@Test
public void findsAllAppleProductPaged() {

    Page<Product> products = repository.findByDescriptionContaining("Apple", new PageRequest(0, 1));

    assertThat(products.isFirst()).isTrue();
    assertThat(products.hasNext()).isTrue();

    assertThat(products).filteredOn("name", "iPad").isNotEmpty();
    assertThat(products).filteredOn("name", "Dock").isEmpty();
}

From source file:org.devgateway.toolkit.forms.wicket.providers.AbstractJpaRepositoryTextChoiceProvider.java

@Override
public void query(final String term, final int page, final Response<T> response) {
    Page<T> itemsByTerm;
    if (term == null || term.isEmpty()) {
        itemsByTerm = findAll(page);//from  ww w  . j  ava 2  s . com
        response.setHasMore(itemsByTerm.hasNext());
    } else {
        itemsByTerm = getItemsByTerm(term.toLowerCase(), page);
    }

    if (itemsByTerm != null) {
        if (itemsByTerm.getContent().size() == 0 && addNewElements) {
            // add new element dynamically
            // the new element should extend Category so that we can attache
            // a 'label' to it
            try {
                newObject = clazz.newInstance();
                newObject.setLabel(term);
            } catch (InstantiationException e) {
                logger.error(e);
            } catch (IllegalAccessException e) {
                logger.error(e);
            }

            List<T> newElementsList = new ArrayList<>();
            newElementsList.add(newObject);

            response.addAll(newElementsList);
        } else {
            response.setHasMore(itemsByTerm.hasNext());
            response.addAll(itemsByTerm.getContent());
        }
    }
}

From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java

/**
 * Gets the link node of the next page./*  w ww. j a v  a 2 s. com*/
 *
 * @param page        the pagination object
 * @param contextPath current context path of servlet
 * @return the node
 */
private Element getNextElement(final Page<?> page, final String contextPath) {
    final Element result = new Element("li");

    String url;
    if (!page.hasNext()) {
        int pageNumber = page.getTotalPages() - 1;
        url = getPagedParams(contextPath, pageNumber < 0 ? 0 : pageNumber, page.getSize());
    } else {
        url = getPagedParams(contextPath, page.getNumber() + 1, page.getSize());
    }

    final Element a = new Element("a");
    a.setAttribute("href", url);
    result.addChild(a);

    final Element icon = new Element("i");
    icon.setAttribute("class", "glyphicon glyphicon-triangle-right");

    a.addChild(icon);

    if (!page.hasNext()) {
        result.setAttribute("class", "disabled");
    }

    return result;
}

From source file:com.dickthedeployer.dick.web.service.BuildService.java

@Transactional
public void deleteBuilds(Project project) {
    PageRequest pageable = new PageRequest(0, 20);
    Page<Build> page;
    do {/*ww  w  .java  2s . c om*/
        page = buildDao.findByProject(project, pageable);
        page.getContent().stream().forEach(build -> {
            jobBuildService.deleteJobBuilds(build);
            buildDao.delete(build);
        });
    } while (page.hasNext());
}

From source file:com.chessix.vas.service.ClasService.java

/**
 * Validate given clas, if all accounts count to 0.
 *///www . jav  a 2  s  .c om
public boolean validate(final String clasId) {
    int page = 0;
    long total = 0;
    Page<Account> accounts;
    do {
        log.debug("validate({}) : page: {}", clasId, page);
        accounts = dbService.findAccountsByClas(clasId, new PageRequest(page, PAGE_SIZE));
        for (final Account account : accounts) {
            total += account.getBalance();
        }
        page += 1;
    } while (accounts.hasNext());
    return total == 0;
}

From source file:com.chessix.vas.service.RdbmsStorage.java

@Override
public List<Integer> accountValues(final String clasId) {
    final List<Integer> result = Lists.newLinkedList();
    int page = 0;
    Page<Account> accounts;
    do {/*  w w w.j a  v  a 2s.c  o  m*/
        accounts = dbService.findAccountsByClas(clasId, new PageRequest(page, PAGE_SIZE));
        result.addAll(Lists.transform(accounts.getContent(), new Function<Account, Integer>() {

            @Override
            public Integer apply(final Account input) {
                return input.getBalance();
            }
        }));

        page += 1;
    } while (accounts.hasNext());

    return result;
}

From source file:org.lareferencia.backend.rest.PageResource.java

public PageResource(Page<T> page, String pageParam, String sizeParam) {
    super();/* w  w w.  j  a  va2  s  .c  o  m*/
    this.page = page;
    if (page.hasPrevious()) {
        String path = createBuilder().queryParam(pageParam, page.getNumber() - 1)
                .queryParam(sizeParam, page.getSize()).build().toUriString();
        Link link = new Link(path, Link.REL_PREVIOUS);
        add(link);
    }
    if (page.hasNext()) {
        String path = createBuilder().queryParam(pageParam, page.getNumber() + 1)
                .queryParam(sizeParam, page.getSize()).build().toUriString();
        Link link = new Link(path, Link.REL_NEXT);
        add(link);
    }

    Link link = buildPageLink(pageParam, 0, sizeParam, page.getSize(), Link.REL_FIRST);
    add(link);

    int indexOfLastPage = page.getTotalPages() - 1;
    link = buildPageLink(pageParam, indexOfLastPage, sizeParam, page.getSize(), Link.REL_LAST);
    add(link);

    link = buildPageLink(pageParam, page.getNumber(), sizeParam, page.getSize(), Link.REL_SELF);
    add(link);
}

From source file:com.chessix.vas.service.ValidationService.java

/**
 * Validate given clas, if all accounts have the same value in the different
 * layers./*from  w  w  w .  j  ava2 s  .  c  o  m*/
 */
public boolean validate(final String clasId) {
    int page = 0;
    boolean result = true;
    Page<Account> accounts;
    do {
        log.debug("validate({}) : page: {}", clasId, page);
        accounts = dbService.findAccountsByClas(clasId, new PageRequest(page, PAGE_SIZE));
        for (final Account account : accounts) {
            final Integer speed = balance(clasId, account.getExternalId());
            final boolean compare = ObjectUtils.compare(speed, account.getBalance()) == 0;
            if (!compare) {
                log.warn("account {}/{} is out of sync. speed/batch = {}/{}", clasId, account.getExternalId(),
                        speed, account.getBalance());
            }
            result = result && compare;
        }
        page += 1;
    } while (result && accounts.hasNext());
    return result;
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
    Page<Person> slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));

    assertThat(slice.getContent(), hasSize(1));
    assertThat(slice.hasPrevious(), is(true));
    assertThat(slice.hasNext(), is(false));
}