Jian Li | 0a5d4d2 | 2018-06-08 14:06:56 +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 | |
| 18 | import org.onosproject.openstacktelemetry.api.StatsInfo; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Implementation class of StatsInfo. |
| 26 | */ |
| 27 | public final class DefaultStatsInfo implements StatsInfo { |
| 28 | |
| 29 | private final long startupTime; |
| 30 | private final long fstPktArrTime; |
| 31 | private final int lstPktOffset; |
| 32 | private final long prevAccBytes; |
| 33 | private final int prevAccPkts; |
| 34 | private final long currAccBytes; |
| 35 | private final int currAccPkts; |
| 36 | private final short errorPkts; |
| 37 | private final short dropPkts; |
| 38 | |
| 39 | private DefaultStatsInfo(long startupTime, long fstPktArrTime, int lstPktOffset, |
| 40 | long prevAccBytes, int prevAccPkts, long currAccBytes, |
| 41 | int currAccPkts, short errorPkts, short dropPkts) { |
| 42 | this.startupTime = startupTime; |
| 43 | this.fstPktArrTime = fstPktArrTime; |
| 44 | this.lstPktOffset = lstPktOffset; |
| 45 | this.prevAccBytes = prevAccBytes; |
| 46 | this.prevAccPkts = prevAccPkts; |
| 47 | this.currAccBytes = currAccBytes; |
| 48 | this.currAccPkts = currAccPkts; |
| 49 | this.errorPkts = errorPkts; |
| 50 | this.dropPkts = dropPkts; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public long startupTime() { |
| 55 | return startupTime; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public long fstPktArrTime() { |
| 60 | return fstPktArrTime; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int lstPktOffset() { |
| 65 | return lstPktOffset; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public long prevAccBytes() { |
| 70 | return prevAccBytes; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int prevAccPkts() { |
| 75 | return prevAccPkts; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public long currAccBytes() { |
| 80 | return currAccBytes; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public int currAccPkts() { |
| 85 | return currAccPkts; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public short errorPkts() { |
| 90 | return errorPkts; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public short dropPkts() { |
| 95 | return dropPkts; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean equals(Object obj) { |
| 100 | if (this == obj) { |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | if (obj instanceof DefaultStatsInfo) { |
| 105 | final DefaultStatsInfo other = (DefaultStatsInfo) obj; |
| 106 | return Objects.equals(this.startupTime, other.startupTime) && |
| 107 | Objects.equals(this.fstPktArrTime, other.fstPktArrTime) && |
| 108 | Objects.equals(this.lstPktOffset, other.lstPktOffset) && |
| 109 | Objects.equals(this.prevAccBytes, other.prevAccBytes) && |
| 110 | Objects.equals(this.prevAccPkts, other.prevAccPkts) && |
| 111 | Objects.equals(this.currAccBytes, other.currAccBytes) && |
| 112 | Objects.equals(this.currAccPkts, other.currAccPkts) && |
| 113 | Objects.equals(this.errorPkts, other.errorPkts) && |
| 114 | Objects.equals(this.dropPkts, other.dropPkts); |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public int hashCode() { |
| 121 | return Objects.hash(startupTime, fstPktArrTime, lstPktOffset, |
| 122 | prevAccBytes, prevAccPkts, currAccBytes, currAccPkts, |
| 123 | errorPkts, dropPkts); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return toStringHelper(this) |
| 129 | .add("startupTime", startupTime) |
| 130 | .add("fstPktArrTime", fstPktArrTime) |
| 131 | .add("lstPktOffset", lstPktOffset) |
| 132 | .add("prevAccBytes", prevAccBytes) |
| 133 | .add("prevAccPkts", prevAccPkts) |
| 134 | .add("currAccBytes", currAccBytes) |
| 135 | .add("currAccPkts", currAccPkts) |
| 136 | .add("errorPkts", errorPkts) |
| 137 | .add("dropPkts", dropPkts) |
| 138 | .toString(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Builder class of DefaultStatsInfo. |
| 143 | */ |
| 144 | public static final class DefaultBuilder implements StatsInfo.Builder { |
| 145 | private long startupTime; |
| 146 | private long fstPktArrTime; |
| 147 | private int lstPktOffset; |
| 148 | private long prevAccBytes; |
| 149 | private int prevAccPkts; |
| 150 | private long currAccBytes; |
| 151 | private int currAccPkts; |
| 152 | private short errorPkts; |
| 153 | private short dropPkts; |
| 154 | |
| 155 | @Override |
| 156 | public Builder withStartupTime(long startupTime) { |
| 157 | this.startupTime = startupTime; |
| 158 | return this; |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public Builder withFstPktArrTime(long fstPktArrTime) { |
| 163 | this.fstPktArrTime = fstPktArrTime; |
| 164 | return this; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public Builder withLstPktOffset(int lstPktOffset) { |
| 169 | this.lstPktOffset = lstPktOffset; |
| 170 | return this; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public Builder withPrevAccBytes(long prevAccBytes) { |
| 175 | this.prevAccBytes = prevAccBytes; |
| 176 | return this; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public Builder withPrevAccPkts(int prevAccPkts) { |
| 181 | this.prevAccPkts = prevAccPkts; |
| 182 | return this; |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public Builder withCurrAccBytes(long currAccBytes) { |
| 187 | this.currAccBytes = currAccBytes; |
| 188 | return this; |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public Builder withCurrAccPkts(int currAccPkts) { |
| 193 | this.currAccPkts = currAccPkts; |
| 194 | return this; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public Builder withErrorPkts(short errorPkts) { |
| 199 | this.errorPkts = errorPkts; |
| 200 | return this; |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public Builder withDropPkts(short dropPkts) { |
| 205 | this.dropPkts = dropPkts; |
| 206 | return this; |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public StatsInfo build() { |
| 211 | |
| 212 | return new DefaultStatsInfo(startupTime, fstPktArrTime, lstPktOffset, |
| 213 | prevAccBytes, prevAccPkts, currAccBytes, currAccPkts, |
| 214 | errorPkts, dropPkts); |
| 215 | } |
| 216 | } |
| 217 | } |