View Javadoc
1   package com.atlassian.sal.api.search;
2   
3   import com.atlassian.sal.api.message.Message;
4   
5   import java.util.ArrayList;
6   import java.util.Collections;
7   import java.util.List;
8   
9   /**
10   * Provides searchresults for a query.  If there were any errors, check the list of errors.  The searchresult will also
11   * contain the total searchtime (in milliseconds).
12   *
13   * @since 2.0
14   */
15  public class SearchResults {
16      private final List<Message> errors = new ArrayList<Message>();
17      private final List<SearchMatch> matches = new ArrayList<SearchMatch>();
18      private final long searchTime;
19      private final int totalResults;
20  
21      /**
22       * Constructs search results that contained errors
23       *
24       * @param errors The error list
25       */
26      public SearchResults(List<Message> errors) {
27          this.errors
28                  .addAll(errors);
29          searchTime = 0L;
30          totalResults = 0;
31      }
32  
33      /**
34       * Constructs search results with successful matches
35       *
36       * @param matches      The list of matches
37       * @param totalResults The total number of available results
38       * @param searchTime   The time the search took in milliseconds
39       */
40      public SearchResults(List<SearchMatch> matches, int totalResults, long searchTime) {
41          this.totalResults = totalResults;
42          this.matches
43                  .addAll(matches);
44          this.searchTime = searchTime;
45      }
46  
47      /**
48       * @return search errors
49       */
50      public List<Message> getErrors() {
51          return Collections.unmodifiableList(errors);
52      }
53  
54      /**
55       * @return the matches
56       */
57      public List<SearchMatch> getMatches() {
58          return Collections.unmodifiableList(matches);
59      }
60  
61      /**
62       * @return the time the search took in milliseconds
63       */
64      public long getSearchTime() {
65          return searchTime;
66      }
67  
68      /**
69       * @return the total results available
70       */
71      public int getTotalResults() {
72          return totalResults;
73      }
74  }