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 | e44592f | 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 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 26 | * Global identifier of a PI action profile group applied to a device, uniquely |
| 27 | * defined by a device ID, action profile ID and group ID. |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 28 | */ |
| 29 | @Beta |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 30 | public final class PiActionProfileGroupHandle extends PiHandle { |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 31 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 32 | private final PiActionProfileId actionProfileId; |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 33 | private final PiActionProfileGroupId groupId; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 34 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 35 | private PiActionProfileGroupHandle(DeviceId deviceId, PiActionProfileGroup group) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 36 | super(deviceId); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 37 | actionProfileId = group.actionProfile(); |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 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 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 42 | * Creates a new handle for the given device ID and PI action profile |
| 43 | * group. |
Carmelo Cascone | e75b794 | 2017-11-21 17:14:49 -0800 | [diff] [blame] | 44 | * |
| 45 | * @param deviceId device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 46 | * @param group PI action profile group |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 47 | * @return PI action profile group handle |
Carmelo Cascone | e75b794 | 2017-11-21 17:14:49 -0800 | [diff] [blame] | 48 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 49 | public static PiActionProfileGroupHandle of(DeviceId deviceId, |
| 50 | PiActionProfileGroup group) { |
| 51 | return new PiActionProfileGroupHandle(deviceId, group); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 54 | /** |
| 55 | * Returns the action profile ID of this handle. |
| 56 | * |
| 57 | * @return action profile ID |
| 58 | */ |
| 59 | public PiActionProfileId actionProfile() { |
| 60 | return actionProfileId; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the group ID of this handle. |
| 65 | * |
| 66 | * @return group ID |
| 67 | */ |
| 68 | public PiActionProfileGroupId groupId() { |
| 69 | return groupId; |
| 70 | } |
| 71 | |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 72 | @Override |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 73 | public PiEntityType entityType() { |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 74 | return PiEntityType.ACTION_PROFILE_GROUP; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 78 | public int hashCode() { |
| 79 | return Objects.hashCode(deviceId(), |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 80 | actionProfileId, |
| 81 | groupId); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object o) { |
| 86 | if (this == o) { |
| 87 | return true; |
| 88 | } |
| 89 | if (o == null || getClass() != o.getClass()) { |
| 90 | return false; |
| 91 | } |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 92 | PiActionProfileGroupHandle that = (PiActionProfileGroupHandle) o; |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 93 | return Objects.equal(deviceId(), that.deviceId()) && |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 94 | Objects.equal(actionProfileId, |
| 95 | that.actionProfileId) && |
| 96 | Objects.equal(groupId, that.groupId); |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return MoreObjects.toStringHelper(this) |
| 102 | .add("deviceId", deviceId()) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 103 | .add("actionProfile", actionProfileId) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 104 | .add("groupId", groupId) |
Carmelo Cascone | 326ad2d | 2017-11-28 18:09:13 -0800 | [diff] [blame] | 105 | .toString(); |
| 106 | } |
| 107 | } |