]> git.basschouten.com Git - openhab-addons.git/blob
a401547e6c00a4f21882bbda6508316a0adab54b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.icalendar.internal.logic;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.time.Instant;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22
23 /**
24  * A calendar which provides the interface to the calendar implementation for
25  * the binding, encapsulating the implementation of the real calendar.
26  *
27  * @author Michael Wodniok - Initial contribution
28  * @author Andrew Fiddian-Green - Methods getJustBegunEvents() and getJustEndedEvents()
29  * @author Michael Wodniok - Added getFilteredEventsBetween()
30  */
31 @NonNullByDefault
32 public abstract class AbstractPresentableCalendar {
33
34     /**
35      * Creates an implementing Instance of AbstractPresentableCalendar.
36      *
37      * @param calendarStream A Stream containing the iCal data.
38      * @return The instance.
39      * @throws IOException When something while reading stream fails.
40      * @throws CalendarException When something while parsing fails.
41      */
42     public static AbstractPresentableCalendar create(InputStream calendarStream) throws IOException, CalendarException {
43         return new BiweeklyPresentableCalendar(calendarStream);
44     }
45
46     /**
47      * Searches the event currently (at given Instant) present.
48      *
49      * @param instant The Instant, the event should be returned for.
50      * @return The current {@link Event} containing the data of the event or
51      *         null if no event is present.
52      */
53     public abstract @Nullable Event getCurrentEvent(Instant instant);
54
55     /**
56      * Return a list of events that have just begun within the time frame
57      *
58      * @param frameBegin the start of the time frame
59      * @param frameEnd the start of the time frame
60      * @return list of iCalendar Events that BEGIN within the time frame
61      */
62     public abstract List<Event> getJustBegunEvents(Instant frameBegin, Instant frameEnd);
63
64     /**
65      * Return a list of events that have just ended within the time frame
66      *
67      * @param frameBegin the start of the time frame
68      * @param frameEnd the start of the time frame
69      * @return list of iCalendar Events that END within the time frame
70      */
71     public abstract List<Event> getJustEndedEvents(Instant frameBegin, Instant frameEnd);
72
73     /**
74      * The next event after given instant.
75      *
76      * @param instant The Instant after which the next event should be
77      *            searched.
78      * @return The next event after the given Instant or null if there is any
79      *         further in the calendar.
80      */
81     public abstract @Nullable Event getNextEvent(Instant instant);
82
83     /**
84      * Checks whether an event is present at given Instant.
85      *
86      * @param instant The Instant, that should be checked.
87      * @return True if an event is present.
88      */
89     public abstract boolean isEventPresent(Instant instant);
90
91     /**
92      * Return a filtered List of events with a maximum count, ordered by start.
93      *
94      * @param begin The begin of the time range where to search for events
95      * @param end The end of the time range where to search for events
96      * @param filter A filter for contents, if set to null, all events will be returned
97      * @param maximumCount The maximum of events returned here.
98      * @return A list with the filtered results.
99      */
100     public abstract List<Event> getFilteredEventsBetween(Instant begin, Instant end, @Nullable EventTextFilter filter,
101             int maximumCount);
102 }