2 * Copyright (c) 2010-2023 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.plugwiseha.internal.api.model.dto;
15 import java.time.ZonedDateTime;
16 import java.util.Optional;
18 import com.thoughtworks.xstream.annotations.XStreamAlias;
21 * @author B. van Wetten - Initial contribution
22 * @author Leo Siepel - finish initial contribution
24 @XStreamAlias("point_log")
25 public class Log extends PlugwiseBaseModel implements PlugwiseComparableDate<Log> {
31 private String measurement;
33 @XStreamAlias("measurement_date")
34 private ZonedDateTime measurementDate;
36 @XStreamAlias("updated_date")
37 private ZonedDateTime updatedDate;
39 public String getType() {
43 public String getUnit() {
47 public Optional<String> getMeasurement() {
48 return Optional.ofNullable(measurement);
51 public Optional<Boolean> getMeasurementAsBoolean() {
52 if (measurement != null) {
53 switch (measurement.toLowerCase()) {
55 return Optional.of(true);
57 return Optional.of(false);
59 return Optional.empty();
62 return Optional.empty();
66 public Optional<Double> getMeasurementAsDouble() {
68 if (measurement != null) {
69 return Optional.of(Double.parseDouble(measurement));
71 return Optional.empty();
73 } catch (NumberFormatException e) {
74 return Optional.empty();
78 public Optional<String> getMeasurementUnit() {
79 return Optional.ofNullable(unit);
82 public ZonedDateTime getMeasurementDate() {
83 return measurementDate;
87 public ZonedDateTime getUpdatedDate() {
92 public int compareDateWith(Log compareTo) {
93 if (compareTo == null) {
96 ZonedDateTime compareToDate = compareTo.getMeasurementDate();
97 ZonedDateTime compareFromDate = this.getMeasurementDate();
98 if (compareFromDate == null) {
100 } else if (compareToDate == null) {
103 return compareFromDate.compareTo(compareToDate);
108 public boolean isNewerThan(Log hasModifiedDate) {
109 return compareDateWith(hasModifiedDate) > 0;
113 public boolean isOlderThan(Log hasModifiedDate) {
114 return compareDateWith(hasModifiedDate) < 0;