]> git.basschouten.com Git - openhab-addons.git/blob
c93e939e28e62e615f602d87fc9f3c4790412a2d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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;
14
15 import javax.measure.Quantity;
16 import javax.measure.Unit;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Represents one value of the meter device.
23  *
24  * @author Matthias Steigenberger - Initial contribution
25  *
26  */
27 @NonNullByDefault
28 public class MeterValue<Q extends Quantity<Q>> {
29
30     private String obis;
31     private String value;
32     @Nullable
33     private Unit<? extends Q> unit;
34     @Nullable
35     private String status;
36
37     public MeterValue(String obis, String value, @Nullable Unit<? extends Q> unit, @Nullable String status) {
38         this.obis = obis;
39         this.unit = unit;
40         this.value = value;
41         this.status = status;
42     }
43
44     public MeterValue(String obis, String value, @Nullable Unit<Q> unit) {
45         this(obis, value, unit, null);
46     }
47
48     /**
49      * Gets the values unit.
50      *
51      * @return the string representation of the values unit - otherwise null.
52      */
53     public @Nullable Unit<? extends Q> getUnit() {
54         return unit;
55     }
56
57     /**
58      * Gets the value
59      *
60      * @return the value as String if available - otherwise null.
61      */
62     public String getValue() {
63         return value;
64     }
65
66     @Override
67     public int hashCode() {
68         final int prime = 31;
69         int result = 1;
70         result = prime * result + ((obis == null) ? 0 : obis.hashCode());
71         result = prime * result + ((status == null) ? 0 : status.hashCode());
72         result = prime * result + ((unit == null) ? 0 : unit.hashCode());
73         result = prime * result + ((value == null) ? 0 : value.hashCode());
74         return result;
75     }
76
77     @SuppressWarnings("PMD.SimplifyBooleanReturns")
78     @Override
79     public boolean equals(@Nullable Object obj) {
80         if (this == obj) {
81             return true;
82         }
83         if (obj == null) {
84             return false;
85         }
86         if (getClass() != obj.getClass()) {
87             return false;
88         }
89         MeterValue<?> other = (MeterValue<?>) obj;
90         if (!obis.equals(other.obis)) {
91             return false;
92         }
93         if (status == null) {
94             if (other.status != null) {
95                 return false;
96             }
97         } else if (!status.equals(other.status)) {
98             return false;
99         }
100         if (unit == null) {
101             if (other.unit != null) {
102                 return false;
103             }
104         } else if (!unit.equals(other.unit)) {
105             return false;
106         }
107         if (!value.equals(other.value)) {
108             return false;
109         }
110         return true;
111     }
112
113     @Override
114     public String toString() {
115         return "MeterValue [obis=" + obis + ", value=" + value + ", unit=" + unit + "]";
116     }
117
118     public String getObisCode() {
119         return this.obis;
120     }
121
122     public @Nullable String getStatus() {
123         return status;
124     }
125
126     public void setStatus(String status) {
127         this.status = status;
128     }
129 }