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.binding.satel.internal.event;
15 import java.util.BitSet;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Event class describing changes in Integra state since last state read.
22 * @author Krzysztof Goworek - Initial contribution
25 public class NewStatesEvent implements SatelEvent {
27 private BitSet newStates;
30 * Constructs event class from given {@link BitSet}.
32 * @param newStates changed states as {@link BitSet}
34 public NewStatesEvent(BitSet newStates) {
35 this.newStates = newStates;
39 * Constructs event class from given byte array.
41 * @param newStates changed states as byte array
43 public NewStatesEvent(byte[] newStates) {
44 this(BitSet.valueOf(newStates));
48 * Checks if specified state has changed since last read.
50 * @param nbr state number to check
51 * @return <code>true</code> if state has changed
53 public boolean isNew(int nbr) {
54 return newStates.get(nbr);
58 public String toString() {
59 StringBuilder newStatesStr = new StringBuilder();
60 for (int i = this.newStates.nextSetBit(0); i >= 0; i = this.newStates.nextSetBit(i + 1)) {
61 if (newStatesStr.length() > 0) {
62 newStatesStr.append(",");
64 newStatesStr.append(String.format("%02X", i));
66 return String.format("NewStatesEvent: changed = [%s]", newStatesStr);