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.persistence.mapdb.internal;
15 import java.text.DateFormat;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
18 import java.util.Date;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.persistence.HistoricItem;
23 import org.openhab.core.persistence.PersistenceItemInfo;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
28 * This is a Java bean used to persist item states with timestamps in the database.
30 * @author Jens Viebig - Initial contribution
34 public class MapDbItem implements HistoricItem, PersistenceItemInfo {
36 private String name = "";
37 private State state = UnDefType.NULL;
38 private Date timestamp = new Date(0);
41 public String getName() {
45 public void setName(String name) {
50 public State getState() {
54 public void setState(State state) {
59 public ZonedDateTime getTimestamp() {
60 return ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
63 public void setTimestamp(Date timestamp) {
64 this.timestamp = timestamp;
68 public String toString() {
69 return DateFormat.getDateTimeInstance().format(timestamp) + ": " + name + " -> " + state.toString();
73 public @Nullable Integer getCount() {
74 return Integer.valueOf(1);
78 public @Nullable Date getEarliest() {
83 public @Nullable Date getLatest() {
87 public boolean isValid() {
88 return name != null && state != null && timestamp != null;