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.filter;
15 import java.util.List;
16 import java.util.regex.Pattern;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.deutschebahn.internal.AttributeSelection;
20 import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
23 * Abstract predicate that filters timetable stops by a selected attribute of a {@link TimetableStop}.
25 * If value has multiple values (for example stations on the planned-path) the predicate will return <code>true</code>,
26 * if at least one value matches the given filter.
28 * @author Sönke Küper - initial contribution
31 public final class TimetableStopByStringEventAttributeFilter implements TimetableStopPredicate {
33 private final AttributeSelection attributeSelection;
34 private final Pattern filter;
37 * Creates a new {@link TimetableStopByStringEventAttributeFilter}.
39 TimetableStopByStringEventAttributeFilter(final AttributeSelection attributeSelection, final Pattern filter) {
40 this.attributeSelection = attributeSelection;
45 public boolean test(TimetableStop t) {
46 final List<String> values = attributeSelection.getStringValues(t);
48 for (String actualValue : values) {
49 if (filter.matcher(actualValue).matches()) {
57 * Returns the {@link AttributeSelection}.
59 final AttributeSelection getAttributeSelection() {
60 return attributeSelection;
64 * Returns the filter pattern.
66 final Pattern getFilter() {