]> git.basschouten.com Git - openhab-addons.git/blob
ef23fdf78f52282c39140f1abc2029af8f4879ec
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.mongodb.internal;
14
15 import java.text.DateFormat;
16 import java.time.ZonedDateTime;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.persistence.HistoricItem;
20 import org.openhab.core.types.State;
21
22 /**
23  * This is the implementation of the MongoDB historic item.
24  *
25  * @author Thorsten Hoeger - Initial contribution
26  */
27 @NonNullByDefault
28 public class MongoDBItem implements HistoricItem {
29
30     private final String name;
31     private final State state;
32     private final ZonedDateTime timestamp;
33
34     public MongoDBItem(String name, State state, ZonedDateTime timestamp) {
35         this.name = name;
36         this.state = state;
37         this.timestamp = timestamp;
38     }
39
40     @Override
41     public String getName() {
42         return name;
43     }
44
45     @Override
46     public State getState() {
47         return state;
48     }
49
50     @Override
51     public ZonedDateTime getTimestamp() {
52         return timestamp;
53     }
54
55     @Override
56     public String toString() {
57         return DateFormat.getDateTimeInstance().format(timestamp) + ": " + name + " -> " + state.toString();
58     }
59 }