2 * Copyright (c) 2010-2024 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());
77 @SuppressWarnings("PMD.SimplifyBooleanReturns")
79 public boolean equals(@Nullable Object obj) {
86 if (getClass() != obj.getClass()) {
89 MeterValue<?> other = (MeterValue<?>) obj;
90 if (!obis.equals(other.obis)) {
94 if (other.status != null) {
97 } else if (!status.equals(other.status)) {
101 if (other.unit != null) {
104 } else if (!unit.equals(other.unit)) {
107 if (!value.equals(other.value)) {
114 public String toString() {
115 return "MeterValue [obis=" + obis + ", value=" + value + ", unit=" + unit + "]";
118 public String getObisCode() {
122 public @Nullable String getStatus() {
126 public void setStatus(String status) {
127 this.status = status;