]> git.basschouten.com Git - openhab-addons.git/blob
145b1a350b326619f101e7726e80ebd1041ec6ca
[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.knx.internal.channel;
14
15 import static java.util.stream.Collectors.toSet;
16
17 import java.util.Collections;
18 import java.util.Objects;
19 import java.util.Set;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.core.thing.type.ChannelTypeUID;
25
26 /**
27  * Helper class to find the matching {@link KNXChannelType} for any given {@link ChannelTypeUID}.
28  *
29  * @author Simon Kaufmann - initial contribution and API.
30  *
31  */
32 @NonNullByDefault
33 public final class KNXChannelTypes {
34
35     private static final Set<KNXChannelType> TYPES = Collections.unmodifiableSet(Stream.of(//
36             new TypeColor(), //
37             new TypeContact(), //
38             new TypeDateTime(), //
39             new TypeDimmer(), //
40             new TypeNumber(), //
41             new TypeRollershutter(), //
42             new TypeString(), //
43             new TypeSwitch() //
44     ).collect(toSet()));
45
46     private KNXChannelTypes() {
47         // prevent instantiation
48     }
49
50     public static KNXChannelType getType(@Nullable ChannelTypeUID channelTypeUID) throws IllegalArgumentException {
51         Objects.requireNonNull(channelTypeUID);
52         for (KNXChannelType c : TYPES) {
53             if (c.getChannelIDs().contains(channelTypeUID.getId())) {
54                 return c;
55             }
56         }
57         throw new IllegalArgumentException(channelTypeUID.getId() + " is not a valid value channel type ID");
58     }
59 }