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.io.hueemulation.internal.rest.mocks;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.List;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.core.common.registry.RegistryChangeListener;
25 import org.openhab.core.items.Metadata;
26 import org.openhab.core.items.MetadataKey;
27 import org.openhab.core.items.MetadataRegistry;
30 * @author David Graeff - Initial contribution
33 public class DummyMetadataRegistry implements MetadataRegistry {
34 Map<MetadataKey, Metadata> items = new HashMap<>();
35 List<RegistryChangeListener<Metadata>> listeners = new ArrayList<>();
38 public void addRegistryChangeListener(RegistryChangeListener<Metadata> listener) {
39 listeners.add(listener);
43 public Collection<Metadata> getAll() {
44 return items.values();
48 public Stream<Metadata> stream() {
49 return items.values().stream();
53 public @Nullable Metadata get(@Nullable MetadataKey key) {
54 return items.get(key);
58 public void removeRegistryChangeListener(RegistryChangeListener<Metadata> listener) {
59 listeners.remove(listener);
63 public Metadata add(Metadata element) {
64 items.put(element.getUID(), element);
65 for (RegistryChangeListener<Metadata> l : listeners) {
72 public @Nullable Metadata update(Metadata element) {
73 Metadata put = items.put(element.getUID(), element);
75 for (RegistryChangeListener<Metadata> l : listeners) {
76 l.updated(put, element);
83 public @Nullable Metadata remove(MetadataKey key) {
84 Metadata put = items.remove(key);
86 for (RegistryChangeListener<Metadata> l : listeners) {
94 public boolean isInternalNamespace(String namespace) {
99 public void removeItemMetadata(String name) {