2 * Copyright (c) 2010-2022 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.smartmeter.internal;
15 import javax.measure.Quantity;
16 import javax.measure.Unit;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Represents one value of the meter device.
24 * @author Matthias Steigenberger - Initial contribution
28 public class MeterValue<Q extends Quantity<Q>> {
33 private Unit<? extends Q> unit;
35 private String status;
37 public MeterValue(String obis, String value, @Nullable Unit<? extends Q> unit, @Nullable String status) {
44 public MeterValue(String obis, String value, @Nullable Unit<Q> unit) {
45 this(obis, value, unit, null);
49 * Gets the values unit.
51 * @return the string representation of the values unit - otherwise null.
53 public @Nullable Unit<? extends Q> getUnit() {
60 * @return the value as String if available - otherwise null.
62 public String getValue() {
67 public int hashCode() {
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());
78 public boolean equals(@Nullable Object obj) {
85 if (getClass() != obj.getClass()) {
88 MeterValue<?> other = (MeterValue<?>) obj;
89 if (!obis.equals(other.obis)) {
93 if (other.status != null) {
96 } else if (!status.equals(other.status)) {
100 if (other.unit != null) {
103 } else if (!unit.equals(other.unit)) {
106 if (!value.equals(other.value)) {
113 public String toString() {
114 return "MeterValue [obis=" + obis + ", value=" + value + ", unit=" + unit + "]";
117 public String getObisCode() {
121 public @Nullable String getStatus() {
125 public void setStatus(String status) {
126 this.status = status;