2 * Copyright (c) 2010-2024 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.nobohub.internal.model;
15 import java.util.Collection;
16 import java.util.HashMap;
19 import javax.validation.constraints.NotNull;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
25 * Stores a mapping between component ids and components that exists.
27 * @author Jørgen Austvik - Initial contribution
28 * @author Espen Fossen - Initial contribution
31 public final class ComponentRegister {
33 private final @NotNull Map<SerialNumber, Component> register = new HashMap<SerialNumber, Component>();
36 * Stores a new Component in the register. If a component exists with the same id, that value is overwritten.
38 * @param component The Component to store.
40 public void put(Component component) {
41 register.put(component.getSerialNumber(), component);
45 * Removes a component from the registry.
47 * @param componentId The component to remove
48 * @return The component that is removed. Null if the component is not found.
50 public @Nullable Component remove(SerialNumber componentId) {
51 return register.remove(componentId);
55 * Returns a component from the registry.
57 * @param componentId The id of the component to return.
58 * @return Returns the component, or null if it doesn't exist in the regestry.
60 public @Nullable Component get(SerialNumber componentId) {
61 return register.get(componentId);
64 public Collection<Component> values() {
65 return register.values();