View Javadoc

1   /*
2    * Copyright (C) 2011 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.api.domain;
18  
19  import com.google.common.base.Objects;
20  
21  /**
22   * Represents search results - links to issues matching given filter (JQL query) with basic
23   * information supporting the paging through the results.
24   *
25   * @since v0.2
26   */
27  public class SearchResult {
28      private final int startIndex;
29      private final int maxResults;
30      private final int total;
31      private final Iterable<Issue> issues;
32  
33      public SearchResult(int startIndex, int maxResults, int total, Iterable<Issue> issues) {
34          this.startIndex = startIndex;
35          this.maxResults = maxResults;
36          this.total = total;
37          this.issues = issues;
38      }
39  
40      /**
41       * @return 0-based start index of the returned issues (e.g. "3" means that 4th, 5th...maxResults issues matching given query
42       * have been returned.
43       */
44      public int getStartIndex() {
45          return startIndex;
46      }
47  
48      /**
49       * @return maximum page size (the window to results).
50       */
51      public int getMaxResults() {
52          return maxResults;
53      }
54  
55      /**
56       * @return total number of issues (regardless of current maxResults and startIndex) matching given criteria.
57       * Query JIRA another time with different startIndex to get subsequent issues
58       */
59      public int getTotal() {
60          return total;
61      }
62  
63      public Iterable<Issue> getIssues() {
64          return issues;
65      }
66  
67      @Override
68      public String toString() {
69          return Objects.toStringHelper(this).
70                  add("startIndex", startIndex).
71                  add("maxResults", maxResults).
72                  add("total", total).
73                  add("issues", issues).
74                  toString();
75      }
76  
77      @Override
78      public boolean equals(Object obj) {
79          if (obj instanceof SearchResult) {
80              SearchResult that = (SearchResult) obj;
81              return Objects.equal(this.startIndex, that.startIndex)
82                      && Objects.equal(this.maxResults, that.maxResults)
83                      && Objects.equal(this.total, that.total)
84                      && Objects.equal(this.issues, that.issues);
85          }
86          return false;
87      }
88  
89      @Override
90      public int hashCode() {
91          return Objects.hashCode(startIndex, maxResults, total, issues);
92      }
93  
94  }