]> git.basschouten.com Git - openhab-addons.git/blob
147c81b66acf83b0d11b4cae3a58ca934dbb42aa
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 package org.openhab.persistence.rrd4j.internal;
14
15 import java.time.ZonedDateTime;
16 import java.time.format.DateTimeFormatter;
17 import java.time.format.FormatStyle;
18 import java.util.Locale;
19
20 import org.openhab.core.persistence.HistoricItem;
21 import org.openhab.core.types.State;
22
23 /**
24  * This is a Java bean used to return historic items from a rrd4j database.
25  *
26  * @author Kai Kreuzer - Initial contribution
27  *
28  */
29 public class RRD4jItem implements HistoricItem {
30
31     private final String name;
32     private final State state;
33     private final ZonedDateTime timestamp;
34
35     public RRD4jItem(String name, State state, ZonedDateTime timestamp) {
36         this.name = name;
37         this.state = state;
38         this.timestamp = timestamp;
39     }
40
41     @Override
42     public String getName() {
43         return name;
44     }
45
46     @Override
47     public State getState() {
48         return state;
49     }
50
51     @Override
52     public ZonedDateTime getTimestamp() {
53         return timestamp;
54     }
55
56     @Override
57     public String toString() {
58         return timestamp
59                 .format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.getDefault())) + ": "
60                 + name + " -> " + state.toString();
61     }
62 }