]> git.basschouten.com Git - openhab-addons.git/blob
121ea70ecec5a4c5adafb451f8cc1f74c10746f3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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() & getJustEndedEvents()
29  */
30 @NonNullByDefault
31 public abstract class AbstractPresentableCalendar {
32
33     /**
34      * Creates an implementing Instance of AbstractPresentableCalendar.
35      *
36      * @param calendarStream A Stream containing the iCal data.
37      * @return The instance.
38      * @throws IOException When something while reading stream fails.
39      * @throws CalendarException When something while parsing fails.
40      */
41     public static AbstractPresentableCalendar create(InputStream calendarStream) throws IOException, CalendarException {
42         return new BiweeklyPresentableCalendar(calendarStream);
43     }
44
45     /**
46      * Searches the event currently (at given Instant) present.
47      *
48      * @param instant The Instant, the event should be returned for.
49      * @return The current {@link Event} containing the data of the event or
50      *         null if no event is present.
51      */
52     public abstract @Nullable Event getCurrentEvent(Instant instant);
53
54     /**
55      * Return a list of events that have just begun within the time frame
56      *
57      * @param frameBegin the start of the time frame
58      * @param frameEnd the start of the time frame
59      * @return list of iCalendar Events that BEGIN within the time frame
60      */
61     public abstract List<Event> getJustBegunEvents(Instant frameBegin, Instant frameEnd);
62
63     /**
64      * Return a list of events that have just ended within the time frame
65      *
66      * @param frameBegin the start of the time frame
67      * @param frameEnd the start of the time frame
68      * @return list of iCalendar Events that END within the time frame
69      */
70     public abstract List<Event> getJustEndedEvents(Instant frameBegin, Instant frameEnd);
71
72     /**
73      * The next event after given instant.
74      *
75      * @param instant The Instant after which the next event should be
76      *            searched.
77      * @return The next event after the given Instant or null if there is any
78      *         further in the calendar.
79      */
80     public abstract @Nullable Event getNextEvent(Instant instant);
81
82     /**
83      * Checks whether an event is present at given Instant.
84      *
85      * @param instant The Instant, that should be checked.
86      * @return True if an event is present.
87      */
88     public abstract boolean isEventPresent(Instant instant);
89 }