blob: 87716506073baf0114fe90b580010c5cccc85173 [file] [log] [blame]
Carmelo Casconee44592f2018-09-12 02:24:47 -07001/*
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
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.base.MoreObjects;
20import com.google.common.base.Objects;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.pi.model.PiActionProfileId;
23
24import 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 Casconecb4327a2018-09-11 15:17:23 -070030public final class PiActionProfileMemberHandle extends PiHandle<PiActionProfileMember> {
Carmelo Casconee44592f2018-09-12 02:24:47 -070031
Carmelo Casconecb4327a2018-09-11 15:17:23 -070032 private final PiActionProfileMemberId memberId;
Carmelo Casconee44592f2018-09-12 02:24:47 -070033 private final PiActionProfileId actionProfileId;
34
Carmelo Casconecb4327a2018-09-11 15:17:23 -070035 private PiActionProfileMemberHandle(DeviceId deviceId,
Carmelo Casconee44592f2018-09-12 02:24:47 -070036 PiActionProfileId actionProfileId,
Carmelo Casconecb4327a2018-09-11 15:17:23 -070037 PiActionProfileMemberId memberId) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070038 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 Casconecb4327a2018-09-11 15:17:23 -070052 public static PiActionProfileMemberHandle of(
Carmelo Casconee44592f2018-09-12 02:24:47 -070053 DeviceId deviceId,
54 PiActionProfileId actionProfileId,
Carmelo Casconecb4327a2018-09-11 15:17:23 -070055 PiActionProfileMemberId memberId) {
56 return new PiActionProfileMemberHandle(
Carmelo Casconee44592f2018-09-12 02:24:47 -070057 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 Casconecb4327a2018-09-11 15:17:23 -070068 public static PiActionProfileMemberHandle of(
Carmelo Casconee44592f2018-09-12 02:24:47 -070069 DeviceId deviceId,
Carmelo Casconecb4327a2018-09-11 15:17:23 -070070 PiActionProfileMember member) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070071 checkNotNull(member);
Carmelo Casconecb4327a2018-09-11 15:17:23 -070072 return new PiActionProfileMemberHandle(
Carmelo Casconee44592f2018-09-12 02:24:47 -070073 deviceId, member.actionProfile(), member.id());
74 }
75
76 /**
77 * Returns the member ID of this handle.
78 *
79 * @return member ID
80 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -070081 public PiActionProfileMemberId memberId() {
Carmelo Casconee44592f2018-09-12 02:24:47 -070082 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 Casconecb4327a2018-09-11 15:17:23 -070096 return PiEntityType.ACTION_PROFILE_MEMBER;
Carmelo Casconee44592f2018-09-12 02:24:47 -070097 }
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 Casconecb4327a2018-09-11 15:17:23 -0700112 final PiActionProfileMemberHandle other = (PiActionProfileMemberHandle) obj;
Carmelo Casconee44592f2018-09-12 02:24:47 -0700113 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}