]> git.basschouten.com Git - openhab-addons.git/blob
f04d0a09a940ea9ee2883f8dc70602035bfb3d10
[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 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      * Access-Token.
36      */
37     public String accessToken = "";
38
39     /**
40      * evaNo of the station to be queried.
41      */
42     public String evaNo = "";
43
44     /**
45      * Filter for timetable stops.
46      */
47     public String trainFilter = "";
48
49     /**
50      * Specifies additional filters for trains to be displayed within the timetable.
51      */
52     public String additionalFilter = "";
53
54     /**
55      * Returns the {@link TimetableStopFilter}.
56      */
57     public TimetableStopFilter getTrainFilterFilter() {
58         return TimetableStopFilter.valueOf(this.trainFilter.toUpperCase());
59     }
60
61     /**
62      * Returns the additional configured {@link TimetableStopPredicate} or <code>null</code> if not specified.
63      */
64     public @Nullable TimetableStopPredicate getAdditionalFilter() throws FilterScannerException, FilterParserException {
65         if (additionalFilter.isBlank()) {
66             return null;
67         } else {
68             final FilterScanner scanner = new FilterScanner();
69             final List<FilterToken> filterTokens = scanner.processInput(additionalFilter);
70             return FilterParser.parse(filterTokens);
71         }
72     }
73 }