Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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.base.MoreObjects; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Global identifier of a PI action profile group member, uniquely defined by a |
| 28 | * device ID, action profile ID, and member ID. |
| 29 | */ |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 30 | public final class PiActionProfileMemberHandle extends PiHandle<PiActionProfileMember> { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 31 | |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 32 | private final PiActionProfileMemberId memberId; |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 33 | private final PiActionProfileId actionProfileId; |
| 34 | |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 35 | private PiActionProfileMemberHandle(DeviceId deviceId, |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 36 | PiActionProfileId actionProfileId, |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 37 | PiActionProfileMemberId memberId) { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 38 | super(deviceId); |
| 39 | this.actionProfileId = actionProfileId; |
| 40 | this.memberId = memberId; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates a new handle for the given device ID, action profile ID, and |
| 45 | * member ID. |
| 46 | * |
| 47 | * @param deviceId device ID |
| 48 | * @param actionProfileId action profile ID |
| 49 | * @param memberId member ID |
| 50 | * @return action profile group member handle |
| 51 | */ |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 52 | public static PiActionProfileMemberHandle of( |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 53 | DeviceId deviceId, |
| 54 | PiActionProfileId actionProfileId, |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 55 | PiActionProfileMemberId memberId) { |
| 56 | return new PiActionProfileMemberHandle( |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 57 | deviceId, actionProfileId, memberId); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new handle for the given device ID, and action profile group |
| 62 | * member instance. |
| 63 | * |
| 64 | * @param deviceId device ID |
| 65 | * @param member member instance |
| 66 | * @return action profile group member handle |
| 67 | */ |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 68 | public static PiActionProfileMemberHandle of( |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 69 | DeviceId deviceId, |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 70 | PiActionProfileMember member) { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 71 | checkNotNull(member); |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 72 | return new PiActionProfileMemberHandle( |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 73 | deviceId, member.actionProfile(), member.id()); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the member ID of this handle. |
| 78 | * |
| 79 | * @return member ID |
| 80 | */ |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 81 | public PiActionProfileMemberId memberId() { |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 82 | return memberId; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the action profile ID of this handle. |
| 87 | * |
| 88 | * @return action profile ID |
| 89 | */ |
| 90 | public PiActionProfileId actionProfileId() { |
| 91 | return actionProfileId; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public PiEntityType entityType() { |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 96 | return PiEntityType.ACTION_PROFILE_MEMBER; |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hashCode(deviceId(), actionProfileId, memberId); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (this == obj) { |
| 107 | return true; |
| 108 | } |
| 109 | if (obj == null || getClass() != obj.getClass()) { |
| 110 | return false; |
| 111 | } |
Carmelo Cascone | f2b7bfe | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 112 | final PiActionProfileMemberHandle other = (PiActionProfileMemberHandle) obj; |
Carmelo Cascone | e3ba922 | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 113 | return Objects.equal(this.deviceId(), other.deviceId()) |
| 114 | && Objects.equal(this.actionProfileId, other.actionProfileId) |
| 115 | && Objects.equal(this.memberId, other.memberId); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public String toString() { |
| 120 | return MoreObjects.toStringHelper(this) |
| 121 | .add("deviceId", deviceId()) |
| 122 | .add("actionProfileId", actionProfileId) |
| 123 | .add("memberId", memberId) |
| 124 | .toString(); |
| 125 | } |
| 126 | } |