public static <T> PagedQueryResultDsl<T> of(final int offset, final int total, final List<T> results) { return new PagedQueryResultDsl<>(offset, total, results); }
/** * Creates a copy of this with the given total items count. * @param total the number of total items in the backend. * @return a copy with total as new total. */ public PagedQueryResultDsl<T> withTotal(final Long total) { return PagedQueryResult.of(getOffset(), getLimit(), total, getResults()); } }
/** * Creates a copy of this item with the given offset. * @param offset the offset of the new copy * @return the copy */ public PagedQueryResultDsl<T> withOffset(final Long offset) { return PagedQueryResult.of(offset, getLimit(), getTotal(), getResults()); }
/** * Creates a copy of this item with the given offset. * @param offset the offset of the new copy * @return the copy */ public PagedQueryResultDsl<T> withOffset(final int offset) { return PagedQueryResult.of(offset, getTotal(), getResults()); }
/** * Creates a copy of this with the given total items count. * @param total the number of total items in the backend. * @return a copy with total as new total. */ public PagedQueryResultDsl<T> withTotal(final int total) { return PagedQueryResult.of(getOffset(), total, getResults()); } }
@Test public void withTotal() throws Exception { final PagedQueryResult<String> result = PagedQueryResult.of("hello").withTotal(500L); assertThat(result.getCount()).isEqualTo(1); assertThat(result.getOffset()).isEqualTo(0); assertThat(result.getResults()).isEqualTo(Collections.singletonList("hello")); assertThat(result.getTotal()).isEqualTo(500); }
@Test public void withOffset() throws Exception { assertThat(PagedQueryResult.of(0L, PAGE_SIZE, 500L, listOfSize(PAGE_SIZE)).withOffset(5L)). isEqualTo(PagedQueryResult.of(5L, PAGE_SIZE, 500L, listOfSize(PAGE_SIZE))); }
/** * Creates a {@code PagedQueryResult} for queries with no matching values. * @param <T> the type of the underlying model * @return an empty {@code PagedQueryResult} */ public static <T> PagedQueryResultDsl<T> empty() { return new PagedQueryResultDsl<>(0, 0, Collections.<T>emptyList()); }
/** * Creates a {@code PagedQueryResult} for queries with no matching values. * * @param <T> the type of the underlying model * @return an empty {@code PagedQueryResult} */ static <T> PagedQueryResultDsl<T> empty() { return new PagedQueryResultDsl<>(0L, 0L, 0L, Collections.<T>emptyList(), 0L); }
/** * @deprecated PagedQueryResult should remain as a read model, and be constructed only by deserialization. * @param <T> the type of the underlying model * @param limit The limit supplied by the client or the server default * @param offset The offset supplied by the client or the server default. * @param total The total number of results matching the request. * @param results the mocked results. * @return the paged query result. */ @Deprecated static <T> PagedQueryResultDsl<T> of(final Long offset, final Long limit, final Long total, final List<T> results) { return new PagedQueryResultDsl<>(offset, limit, total, results, (long) results.size()); }