]> git.basschouten.com Git - openhab-addons.git/blob
5475334809482bf7e5e170be159700ecb7cc7adc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.smartmeter.internal.conformity.negate;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Models the negate bit - namely the OBIS code, whether its in the status bytes and on which position (of the status)
20  * it is encoded.
21  *
22  * @author Matthias Steigenberger - Initial contribution
23  *
24  */
25 @NonNullByDefault
26 public class NegateBitModel {
27
28     private int negatePosition;
29     private boolean negateBit;
30     private String negateObis;
31     private boolean status;
32
33     /**
34      *
35      * @param negatePosition
36      * @param negateBit
37      * @param negateObis
38      * @param status Whether to get the negate bit from status value or from actual value.
39      */
40     public NegateBitModel(int negatePosition, boolean negateBit, String negateObis, boolean status) {
41         this.negatePosition = negatePosition;
42         this.negateBit = negateBit;
43         this.negateObis = negateObis;
44         this.status = status;
45     }
46
47     public int getNegatePosition() {
48         return negatePosition;
49     }
50
51     public boolean isNegateBit() {
52         return negateBit;
53     }
54
55     public String getNegateChannelId() {
56         return negateObis;
57     }
58
59     @Override
60     public int hashCode() {
61         final int prime = 31;
62         int result = 1;
63         result = prime * result + (negateBit ? 1231 : 1237);
64         result = prime * result + (negateObis.hashCode());
65         result = prime * result + negatePosition;
66         return result;
67     }
68
69     @SuppressWarnings("PMD.SimplifyBooleanReturns")
70     @Override
71     public boolean equals(@Nullable Object obj) {
72         if (this == obj) {
73             return true;
74         }
75         if (obj == null) {
76             return false;
77         }
78         if (getClass() != obj.getClass()) {
79             return false;
80         }
81         NegateBitModel other = (NegateBitModel) obj;
82         if (negateBit != other.negateBit) {
83             return false;
84         }
85         if (!negateObis.equals(other.negateObis)) {
86             return false;
87         }
88         if (negatePosition != other.negatePosition) {
89             return false;
90         }
91         return true;
92     }
93
94     public boolean isStatus() {
95         return status;
96     }
97 }