2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.icalendar.internal.logic;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.time.Instant;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
24 * A calendar which provides the interface to the calendar implementation for
25 * the binding, encapsulating the implementation of the real calendar.
27 * @author Michael Wodniok - Initial contribution
28 * @author Andrew Fiddian-Green - Methods getJustBegunEvents() & getJustEndedEvents()
29 * @author Michael Wodniok - Added getFilteredEventsBetween()
32 public abstract class AbstractPresentableCalendar {
35 * Creates an implementing Instance of AbstractPresentableCalendar.
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.
42 public static AbstractPresentableCalendar create(InputStream calendarStream) throws IOException, CalendarException {
43 return new BiweeklyPresentableCalendar(calendarStream);
47 * Searches the event currently (at given Instant) present.
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.
53 public abstract @Nullable Event getCurrentEvent(Instant instant);
56 * Return a list of events that have just begun within the time frame
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
62 public abstract List<Event> getJustBegunEvents(Instant frameBegin, Instant frameEnd);
65 * Return a list of events that have just ended within the time frame
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
71 public abstract List<Event> getJustEndedEvents(Instant frameBegin, Instant frameEnd);
74 * The next event after given instant.
76 * @param instant The Instant after which the next event should be
78 * @return The next event after the given Instant or null if there is any
79 * further in the calendar.
81 public abstract @Nullable Event getNextEvent(Instant instant);
84 * Checks whether an event is present at given Instant.
86 * @param instant The Instant, that should be checked.
87 * @return True if an event is present.
89 public abstract boolean isEventPresent(Instant instant);
92 * Return a filtered List of events with a maximum count, ordered by start.
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.
100 public abstract List<Event> getFilteredEventsBetween(Instant begin, Instant end, @Nullable EventTextFilter filter,