blob: d7ec2e1e18a0ad6c4e93dd9d7065523ed7573323 [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
Jian Liae3fcff2018-07-30 11:55:44 +090018import com.google.common.base.Strings;
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090019import org.onosproject.openstacktelemetry.api.InfluxRecord;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_MEASUREMENT;
25
Jian Liae3fcff2018-07-30 11:55:44 +090026/**
27 * A default implementation of influx record.
28 *
29 * @param <K> key of influx record
30 * @param <V> value of influx record
31 */
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090032public final class DefaultInfluxRecord<K, V> implements InfluxRecord<K, V> {
33 public static final String MEASUREMENT_NAME = DEFAULT_INFLUXDB_MEASUREMENT;
34 private final K measurement;
35 private final V flowInfos;
36
37 protected DefaultInfluxRecord(K measurement, V flowInfos) {
Jian Liae3fcff2018-07-30 11:55:44 +090038 if (Strings.isNullOrEmpty((String) measurement)) {
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090039 this.measurement = (K) MEASUREMENT_NAME;
40 } else {
41 this.measurement = measurement;
42 }
43 this.flowInfos = flowInfos;
44 }
45
46 @Override
47 public K measurement() {
48 return measurement;
49 }
50
51 @Override
52 public V flowInfos() {
53 return flowInfos;
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61
62 if (obj instanceof DefaultInfluxRecord) {
63 final DefaultInfluxRecord other = (DefaultInfluxRecord) obj;
64 return Objects.equals(this.measurement, other.measurement) &&
65 Objects.equals(this.flowInfos, other.flowInfos);
66 }
67 return false;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hash(measurement, flowInfos);
73 }
74
Jian Liae3fcff2018-07-30 11:55:44 +090075 @Override
Boyoung Jeong4d1c9d12018-07-20 17:09:20 +090076 public String toString() {
77 return toStringHelper(this)
78 .add("measurement", measurement)
79 .add("flowInfos", flowInfos)
80 .toString();
81 }
82}