Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | |
| 25 | /** |
| 26 | * Represents a band used within a meter. |
| 27 | */ |
| 28 | @Beta |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 29 | public final class PiMeterBand { |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 30 | private final long rate; |
| 31 | private final long burst; |
| 32 | |
| 33 | /** |
| 34 | * Creates a band with rate and burst. |
| 35 | * |
| 36 | * @param rate rate of this band |
| 37 | * @param burst burst of this band |
| 38 | */ |
| 39 | public PiMeterBand(long rate, long burst) { |
| 40 | this.rate = rate; |
| 41 | this.burst = burst; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the rate of this band. |
| 46 | * |
| 47 | * @return rate of this band |
| 48 | */ |
| 49 | public long rate() { |
| 50 | return rate; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns the burst of this band. |
| 55 | * |
| 56 | * @return burst of this band |
| 57 | */ |
| 58 | public long burst() { |
| 59 | return burst; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public int hashCode() { |
| 64 | return Objects.hash(rate, burst); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object obj) { |
| 69 | if (this == obj) { |
| 70 | return true; |
| 71 | } |
| 72 | if (obj instanceof PiMeterBand) { |
| 73 | PiMeterBand that = (PiMeterBand) obj; |
| 74 | return Objects.equals(rate, that.rate) && |
| 75 | Objects.equals(burst, that.burst); |
| 76 | |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | public String toString() { |
| 82 | return toStringHelper(this) |
| 83 | .add("rate", rate) |
| 84 | .add("burst", burst).toString(); |
| 85 | } |
| 86 | } |