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.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<BasicIssue> issues;
32  
33  	public SearchResult(int startIndex, int maxResults, int total, Iterable<BasicIssue> issues) {
34  		this.startIndex = startIndex;
35  		this.maxResults = maxResults;
36  		this.total = total;
37  		this.issues = issues;
38  	}
39  
40  	/**
41  	 *
42  	 * @return 0-based start index of the returned issues (e.g. "3" means that 4th, 5th...maxResults issues matching given query
43  	 * have been returned.
44  	 */
45  	public int getStartIndex() {
46  		return startIndex;
47  	}
48  
49  	/**
50  	 * @return maximum page size (the window to results).
51  	 */
52  	public int getMaxResults() {
53  		return maxResults;
54  	}
55  
56  	/**
57  	 * @return total number of issues (regardless of current maxResults and startIndex) matching given criteria.
58  	 * Query JIRA another time with different startIndex to get subsequent issues
59  	 */
60  	public int getTotal() {
61  		return total;
62  	}
63  
64  	public Iterable<BasicIssue> getIssues() {
65  		return issues;
66  	}
67  
68  	@Override
69  	public String toString() {
70  		return Objects.toStringHelper(this).
71  				add("startIndex", startIndex).
72  				add("maxResults", maxResults).
73  				add("total", total).
74  				add("issues", issues).
75  				toString();
76  	}
77  
78  	@Override
79  	public boolean equals(Object obj) {
80  		if (obj instanceof SearchResult) {
81  			SearchResult that = (SearchResult) obj;
82  			return Objects.equal(this.startIndex, that.startIndex)
83  					&& Objects.equal(this.maxResults, that.maxResults)
84  					&& Objects.equal(this.total, that.total)
85  					&& Objects.equal(this.issues, that.issues);
86  		}
87  		return false;
88  	}
89  
90  	@Override
91  	public int hashCode() {
92  		return Objects.hashCode(startIndex, maxResults, total, issues);
93  	}
94  
95  }