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.binding.siemensrds.internal;
15 import static org.openhab.binding.siemensrds.internal.RdsBindingConstants.DEBOUNCE_DELAY;
17 import java.util.Date;
18 import java.util.HashMap;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
25 * The {@link RdsDebouncer} determines if change events should be forwarded to a
28 * @author Andrew Fiddian-Green - Initial contribution
31 public class RdsDebouncer {
33 private final Map<String, @Nullable DebounceDelay> channels = new HashMap<>();
35 @SuppressWarnings("null")
37 static class DebounceDelay {
39 private long expireTime;
41 public DebounceDelay(boolean enabled) {
43 expireTime = new Date().getTime() + (DEBOUNCE_DELAY * 1000);
47 public boolean timeExpired() {
48 return (expireTime < new Date().getTime());
52 public RdsDebouncer() {
55 public void initialize(String channelId) {
56 channels.put(channelId, new DebounceDelay(true));
59 public Boolean timeExpired(String channelId) {
60 if (channels.containsKey(channelId)) {
62 DebounceDelay debounceDelay = channels.get(channelId);
63 if (debounceDelay != null) {
64 return ((DebounceDelay) debounceDelay).timeExpired();