KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > browse > BrowseInfo


1 /*
2  * BrowseInfo.java
3  *
4  * Version: $Revision: 1.9 $
5  *
6  * Date: $Date: 2005/04/20 14:23:12 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.browse;
41
42 import java.util.Collections JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.dspace.content.Item;
46
47 /**
48  * The results of a Browse method call.
49  *
50  * <p>
51  * Results are a List of objects returned from the browse; each returned object
52  * is either a String (for getAuthors()) or an {@link org.dspace.content.Item}
53  * (for all the getItems.... methods). The list is readonly, and is guaranteed
54  * to be non-null.
55  * </p>
56  *
57  * <p>
58  * overallPosition is the position of the first element of results within the
59  * Browse index. Positions begin with 0.
60  * </p>
61  *
62  * <p>
63  * total is the number of objects in the index. Note that this is a snapshot,
64  * which is only guaranteed to be correct at the time the browse method was
65  * called.
66  * </p>
67  *
68  * <p>
69  * offset is the position of the requested object within the results. This
70  * position is also 0-based.
71  * </p>
72  */

73 public class BrowseInfo
74 {
75     /**
76      * The results of the browse.
77      */

78     private List JavaDoc results;
79
80     /**
81      * The position of the first element of results within the Browse index.
82      * Positions begin with 0.
83      */

84     private int overallPosition;
85
86     /**
87      * The position of the requested object within the results. Offsets begin
88      * with 0.
89      */

90     private int offset;
91
92     /**
93      * The total number of items in the browse index.
94      */

95     private int total;
96
97     /**
98      * True if this browse was cached.
99      */

100     private boolean cached;
101
102     /**
103      * Constructor
104      *
105      * @param results
106      * A List of Browse results
107      * @param overallPosition
108      * The position of the first returned item in the overall index
109      * @param total
110      * The total number of items in the index
111      * @param offset
112      * The position of the requested item in the set of results
113      */

114     public BrowseInfo(List JavaDoc results, int overallPosition, int total, int offset)
115     {
116         if (results == null)
117         {
118             throw new IllegalArgumentException JavaDoc("Null result list not allowed");
119         }
120
121         this.results = Collections.unmodifiableList(results);
122         this.overallPosition = overallPosition;
123         this.total = total;
124         this.offset = offset;
125     }
126
127     /**
128      * The results of the Browse. Each member of the list is either a String
129      * (for the authors browse) or an {@link org.dspace.content.Item}(for the
130      * other browses).
131      *
132      * @return Result list. This list cannot be modified.
133      */

134     public List JavaDoc getResults()
135     {
136         return results;
137     }
138
139     /**
140      * Return the results of the Browse as a String array.
141      *
142      * @return The results of the Browse as a String array.
143      */

144     public String JavaDoc[] getStringResults()
145     {
146         return (String JavaDoc[]) results.toArray(new String JavaDoc[results.size()]);
147     }
148
149     /**
150      * Return the results of the Browse as an Item array.
151      *
152      * @return The results of the Browse as an Item array.
153      */

154     public Item[] getItemResults()
155     {
156         return (Item[]) results.toArray(new Item[results.size()]);
157     }
158
159     /**
160      * Return the number of results.
161      *
162      * @return The number of results.
163      */

164     public int getResultCount()
165     {
166         return results.size();
167     }
168
169     /**
170      * Return the position of the results in index being browsed. This is 0 for
171      * the start of the index.
172      *
173      * @return The position of the results in index being browsed.
174      */

175     public int getOverallPosition()
176     {
177         return overallPosition;
178     }
179
180     /**
181      * Return the total number of items in the index.
182      *
183      * @return The total number of items in the index.
184      */

185     public int getTotal()
186     {
187         return total;
188     }
189
190     /**
191      * Return the position of the requested item or value in the set of results.
192      *
193      * @return The position of the requested item or value in the set of results
194      */

195     public int getOffset()
196     {
197         return offset;
198     }
199
200     /**
201      * True if there are no previous results from the browse.
202      *
203      * @return True if there are no previous results from the browse
204      */

205     public boolean isFirst()
206     {
207         return overallPosition == 0;
208     }
209
210     /**
211      * True if these are the last results from the browse.
212      *
213      * @return True if these are the last results from the browse
214      */

215     public boolean isLast()
216     {
217         return (overallPosition + getResultCount()) == total;
218     }
219
220     /**
221      * True if this browse was cached.
222      */

223     public boolean wasCached()
224     {
225         return cached;
226     }
227
228     /**
229      * Set whether this browse was cached.
230      */

231     void setCached(boolean cached)
232     {
233         this.cached = cached;
234     }
235 }
236
Popular Tags