blob: 9ef8a319c218b65e570a01de679ac8e2e15f902a [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 */
30public final class PiActionGroupMemberHandle extends PiHandle<PiActionGroupMember> {
31
32 private final PiActionGroupMemberId memberId;
33 private final PiActionProfileId actionProfileId;
34
35 private PiActionGroupMemberHandle(DeviceId deviceId,
36 PiActionProfileId actionProfileId,
37 PiActionGroupMemberId memberId) {
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 */
52 public static PiActionGroupMemberHandle of(
53 DeviceId deviceId,
54 PiActionProfileId actionProfileId,
55 PiActionGroupMemberId memberId) {
56 return new PiActionGroupMemberHandle(
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 */
68 public static PiActionGroupMemberHandle of(
69 DeviceId deviceId,
70 PiActionGroupMember member) {
71 checkNotNull(member);
72 return new PiActionGroupMemberHandle(
73 deviceId, member.actionProfile(), member.id());
74 }
75
76 /**
77 * Returns the member ID of this handle.
78 *
79 * @return member ID
80 */
81 public PiActionGroupMemberId memberId() {
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() {
96 return PiEntityType.GROUP_MEMBER;
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 }
112 final PiActionGroupMemberHandle other = (PiActionGroupMemberHandle) obj;
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}