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.deutschebahn.internal;
15 import java.util.function.Function;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.deutschebahn.internal.timetable.dto.Event;
20 import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
23 * Type of an {@link Event} within a {@link TimetableStop}.
25 * @author Sönke Küper - initial contribution
28 public enum EventType {
31 * Selects the Arrival-Element (i.e. ar).
33 ARRIVAL(TimetableStop::getAr, TimetableStop::getDp),
36 * Selects the departure element (i.e. dp).
38 DEPARTURE(TimetableStop::getDp, TimetableStop::getAr);
40 private final Function<TimetableStop, @Nullable Event> getter;
41 private final Function<TimetableStop, @Nullable Event> oppositeGetter;
43 private EventType(Function<TimetableStop, @Nullable Event> getter,
44 Function<TimetableStop, @Nullable Event> oppositeGetter) {
46 this.oppositeGetter = oppositeGetter;
50 * Returns the selected event from the given {@link TimetableStop}.
53 public final Event getEvent(TimetableStop stop) {
54 return this.getter.apply(stop);
58 * Returns the opposite event from the given {@link TimetableStop}.
61 public final Event getOppositeEvent(TimetableStop stop) {
62 return this.oppositeGetter.apply(stop);