View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.search.api;
20  
21  import org.apache.maven.search.api.request.Paging;
22  import org.apache.maven.search.api.request.Query;
23  
24  import static java.util.Objects.requireNonNull;
25  
26  /**
27   * A search request to perform search: defines paging and query.
28   */
29  public final class SearchRequest {
30      private final Paging paging;
31  
32      private final Query query;
33  
34      /**
35       * Creates a request with given {@link Query} instance and default page size of 50.
36       */
37      public SearchRequest(Query query) {
38          this(new Paging(50), query);
39      }
40  
41      /**
42       * Creates a request with given {@link Query} and {@link Paging}.
43       */
44      public SearchRequest(Paging paging, Query query) {
45          this.paging = requireNonNull(paging);
46          this.query = requireNonNull(query);
47      }
48  
49      /**
50       * The {@link Paging} of this request: defines page size and page offset, never {@code null}.
51       */
52      public Paging getPaging() {
53          return paging;
54      }
55  
56      /**
57       * The {@link Query} of this request, never {@code null}.
58       */
59      public Query getQuery() {
60          return query;
61      }
62  
63      /**
64       * Returns a new {@link SearchRequest} instance for "next page" relative to this instance, never {@code null}.
65       */
66      public SearchRequest nextPage() {
67          return new SearchRequest(paging.nextPage(), query);
68      }
69  
70      @Override
71      public String toString() {
72          return getClass().getSimpleName() + "{" + "paging=" + paging + ", query=" + query + '}';
73      }
74  }