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

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

Introduction

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

Prototype

boolean hasPrevious();

Source Link

Document

Returns if there is a previous Slice .

Usage

From source file:example.springdata.jpa.showcase.after.CustomerRepositoryIntegrationTest.java

@Test
public void findsFirstPageOfMatthews() throws Exception {

    Page<Customer> customers = repository.findByLastname("Matthews", new PageRequest(0, 2));

    assertThat(customers.getContent().size(), is(2));
    assertFalse(customers.hasPrevious());
}

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

public PageResource(Page<T> page, String pageParam, String sizeParam) {
    super();//w w  w  . j a v a  2s  . 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.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java

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

    String url;
    if (!page.hasPrevious()) {
        url = getPagedParams(contextPath, 0, 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-left");

    a.addChild(icon);

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

    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));
}

From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java

@Test
public void findAllByPageable() throws Exception {
    // given/*from   ww  w .  ja  v a  2s  .  c o m*/
    dbSetupTracker.skipNextLaunch();

    // when
    PageRequest page1 = new PageRequest(0, 2);
    PageRequest page2 = new PageRequest(1, 2);
    Page<BookApi> bookApis1 = repository.findAll(page1);
    Page<BookApi> bookApis2 = repository.findAll(page2);

    // then
    assertThat(bookApis1).isNotNull().isNotEmpty().hasSize(2).extracting("id", "name", "url").containsExactly(
            tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"),
            tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes"));
    assertThat(bookApis1.getNumber()).isEqualTo(0);
    assertThat(bookApis1.getNumberOfElements()).isEqualTo(2);
    assertThat(bookApis1.getSize()).isEqualTo(2);
    assertThat(bookApis1.getTotalPages()).isEqualTo(2);
    assertThat(bookApis1.getTotalElements()).isEqualTo(3);
    assertThat(bookApis1.isFirst()).isTrue();
    assertThat(bookApis1.isLast()).isFalse();
    assertThat(bookApis1.hasNext()).isTrue();
    assertThat(bookApis1.hasPrevious()).isFalse();
    assertThat(bookApis2).isNotNull().isNotEmpty().hasSize(1).extracting("id", "name", "url")
            .containsExactly(tuple(3, "?API",
                    "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522"));
    assertThat(bookApis2.getNumber()).isEqualTo(1);
    assertThat(bookApis2.getNumberOfElements()).isEqualTo(1);
    assertThat(bookApis2.getSize()).isEqualTo(2);
    assertThat(bookApis2.getTotalPages()).isEqualTo(2);
    assertThat(bookApis2.getTotalElements()).isEqualTo(3);
    assertThat(bookApis2.isFirst()).isFalse();
    assertThat(bookApis2.isLast()).isTrue();
    assertThat(bookApis2.hasNext()).isFalse();
    assertThat(bookApis2.hasPrevious()).isTrue();
}

From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java

@Test
public void findAllByPageableAndDescendingSort() throws Exception {
    // given//w w  w.j a v  a2s  . c  o m
    dbSetupTracker.skipNextLaunch();

    // when
    PageRequest page1 = new PageRequest(0, 2, Sort.Direction.DESC, "id");
    PageRequest page2 = new PageRequest(1, 2, Sort.Direction.DESC, "id");
    Page<BookApi> bookApis1 = repository.findAll(page1);
    Page<BookApi> bookApis2 = repository.findAll(page2);

    // then
    assertThat(bookApis1).isNotNull().isNotEmpty().hasSize(2).extracting("id", "name", "url").containsExactly(
            tuple(3, "?API",
                    "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522"),
            tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes"));
    assertThat(bookApis1.getNumber()).isEqualTo(0);
    assertThat(bookApis1.getNumberOfElements()).isEqualTo(2);
    assertThat(bookApis1.getSize()).isEqualTo(2);
    assertThat(bookApis1.getTotalPages()).isEqualTo(2);
    assertThat(bookApis1.getTotalElements()).isEqualTo(3);
    assertThat(bookApis1.isFirst()).isTrue();
    assertThat(bookApis1.isLast()).isFalse();
    assertThat(bookApis1.hasNext()).isTrue();
    assertThat(bookApis1.hasPrevious()).isFalse();
    assertThat(bookApis2).isNotNull().isNotEmpty().hasSize(1).extracting("id", "name", "url")
            .containsExactly(tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"));
    assertThat(bookApis2.getNumber()).isEqualTo(1);
    assertThat(bookApis2.getNumberOfElements()).isEqualTo(1);
    assertThat(bookApis2.getSize()).isEqualTo(2);
    assertThat(bookApis2.getTotalPages()).isEqualTo(2);
    assertThat(bookApis2.getTotalElements()).isEqualTo(3);
    assertThat(bookApis2.isFirst()).isFalse();
    assertThat(bookApis2.isLast()).isTrue();
    assertThat(bookApis2.hasNext()).isFalse();
    assertThat(bookApis2.hasPrevious()).isTrue();
}

From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java

@Test
public void findAllByPageableNothing() throws Exception {
    // given//from   w  w  w.  j  a v a 2  s.  c  o m
    dbSetupTracker.skipNextLaunch();
    Pageable nothing = null;

    // when
    Page<BookApi> bookApis = repository.findAll(nothing);

    // then
    assertThat(bookApis).isNotNull().isNotEmpty().hasSize(3).extracting("id", "name", "url").containsExactly(
            tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"),
            tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes"),
            tuple(3, "?API",
                    "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522"));
    assertThat(bookApis.getNumber()).isEqualTo(0);
    assertThat(bookApis.getNumberOfElements()).isEqualTo(3);
    assertThat(bookApis.getSize()).isEqualTo(0);
    assertThat(bookApis.getTotalPages()).isEqualTo(1);
    assertThat(bookApis.getTotalElements()).isEqualTo(3);
    assertThat(bookApis.isFirst()).isTrue();
    assertThat(bookApis.isLast()).isTrue();
    assertThat(bookApis.hasNext()).isFalse();
    assertThat(bookApis.hasPrevious()).isFalse();
}