1 package org.apache.maven.search; 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 import org.apache.maven.search.request.Paging; 23 import org.apache.maven.search.request.Query; 24 25 import static java.util.Objects.requireNonNull; 26 27 /** 28 * A search request to perform search: defines paging and query. 29 */ 30 public final class SearchRequest 31 { 32 private final Paging paging; 33 34 private final Query query; 35 36 /** 37 * Creates a request with given {@link Query} instance and default page size of 50. 38 */ 39 public SearchRequest( Query query ) 40 { 41 this( new Paging( 50 ), query ); 42 } 43 44 /** 45 * Creates a request with given {@link Query} and {@link Paging}. 46 */ 47 public SearchRequest( Paging paging, Query query ) 48 { 49 this.paging = requireNonNull( paging ); 50 this.query = requireNonNull( query ); 51 } 52 53 /** 54 * The {@link Paging} of this request: defines page size and page offset, never {@code null}. 55 */ 56 public Paging getPaging() 57 { 58 return paging; 59 } 60 61 /** 62 * The {@link Query} of this request, never {@code null}. 63 */ 64 public Query getQuery() 65 { 66 return query; 67 } 68 69 /** 70 * Returns a new {@link SearchRequest} instance for "next page" relative to this instance, never {@code null}. 71 */ 72 public SearchRequest nextPage() 73 { 74 return new SearchRequest( paging.nextPage(), query ); 75 } 76 77 @Override 78 public String toString() 79 { 80 return getClass().getSimpleName() + "{" + "paging=" + paging + ", query=" + query + '}'; 81 } 82 }