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