01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/calendar-api/api/src/java/org/sakaiproject/calendar/api/CalendarEventVector.java $
03: * $Id: CalendarEventVector.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.calendar.api;
21:
22: import java.util.Iterator;
23: import java.util.Vector;
24:
25: import org.sakaiproject.time.api.TimeRange;
26:
27: /**
28: * <p>CalendarEventVector is a helper class for the Calendar service. It will read in
29: * a bunch of CalendarEvents from an iterator, place them into a vector, and provide
30: * time range controlled access to the events.</p>
31: * <p>Use this to make larger, more user action aligned service requests, but still have fine
32: * grained time range access to the events returned.</p>
33: */
34: public class CalendarEventVector extends Vector {
35: /**
36: * Construct empty.
37: */
38: public CalendarEventVector() {
39: super ();
40: }
41:
42: /**
43: * Construct
44: * @param events An interator on CalendarEvents to load into the vector.
45: */
46: public CalendarEventVector(Iterator events) {
47: super ();
48:
49: while (events.hasNext()) {
50: add(events.next());
51: }
52:
53: } // CalendarEventVector
54:
55: /**
56: * Return an iterator on events in the CalendarEventVector.
57: * The order in which the events will be found in the iteration is by event start date.
58: * @param range A time range to limit the iterated events. May be null; all events will be returned.
59: * @return an iterator on CalendarEvent objects in the CalendarEventVector (may be empty).
60: */
61: public Iterator getEvents(TimeRange range) {
62: // pull the range of events from vector
63: Vector events = new Vector();
64: Iterator it = iterator();
65: while (it.hasNext()) {
66: CalendarEvent test = (CalendarEvent) it.next();
67: if (range.overlaps(test.getRange())) {
68: events.add(test);
69: }
70: // %%% if test is past range, we can stop now...
71: }
72:
73: return events.iterator();
74:
75: } // getEvents
76:
77: } // CalendarEventVector
|