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.Collections;
16 import java.util.List;
17 import java.util.Objects;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.deutschebahn.internal.timetable.dto.Event;
22 import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
23 import org.openhab.core.types.State;
24 import org.openhab.core.types.UnDefType;
27 * Selection that returns the value of an {@link EventAttribute}. The required {@link Event} is
28 * selected with the given {@link EventType}.
30 * @author Sönke Küper - Initial contribution
33 public final class EventAttributeSelection implements AttributeSelection {
35 private final EventType eventType;
36 private final EventAttribute<?, ?> eventAttribute;
39 * Creates a new {@link EventAttributeSelection}.
41 public EventAttributeSelection(EventType eventType, EventAttribute<?, ?> eventAttribute) {
42 this.eventType = eventType;
43 this.eventAttribute = eventAttribute;
48 public State getState(TimetableStop stop) {
49 final Event event = eventType.getEvent(stop);
51 return UnDefType.UNDEF;
53 return this.eventAttribute.getState(event);
58 public @Nullable Object getValue(TimetableStop stop) {
59 final Event event = eventType.getEvent(stop);
61 return UnDefType.UNDEF;
63 return this.eventAttribute.getValue(event);
68 public List<String> getStringValues(TimetableStop stop) {
69 final Event event = eventType.getEvent(stop);
71 return Collections.emptyList();
73 return this.eventAttribute.getStringValues(event);
78 public int hashCode() {
79 return Objects.hash(eventAttribute, eventType);
83 public boolean equals(@Nullable Object obj) {
84 if (!(obj instanceof EventAttributeSelection)) {
87 final EventAttributeSelection other = (EventAttributeSelection) obj;
88 return Objects.equals(eventAttribute, other.eventAttribute) && eventType == other.eventType;