]> git.basschouten.com Git - openhab-addons.git/blob
279bf65d02d1808a7d986c1e442c430750fe46c1
[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.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.deutschebahn.internal.filter.FilterParser;
20 import org.openhab.binding.deutschebahn.internal.filter.FilterParserException;
21 import org.openhab.binding.deutschebahn.internal.filter.FilterScanner;
22 import org.openhab.binding.deutschebahn.internal.filter.FilterScannerException;
23 import org.openhab.binding.deutschebahn.internal.filter.FilterToken;
24 import org.openhab.binding.deutschebahn.internal.filter.TimetableStopPredicate;
25
26 /**
27  * The {@link DeutscheBahnTimetableConfiguration} for the Timetable bridge-type.
28  *
29  * @author Sönke Küper - Initial contribution
30  */
31 @NonNullByDefault
32 public class DeutscheBahnTimetableConfiguration {
33
34     /**
35      * Client-ID for DB-API Application
36      */
37     public String clientId = "";
38
39     /**
40      * Client-Secret for DB-API Application
41      */
42     public String clientSecret = "";
43
44     /**
45      * evaNo of the station to be queried.
46      */
47     public String evaNo = "";
48
49     /**
50      * Filter for timetable stops.
51      */
52     public String trainFilter = "";
53
54     /**
55      * Specifies additional filters for trains to be displayed within the timetable.
56      */
57     public String additionalFilter = "";
58
59     /**
60      * Returns the {@link TimetableStopFilter}.
61      */
62     public TimetableStopFilter getTrainFilterFilter() {
63         return TimetableStopFilter.valueOf(this.trainFilter.toUpperCase());
64     }
65
66     /**
67      * Returns the additional configured {@link TimetableStopPredicate} or <code>null</code> if not specified.
68      */
69     public @Nullable TimetableStopPredicate getAdditionalFilter() throws FilterScannerException, FilterParserException {
70         if (additionalFilter.isBlank()) {
71             return null;
72         } else {
73             final FilterScanner scanner = new FilterScanner();
74             final List<FilterToken> filterTokens = scanner.processInput(additionalFilter);
75             return FilterParser.parse(filterTokens);
76         }
77     }
78 }