2 * Copyright (c) 2010-2020 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();
49 public Stream<Rule> stream() {
50 return items.values().stream();
54 public @Nullable Rule get(@Nullable String key) {
55 return items.get(key);
59 public void removeRegistryChangeListener(RegistryChangeListener<Rule> listener) {
60 listeners.remove(listener);
64 public Rule add(Rule element) {
65 Rule put = items.put(element.getUID(), element);
66 for (RegistryChangeListener<Rule> l : listeners) {
73 public @Nullable Rule update(Rule element) {
74 Rule put = items.put(element.getUID(), element);
75 for (RegistryChangeListener<Rule> l : listeners) {
76 l.updated(put, element);
82 public @Nullable Rule remove(String key) {
83 Rule put = items.remove(key);
84 for (RegistryChangeListener<Rule> l : listeners) {
92 public Collection<Rule> getByTag(String tag) {
93 return Collections.emptyList();
98 public Collection<Rule> getByTags(String... tags) {
99 return Collections.emptyList();