Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [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; |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 23 | import org.onosproject.net.pi.model.PiActionProfileId; |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Global identifier of a PI action group applied to a device, uniquely defined |
| 27 | * by a device ID, action profile ID and group ID. |
| 28 | */ |
| 29 | @Beta |
| 30 | public final class PiActionGroupHandle extends PiHandle<PiActionGroup> { |
| 31 | |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 32 | private final PiActionProfileId actionProfileId; |
| 33 | private final PiActionGroupId groupId; |
| 34 | |
Carmelo Cascone | e75b794 | 2017-11-21 17:14:49 -0800 | [diff] [blame] | 35 | private PiActionGroupHandle(DeviceId deviceId, PiActionGroup group) { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 36 | super(deviceId); |
| 37 | actionProfileId = group.actionProfileId(); |
| 38 | groupId = group.id(); |
Carmelo Cascone | e75b794 | 2017-11-21 17:14:49 -0800 | [diff] [blame] | 39 | } |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 40 | |
Carmelo Cascone | e75b794 | 2017-11-21 17:14:49 -0800 | [diff] [blame] | 41 | /** |
| 42 | * Creates a new handle for the given device ID and PI action group. |
| 43 | * |
| 44 | * @param deviceId device ID |
| 45 | * @param group PI action group |
| 46 | * @return PI action group handle |
| 47 | */ |
| 48 | public static PiActionGroupHandle of(DeviceId deviceId, |
| 49 | PiActionGroup group) { |
| 50 | return new PiActionGroupHandle(deviceId, group); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 54 | public PiEntityType entityType() { |
| 55 | return PiEntityType.GROUP; |
| 56 | } |
| 57 | |
| 58 | @Override |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 59 | public int hashCode() { |
| 60 | return Objects.hashCode(deviceId(), |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 61 | actionProfileId, |
| 62 | groupId); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object o) { |
| 67 | if (this == o) { |
| 68 | return true; |
| 69 | } |
| 70 | if (o == null || getClass() != o.getClass()) { |
| 71 | return false; |
| 72 | } |
| 73 | PiActionGroupHandle that = (PiActionGroupHandle) o; |
| 74 | return Objects.equal(deviceId(), that.deviceId()) && |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 75 | Objects.equal(actionProfileId, |
| 76 | that.actionProfileId) && |
| 77 | Objects.equal(groupId, that.groupId); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(this) |
| 83 | .add("deviceId", deviceId()) |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 84 | .add("actionProfileId", actionProfileId) |
| 85 | .add("groupId", groupId) |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 86 | .toString(); |
| 87 | } |
| 88 | } |