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 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 26 | /** |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 27 | * Global identifier of a PI meter cell configuration applied to a device, |
| 28 | * uniquely defined by a device ID and meter cell ID. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 29 | */ |
| 30 | @Beta |
| 31 | public final class PiMeterHandle extends PiHandle<PiMeterCellConfig> { |
| 32 | |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 33 | private final PiMeterCellId cellId; |
| 34 | |
| 35 | private PiMeterHandle(DeviceId deviceId, PiMeterCellId meterCellId) { |
| 36 | super(deviceId); |
| 37 | this.cellId = meterCellId; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 41 | * Creates a new handle for the given device ID and PI meter cell ID. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 42 | * |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 43 | * @param deviceId device ID |
| 44 | * @param meterCellId meter cell ID |
| 45 | * @return PI meter handle |
| 46 | */ |
| 47 | public static PiMeterHandle of(DeviceId deviceId, |
| 48 | PiMeterCellId meterCellId) { |
| 49 | return new PiMeterHandle(deviceId, meterCellId); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates a new handle for the given device ID and PI meter cell |
| 54 | * configuration. |
| 55 | * |
| 56 | * @param deviceId device ID |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 57 | * @param meterCellConfig meter config |
| 58 | * @return PI meter handle |
| 59 | */ |
| 60 | public static PiMeterHandle of(DeviceId deviceId, |
| 61 | PiMeterCellConfig meterCellConfig) { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 62 | checkNotNull(meterCellConfig); |
| 63 | return new PiMeterHandle(deviceId, meterCellConfig.cellId()); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public PiEntityType entityType() { |
| 68 | return PiEntityType.METER_CELL_CONFIG; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public int hashCode() { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 73 | return Objects.hashCode(deviceId(), cellId); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public boolean equals(Object o) { |
| 78 | if (this == o) { |
| 79 | return true; |
| 80 | } |
| 81 | if (o == null || getClass() != o.getClass()) { |
| 82 | return false; |
| 83 | } |
| 84 | PiMeterHandle that = (PiMeterHandle) o; |
| 85 | return Objects.equal(deviceId(), that.deviceId()) && |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 86 | Objects.equal(cellId, that.cellId); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return MoreObjects.toStringHelper(this) |
| 92 | .add("deviceId", deviceId()) |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 93 | .add("meterCellId", cellId) |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 94 | .toString(); |
| 95 | } |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 96 | } |