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.shelly.internal.handler;
16 import java.util.concurrent.ConcurrentHashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.ConfigurationPolicy;
23 * The{@link ShellyThingTable} implements a simple table to allow dispatching incoming events to the proper thing
26 * @author Markus Michels - Initial contribution
29 @Component(service = ShellyThingTable.class, configurationPolicy = ConfigurationPolicy.OPTIONAL)
30 public class ShellyThingTable {
31 private Map<String, ShellyThingInterface> thingTable = new ConcurrentHashMap<>();
33 public void addThing(String key, ShellyThingInterface thing) {
34 if (thingTable.containsKey(key)) {
35 thingTable.remove(key);
37 thingTable.put(key, thing);
40 public ShellyThingInterface getThing(String key) {
41 ShellyThingInterface t = thingTable.get(key);
45 for (Map.Entry<String, ShellyThingInterface> entry : thingTable.entrySet()) {
47 if (t.checkRepresentation(key)) {
51 throw new IllegalArgumentException();
54 public void removeThing(String key) {
55 if (thingTable.containsKey(key)) {
56 thingTable.remove(key);
60 public Map<String, ShellyThingInterface> getTable() {
65 return thingTable.size();