KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > search > SearchQueryResult


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v 1.15 2004/07/28 09:35:09 ib Exp $
3  * $Revision: 1.15 $
4  * $Date: 2004/07/28 09:35:09 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.search;
25
26 import java.util.Comparator JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.SortedSet JavaDoc;
31 import java.util.TreeSet JavaDoc;
32
33 /**
34  * Aggregates a set containing the result items of a query. This set is either
35  * a HashSet (if no ordering was requested) or a TreeSet (if orderby was
36  * specified) May also contain a status and a response description
37  * (For example: 507 partial result)
38  *
39  *
40  * @version $Revision: 1.15 $
41  */

42 public class SearchQueryResult {
43
44     public final static int STATUS_OK = 0;
45     public final static int STATUS_BAD_QUERY = 1;
46     public final static int STATUS_INVALID_SCOPE = 2;
47     public final static int STATUS_PARTIAL_RESULT = 3;
48     public final static int STATUS_UNPROCESSABLE_ENTITY = 4;
49     public final static int STATUS_BAD_GATEWAY = 5;
50     public final static int STATUS_FORBIDDEN = 6;
51
52     private int status;
53     private String JavaDoc description;
54     private String JavaDoc href;
55
56     private Set JavaDoc result;
57     /**
58      * Method setStatus
59      *
60      * @param status an int
61      *
62      */

63     public void setStatus(int status) {
64         this.status = status;
65     }
66
67     /**
68      * Method getStatus
69      *
70      * @return an int
71      *
72      */

73     public int getStatus() {
74         return status;
75     }
76
77     /**
78      * Method setDescription
79      *
80      * @param description a String
81      *
82      */

83     public void setDescription(String JavaDoc description) {
84         this.description = description;
85     }
86
87     /**
88      * Method getDescription
89      *
90      * @return a String
91      *
92      */

93     public String JavaDoc getDescription() {
94         return description;
95     }
96
97     /**
98      * Method setHref
99      *
100      * @param href a String
101      *
102      */

103     public void setHref (String JavaDoc href) {
104         this.href = href;
105     }
106     /**
107      * Method getHref
108      *
109      * @return a String
110      *
111      */

112     public String JavaDoc getHref () {
113         return href;
114     }
115
116     /**
117      * Method add
118      *
119      * @param subResultSet a SearchQueryResult
120      *
121      */

122     public void add (SearchQueryResult subResultSet) {
123         result.addAll (subResultSet.getResultSet());
124     }
125
126     /**
127      * Constructs an empty unorderred SearchQueryResult
128      *
129      */

130     public SearchQueryResult () {
131         this (null, null);
132     }
133
134     /**
135      * Constructs an unordered SearchQueryResult
136      *
137      * @param result the set containing the result items
138      */

139     public SearchQueryResult (Set JavaDoc result) {
140         this (result, null);
141     }
142
143     /**
144      * Constructs an empty orderred SearchQueryResult
145      *
146      */

147     public SearchQueryResult (Comparator JavaDoc comparator) {
148         this (null, comparator);
149     }
150
151     /**
152      * Constructs an ordered SearchQueryResult
153      *
154      * @param result the set containing the result items
155      * @param comparator for ordering
156      */

157     public SearchQueryResult (Set JavaDoc result, Comparator JavaDoc comparator) {
158         if (comparator == null) {
159             if (result == null)
160                 this.result = new HashSet JavaDoc ();
161             else
162             this.result = result;
163         }
164         else {
165             this.result = new TreeSet JavaDoc (comparator);
166             if (result != null)
167             this.result.addAll (result);
168         }
169         status = STATUS_OK;
170         description = "";
171     }
172
173
174     public SearchQueryResult (Set JavaDoc result, Comparator JavaDoc comparator, int limit) {
175         this (result, comparator);
176         if (this.result.size() > limit) {
177             SortedSet JavaDoc tmp = new TreeSet JavaDoc (comparator);
178             Iterator JavaDoc it = this.result.iterator();
179             for (int i = 0; i < limit; i++) {
180                 tmp.add (it.next());
181             }
182             this.result = tmp;
183         }
184     }
185
186     /**
187      * Method iterator
188      *
189      * @return iterator for iterating the result, RequestedResource
190      *
191      */

192     public Iterator JavaDoc iterator () {
193         return result.iterator();
194     }
195
196     /**
197      * Method getResultSet. needed to add result subsets.
198      *
199      * @return a Set
200      *
201      */

202     Set JavaDoc getResultSet () {
203         return result;
204     }
205 }
206
Popular Tags