1 package org.apache.maven.search.request;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 /**
23 * Paging.
24 */
25 public final class Paging
26 {
27 private final int pageSize;
28
29 private final int pageOffset;
30
31 /**
32 * Creates paging instance with given page size (must be greater than 0) and page offset (must be non-negative).
33 */
34 public Paging( int pageSize, int pageOffset )
35 {
36 if ( pageSize < 1 )
37 {
38 throw new IllegalArgumentException( "pageSize" );
39 }
40 if ( pageOffset < 0 )
41 {
42 throw new IllegalArgumentException( "pageOffset" );
43 }
44 this.pageSize = pageSize;
45 this.pageOffset = pageOffset;
46 }
47
48 /**
49 * Creates paging instance with given page size (must be grater than 0) and 0 page offset.
50 */
51 public Paging( int pageSize )
52 {
53 this( pageSize, 0 );
54 }
55
56 /**
57 * Returns the page size: positive integer, never zero or less.
58 */
59 public int getPageSize()
60 {
61 return pageSize;
62 }
63
64 /**
65 * Returns the page offset: a zero or a positive integer.
66 */
67 public int getPageOffset()
68 {
69 return pageOffset;
70 }
71
72 /**
73 * Creates "next page" instance relative to this instance.
74 */
75 public Paging nextPage()
76 {
77 return new Paging( pageSize, pageOffset + 1 );
78 }
79
80 @Override
81 public String toString()
82 {
83 return getClass().getSimpleName() + "{pageSize=" + pageSize + ", pageOffset=" + pageOffset + "}";
84 }
85 }