-
Notifications
You must be signed in to change notification settings - Fork 25
/
Pagination.java
103 lines (88 loc) · 3.09 KB
/
Pagination.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2019 Otavio Santana and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.nosql.mapping;
import jakarta.nosql.ServiceLoaderProvider;
import java.util.ServiceLoader;
import java.util.function.Function;
/**
* Pagination is the process of separating print or digital content into discrete pages.
* This instance represents this pagination process.
*/
public interface Pagination {
/**
* Returns the page to be returned.
*
* @return the page to be returned.
*/
long getPageNumber();
/**
* Returns the number of items to be returned.
*
* @return the number of items of that page
*/
long getPageSize();
/**
* @return The maximum number of results the select object was set to retrieve.
* According to the underlying page and page size.
*/
long getLimit();
/**
* @return The position of the first result the select object was set to retrieve.
* According to the underlying page and page size.
*/
long getSkip();
/**
* Returns the {@link Pagination} requesting the next {@link Pagination}.
*
* @return the next pagination
*/
Pagination next();
/**
* Returns a pagination instance that is read-only, in other words, that is not allowed to use the {@link Pagination#next()}.
*
* @return a read-onlye {@link Pagination} instance
*/
Pagination unmodifiable();
/**
* A builder to {@link Pagination}, as the first step it defines the page number or the page index that starts from page one.
*
* @param page the page index
* @return a new {@link PaginationBuilder} instance
* @throws IllegalArgumentException when page is lesser equals than zero
*/
static PaginationBuilder page(long page) {
return ServiceLoaderProvider.get(PaginationBuilderProvider.class,
()-> ServiceLoader.load(PaginationBuilderProvider.class)).apply(page);
}
/**
* The builder of {@link Pagination}
*/
interface PaginationBuilder {
/**
* Defines the size of a pagination
*
* @param size the size of pagination
* @return a {@link Pagination} instance
* @throws IllegalArgumentException when size is either zero or negative
*/
Pagination size(long size);
}
/**
* A provider of {@link PaginationBuilder} where it will create from the {@link Long} value
*/
interface PaginationBuilderProvider extends Function<Long, PaginationBuilder> {
}
}