2 * Copyright (c) 2010-2020 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()
31 public abstract class AbstractPresentableCalendar {
34 * Creates an implementing Instance of AbstractPresentableCalendar.
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.
41 public static AbstractPresentableCalendar create(InputStream calendarStream) throws IOException, CalendarException {
42 return new BiweeklyPresentableCalendar(calendarStream);
46 * Searches the event currently (at given Instant) present.
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.
52 public abstract @Nullable Event getCurrentEvent(Instant instant);
55 * Return a list of events that have just begun within the time frame
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
61 public abstract List<Event> getJustBegunEvents(Instant frameBegin, Instant frameEnd);
64 * Return a list of events that have just ended within the time frame
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
70 public abstract List<Event> getJustEndedEvents(Instant frameBegin, Instant frameEnd);
73 * The next event after given instant.
75 * @param instant The Instant after which the next event should be
77 * @return The next event after the given Instant or null if there is any
78 * further in the calendar.
80 public abstract @Nullable Event getNextEvent(Instant instant);
83 * Checks whether an event is present at given Instant.
85 * @param instant The Instant, that should be checked.
86 * @return True if an event is present.
88 public abstract boolean isEventPresent(Instant instant);