]> git.basschouten.com Git - openhab-addons.git/blob
85c8956e43bc446f8e15b106451cf9b127224319
[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 package org.openhab.persistence.influxdb.internal;
14
15 import java.time.Instant;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.DefaultLocation;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22
23 /**
24  * Point data to be stored in InfluxDB
25  *
26  * @author Joan Pujol Espinar - Initial contribution
27  */
28 @NonNullByDefault({ DefaultLocation.PARAMETER })
29 public class InfluxPoint {
30     private String measurementName;
31     private Instant time;
32     private Object value;
33     private Map<String, String> tags;
34
35     private InfluxPoint(Builder builder) {
36         measurementName = builder.measurementName;
37         time = builder.time;
38         value = builder.value;
39         tags = builder.tags;
40     }
41
42     public static Builder newBuilder(String measurementName) {
43         return new Builder(measurementName);
44     }
45
46     public String getMeasurementName() {
47         return measurementName;
48     }
49
50     public Instant getTime() {
51         return time;
52     }
53
54     public Object getValue() {
55         return value;
56     }
57
58     public Map<String, String> getTags() {
59         return Collections.unmodifiableMap(tags);
60     }
61
62     public static final class Builder {
63         private String measurementName;
64         private Instant time;
65         private Object value;
66         private Map<String, String> tags = new HashMap<>();
67
68         private Builder(String measurementName) {
69             this.measurementName = measurementName;
70         }
71
72         public Builder withTime(Instant val) {
73             time = val;
74             return this;
75         }
76
77         public Builder withValue(Object val) {
78             value = val;
79             return this;
80         }
81
82         public Builder withTag(String name, String value) {
83             tags.put(name, value);
84             return this;
85         }
86
87         public InfluxPoint build() {
88             return new InfluxPoint(this);
89         }
90     }
91
92     @Override
93     public String toString() {
94         return "InfluxPoint{" + "measurementName='" + measurementName + '\'' + ", time=" + time + ", value=" + value
95                 + ", tags=" + tags + '}';
96     }
97 }