]> git.basschouten.com Git - openhab-addons.git/blob
a9cdf31876d505112e56b2a56f2636e08977c78b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.freeathomesystem.internal.type;
14
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.Locale;
19 import java.util.Map;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.thing.type.ChannelType;
24 import org.openhab.core.thing.type.ChannelTypeProvider;
25 import org.openhab.core.thing.type.ChannelTypeUID;
26 import org.osgi.service.component.annotations.Component;
27
28 /**
29  *
30  * @author Andras Uhrin - Initial contribution
31  *
32  */
33 @Component(service = { FreeAtHomeChannelTypeProvider.class, ChannelTypeProvider.class })
34 @NonNullByDefault
35 public class FreeAtHomeChannelTypeProviderImpl implements FreeAtHomeChannelTypeProvider {
36
37     private final Map<ChannelTypeUID, ChannelType> channelTypesByUID = new HashMap<>();
38
39     @Override
40     public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
41         Collection<ChannelType> result = new ArrayList<>();
42
43         for (ChannelTypeUID uid : channelTypesByUID.keySet()) {
44             ChannelType channelType = channelTypesByUID.get(uid);
45
46             if (channelType != null) {
47                 result.add(channelType);
48             }
49         }
50
51         return result;
52     }
53
54     @Override
55     public @Nullable ChannelType getChannelType(@Nullable ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
56         return channelTypesByUID.get(channelTypeUID);
57     }
58
59     @Override
60     public void addChannelType(@Nullable ChannelType channelType) {
61         if (channelType != null) {
62             channelTypesByUID.put(channelType.getUID(), channelType);
63         }
64     }
65 }