Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstacktelemetry.impl; |
| 17 | |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame] | 19 | import org.onosproject.openstacktelemetry.api.InfluxRecord; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_MEASUREMENT; |
| 25 | |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 26 | /** |
| 27 | * A default implementation of influx record. |
| 28 | * |
| 29 | * @param <K> key of influx record |
| 30 | * @param <V> value of influx record |
| 31 | */ |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame] | 32 | public 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 Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 38 | if (Strings.isNullOrEmpty((String) measurement)) { |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame] | 39 | 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 Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 75 | @Override |
Boyoung Jeong | 4d1c9d1 | 2018-07-20 17:09:20 +0900 | [diff] [blame] | 76 | public String toString() { |
| 77 | return toStringHelper(this) |
| 78 | .add("measurement", measurement) |
| 79 | .add("flowInfos", flowInfos) |
| 80 | .toString(); |
| 81 | } |
| 82 | } |