alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 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.net.meter; |
| 17 | |
| 18 | import com.google.common.base.Objects; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
alshabib | 5196e86 | 2015-09-27 10:59:50 +0200 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 23 | /** |
| 24 | * A meter key represents a meter uniquely. |
| 25 | */ |
| 26 | public final class MeterKey { |
| 27 | |
| 28 | private final DeviceId deviceId; |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 29 | private final MeterCellId id; |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 30 | |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 31 | private MeterKey(DeviceId deviceId, MeterCellId id) { |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 32 | this.deviceId = deviceId; |
| 33 | this.id = id; |
| 34 | } |
| 35 | |
| 36 | public DeviceId deviceId() { |
| 37 | return deviceId; |
| 38 | } |
| 39 | |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 40 | /** |
| 41 | * @return a MeterId iff the id is a MeterId |
| 42 | * otherwise, return null |
| 43 | * @deprecated in onos-2.5 replaced by {@link #key(DeviceId,MeterCellId)} |
| 44 | * extends MeterKey to support both MeterId and PiMeterCellId |
| 45 | */ |
| 46 | @Deprecated |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 47 | public MeterId meterId() { |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 48 | if (id instanceof MeterId) { |
| 49 | return (MeterId) id; |
| 50 | } else { |
| 51 | return null; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public MeterCellId meterCellId() { |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 56 | return id; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object o) { |
| 61 | if (this == o) { |
| 62 | return true; |
| 63 | } |
| 64 | if (o == null || getClass() != o.getClass()) { |
| 65 | return false; |
| 66 | } |
| 67 | MeterKey meterKey = (MeterKey) o; |
| 68 | return Objects.equal(deviceId, meterKey.deviceId) && |
| 69 | Objects.equal(id, meterKey.id); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | return Objects.hashCode(deviceId, id); |
| 75 | } |
| 76 | |
alshabib | 5196e86 | 2015-09-27 10:59:50 +0200 | [diff] [blame] | 77 | @Override |
| 78 | public String toString() { |
| 79 | return toStringHelper(this) |
| 80 | .add("deviceId", deviceId) |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 81 | .add("meterCellId", id).toString(); |
alshabib | 5196e86 | 2015-09-27 10:59:50 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 84 | /** |
| 85 | * @param deviceId a DeviceId |
| 86 | * @param id a MeterId |
| 87 | * @return a MeterKey contains DeviceId and MeterId |
| 88 | * @deprecated in onos-2.5 replaced by {@link #key(DeviceId,MeterCellId)} |
| 89 | * extends MeterKey to support both MeterId and PiMeterCellId |
| 90 | */ |
| 91 | @Deprecated |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 92 | public static MeterKey key(DeviceId deviceId, MeterId id) { |
| 93 | return new MeterKey(deviceId, id); |
| 94 | } |
Wailok Shum | be900bd | 2021-08-05 00:55:47 +0800 | [diff] [blame] | 95 | |
| 96 | public static MeterKey key(DeviceId deviceId, MeterCellId id) { |
| 97 | return new MeterKey(deviceId, id); |
| 98 | } |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 99 | } |