]> git.basschouten.com Git - openhab-addons.git/blob
b76f43ebf76d37e8663061d404af871f297ca4fd
[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.deutschebahn.internal;
14
15 import java.util.function.Function;
16
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;
21
22 /**
23  * Type of an {@link Event} within a {@link TimetableStop}.
24  * 
25  * @author Sönke Küper - initial contribution
26  */
27 @NonNullByDefault
28 public enum EventType {
29
30     /**
31      * Selects the Arrival-Element (i.e. ar).
32      */
33     ARRIVAL(TimetableStop::getAr, TimetableStop::getDp),
34
35     /**
36      * Selects the departure element (i.e. dp).
37      */
38     DEPARTURE(TimetableStop::getDp, TimetableStop::getAr);
39
40     private final Function<TimetableStop, @Nullable Event> getter;
41     private final Function<TimetableStop, @Nullable Event> oppositeGetter;
42
43     private EventType(Function<TimetableStop, @Nullable Event> getter,
44             Function<TimetableStop, @Nullable Event> oppositeGetter) {
45         this.getter = getter;
46         this.oppositeGetter = oppositeGetter;
47     }
48
49     /**
50      * Returns the selected event from the given {@link TimetableStop}.
51      */
52     @Nullable
53     public final Event getEvent(TimetableStop stop) {
54         return this.getter.apply(stop);
55     }
56
57     /**
58      * Returns the opposite event from the given {@link TimetableStop}.
59      */
60     @Nullable
61     public final Event getOppositeEvent(TimetableStop stop) {
62         return this.oppositeGetter.apply(stop);
63     }
64 }