]> git.basschouten.com Git - openhab-addons.git/blob
51224949f9a100fe2b1f271a79b647d5cc1b486c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.deutschebahn.internal.timetable.dto.Event;
18 import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
19 import org.openhab.core.types.State;
20 import org.openhab.core.types.UnDefType;
21
22 /**
23  * Selection that returns the value of an {@link EventAttribute}. The required {@link Event} is
24  * selected with the given {@link EventType}.
25  * 
26  * @author Sönke Küper - Initial contribution
27  */
28 @NonNullByDefault
29 public final class EventAttributeSelection implements AttributeSelection {
30
31     private final EventType eventType;
32     private final EventAttribute<?, ?> eventAttribute;
33
34     /**
35      * Creates an new {@link EventAttributeSelection}.
36      */
37     public EventAttributeSelection(EventType eventType, EventAttribute<?, ?> eventAttribute) {
38         this.eventType = eventType;
39         this.eventAttribute = eventAttribute;
40     }
41
42     @Nullable
43     @Override
44     public State getState(TimetableStop stop) {
45         final Event event = eventType.getEvent(stop);
46         if (event == null) {
47             return UnDefType.UNDEF;
48         } else {
49             return this.eventAttribute.getState(event);
50         }
51     }
52 }