2 * Copyright (c) 2010-2022 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 thingTable.put(key, thing);
37 public ShellyThingInterface getThing(String key) {
38 ShellyThingInterface t = thingTable.get(key);
42 for (Map.Entry<String, ShellyThingInterface> entry : thingTable.entrySet()) {
44 if (t.checkRepresentation(key)) {
48 throw new IllegalArgumentException();
51 public void removeThing(String key) {
52 if (thingTable.containsKey(key)) {
53 thingTable.remove(key);
57 public Map<String, ShellyThingInterface> getTable() {
62 return thingTable.size();