]> git.basschouten.com Git - openhab-addons.git/blob
c1bbe92793d6be0eaf4ee2233632b7d787f308cd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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     @Override
70     public boolean equals(@Nullable Object obj) {
71         if (this == obj) {
72             return true;
73         }
74         if (obj == null) {
75             return false;
76         }
77         if (getClass() != obj.getClass()) {
78             return false;
79         }
80         NegateBitModel other = (NegateBitModel) obj;
81         if (negateBit != other.negateBit) {
82             return false;
83         }
84         if (!negateObis.equals(other.negateObis)) {
85             return false;
86         }
87         if (negatePosition != other.negatePosition) {
88             return false;
89         }
90         return true;
91     }
92
93     public boolean isStatus() {
94         return status;
95     }
96 }