blob: 8c45a6026280e84d04c6bb681bdd22e592daef90 [file] [log] [blame]
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacktelemetry.impl;
17
18import org.onosproject.openstacktelemetry.api.InfluxRecord;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_MEASUREMENT;
24
25
26public final class DefaultInfluxRecord<K, V> implements InfluxRecord<K, V> {
27 public static final String MEASUREMENT_NAME = DEFAULT_INFLUXDB_MEASUREMENT;
28 private final K measurement;
29 private final V flowInfos;
30
31 protected DefaultInfluxRecord(K measurement, V flowInfos) {
32 if ((measurement == null) || (measurement.equals(""))) {
33 this.measurement = (K) MEASUREMENT_NAME;
34 } else {
35 this.measurement = measurement;
36 }
37 this.flowInfos = flowInfos;
38 }
39
40 @Override
41 public K measurement() {
42 return measurement;
43 }
44
45 @Override
46 public V flowInfos() {
47 return flowInfos;
48 }
49
50 @Override
51 public boolean equals(Object obj) {
52 if (this == obj) {
53 return true;
54 }
55
56 if (obj instanceof DefaultInfluxRecord) {
57 final DefaultInfluxRecord other = (DefaultInfluxRecord) obj;
58 return Objects.equals(this.measurement, other.measurement) &&
59 Objects.equals(this.flowInfos, other.flowInfos);
60 }
61 return false;
62 }
63
64 @Override
65 public int hashCode() {
66 return Objects.hash(measurement, flowInfos);
67 }
68
69 public String toString() {
70 return toStringHelper(this)
71 .add("measurement", measurement)
72 .add("flowInfos", flowInfos)
73 .toString();
74 }
75}