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.support;
20  
21  import java.util.List;
22  
23  import org.apache.maven.search.api.Record;
24  import org.apache.maven.search.api.SearchRequest;
25  import org.apache.maven.search.api.SearchResponse;
26  
27  import static java.util.Objects.requireNonNull;
28  
29  /**
30   * A search response support class.
31   */
32  public abstract class SearchResponseSupport implements SearchResponse {
33      private final SearchRequest searchRequest;
34  
35      private final int totalHits;
36  
37      private final List<Record> page;
38  
39      protected SearchResponseSupport(SearchRequest searchRequest, int totalHits, List<Record> page) {
40          this.searchRequest = requireNonNull(searchRequest);
41          this.totalHits = totalHits;
42          this.page = requireNonNull(page);
43      }
44  
45      @Override
46      public SearchRequest getSearchRequest() {
47          return searchRequest;
48      }
49  
50      @Override
51      public int getTotalHits() {
52          return totalHits;
53      }
54  
55      @Override
56      public int getCurrentHits() {
57          return page.size();
58      }
59  
60      @Override
61      public List<Record> getPage() {
62          return page;
63      }
64  
65      @Override
66      public String toString() {
67          return getClass().getSimpleName() + "{" + "searchRequest=" + searchRequest + ", totalHits=" + totalHits
68                  + ", page=" + page + '}';
69      }
70  }