]> git.basschouten.com Git - openhab-addons.git/blob
f5291900cb741060d9cedef3922c7e9adc48a9ff
[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
14 package org.openhab.binding.mielecloud.internal.webservice.api;
15
16 import java.util.Objects;
17 import java.util.Optional;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23  * A physical quantity as obtained from the Miele REST API.
24  *
25  * @author Björn Lange - Initial contribution
26  */
27 @NonNullByDefault
28 public class Quantity {
29     double value;
30     Optional<String> unit;
31
32     public Quantity(double value, @Nullable String unit) {
33         this.value = value;
34         this.unit = Optional.ofNullable(unit);
35     }
36
37     public double getValue() {
38         return value;
39     }
40
41     public Optional<String> getUnit() {
42         return unit;
43     }
44
45     @Override
46     public int hashCode() {
47         return Objects.hash(value, unit);
48     }
49
50     @Override
51     public boolean equals(@Nullable Object obj) {
52         if (this == obj) {
53             return true;
54         }
55         if (obj == null) {
56             return false;
57         }
58         if (getClass() != obj.getClass()) {
59             return false;
60         }
61         Quantity other = (Quantity) obj;
62         return Double.doubleToLongBits(value) == Double.doubleToLongBits(other.value)
63                 && Objects.equals(unit, other.unit);
64     }
65
66     @Override
67     public String toString() {
68         return "Quantity [value=" + value + ", unit=" + unit + "]";
69     }
70 }