Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.cpman; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * A container class that is used to wrap the control metric response. |
| 26 | */ |
| 27 | public class ControlLoadSnapshot { |
| 28 | |
| 29 | private final long latest; |
| 30 | private final long average; |
| 31 | private final long time; |
| 32 | |
| 33 | /** |
| 34 | * Instantiates a new control metric response with given latest, average, time. |
| 35 | * |
| 36 | * @param latest latest value of control metric |
| 37 | * @param average average value of control metric |
| 38 | * @param time last logging time fo control metric |
| 39 | */ |
| 40 | public ControlLoadSnapshot(long latest, long average, long time) { |
| 41 | this.latest = latest; |
| 42 | this.average = average; |
| 43 | this.time = time; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns latest value of control metric. |
| 48 | * |
| 49 | * @return latest value of control metric |
| 50 | */ |
| 51 | public long latest() { |
| 52 | return latest; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns last logging time of control metric. |
| 57 | * |
| 58 | * @return last logging time of control metric |
| 59 | */ |
| 60 | public long time() { |
| 61 | return time; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns average value of control metric. |
| 66 | * |
| 67 | * @return average value of control metric |
| 68 | */ |
| 69 | public long average() { |
| 70 | return average; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
| 75 | return Objects.hash(latest, average, time); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (this == obj) { |
| 81 | return true; |
| 82 | } |
| 83 | if (obj instanceof ControlLoadSnapshot) { |
| 84 | final ControlLoadSnapshot other = (ControlLoadSnapshot) obj; |
| 85 | return Objects.equals(this.latest, other.latest) && |
| 86 | Objects.equals(this.average, other.average) && |
| 87 | Objects.equals(this.time, other.time); |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | MoreObjects.ToStringHelper helper; |
| 95 | helper = toStringHelper(this) |
| 96 | .add("latest", latest) |
| 97 | .add("average", average) |
| 98 | .add("time", time); |
| 99 | return helper.toString(); |
| 100 | } |
| 101 | } |