blob: b5df9d06993dde0221164f02dda33b526a4d1c4c [file] [log] [blame]
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -04003 *
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.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
Carmelo Casconee44592f2018-09-12 02:24:47 -070022import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040023
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
Carmelo Casconecb4327a2018-09-11 15:17:23 -070027 * Instance of a member of an action profile in a protocol-independent pipeline.
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040028 */
29@Beta
Carmelo Casconecb4327a2018-09-11 15:17:23 -070030public final class PiActionProfileMember implements PiEntity {
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040031
Carmelo Casconee44592f2018-09-12 02:24:47 -070032 private final PiActionProfileId actionProfileId;
Carmelo Casconecb4327a2018-09-11 15:17:23 -070033 private final PiActionProfileMemberId memberId;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040034 private final PiAction action;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040035
Carmelo Casconecb4327a2018-09-11 15:17:23 -070036 private PiActionProfileMember(PiActionProfileId actionProfileId,
37 PiActionProfileMemberId memberId,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080038 PiAction action) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070039 this.actionProfileId = actionProfileId;
Carmelo Casconecb4327a2018-09-11 15:17:23 -070040 this.memberId = memberId;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040041 this.action = action;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040042 }
43
44 /**
45 * Returns the identifier of this member.
46 *
47 * @return member identifier
48 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -070049 public PiActionProfileMemberId id() {
50 return memberId;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040051 }
52
53 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -070054 * Returns the identifier of the action profile.
55 *
56 * @return action profile identifier
57 */
58 public PiActionProfileId actionProfile() {
59 return actionProfileId;
60 }
61
62 /**
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040063 * Returns the action associated to this member.
64 *
65 * @return action
66 */
67 public PiAction action() {
68 return action;
69 }
70
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040071 @Override
Carmelo Cascone5bc7e102018-02-18 18:27:55 -080072 public PiEntityType piEntityType() {
Carmelo Casconecb4327a2018-09-11 15:17:23 -070073 return PiEntityType.ACTION_PROFILE_MEMBER;
Carmelo Cascone5bc7e102018-02-18 18:27:55 -080074 }
75
76 @Override
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040077 public boolean equals(Object o) {
78 if (this == o) {
79 return true;
80 }
Carmelo Casconecb4327a2018-09-11 15:17:23 -070081 if (!(o instanceof PiActionProfileMember)) {
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040082 return false;
83 }
Carmelo Casconecb4327a2018-09-11 15:17:23 -070084 PiActionProfileMember that = (PiActionProfileMember) o;
Carmelo Cascone99c59db2019-01-17 15:39:35 -080085 return Objects.equal(actionProfileId, that.actionProfileId) &&
Carmelo Casconecb4327a2018-09-11 15:17:23 -070086 Objects.equal(memberId, that.memberId) &&
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040087 Objects.equal(action, that.action);
88 }
89
90 @Override
91 public int hashCode() {
Carmelo Cascone99c59db2019-01-17 15:39:35 -080092 return Objects.hashCode(actionProfileId, memberId, action);
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -040093 }
94
95 @Override
96 public String toString() {
97 return MoreObjects.toStringHelper(this)
Carmelo Casconee44592f2018-09-12 02:24:47 -070098 .add("actionProfile", actionProfileId)
Carmelo Casconecb4327a2018-09-11 15:17:23 -070099 .add("id", memberId)
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400100 .add("action", action)
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400101 .toString();
102 }
103
104 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700105 * Returns a new builder of action profile members.
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400106 *
107 * @return member builder
108 */
109 public static Builder builder() {
110 return new Builder();
111 }
112
113 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700114 * Builder of action profile members.
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400115 */
116 public static final class Builder {
117
Carmelo Casconee44592f2018-09-12 02:24:47 -0700118 private PiActionProfileId actionProfileId;
Carmelo Cascone99c59db2019-01-17 15:39:35 -0800119 private PiActionProfileMemberId memberId;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400120 private PiAction action;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400121
122 private Builder() {
123 // Hides constructor.
124 }
125
126 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -0700127 * Sets the action profile identifier of this member.
128 *
129 * @param actionProfileId action profile identifier
130 * @return this
131 */
132 public Builder forActionProfile(PiActionProfileId actionProfileId) {
133 this.actionProfileId = actionProfileId;
134 return this;
135 }
136
137 /**
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400138 * Sets the identifier of this member.
139 *
140 * @param id member identifier
141 * @return this
142 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700143 public Builder withId(PiActionProfileMemberId id) {
Carmelo Cascone99c59db2019-01-17 15:39:35 -0800144 this.memberId = id;
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400145 return this;
146 }
147
148 /**
149 * Sets the action of this member.
150 *
151 * @param action action
152 * @return this
153 */
154 public Builder withAction(PiAction action) {
155 this.action = action;
156 return this;
157 }
158
159 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700160 * Creates a new action profile member.
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400161 *
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700162 * @return action profile member
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400163 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -0700164 public PiActionProfileMember build() {
Carmelo Casconee44592f2018-09-12 02:24:47 -0700165 checkNotNull(actionProfileId);
Carmelo Cascone99c59db2019-01-17 15:39:35 -0800166 checkNotNull(memberId);
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400167 checkNotNull(action);
Carmelo Cascone99c59db2019-01-17 15:39:35 -0800168 return new PiActionProfileMember(actionProfileId, memberId, action);
Carmelo Casconeb2e3dba2017-07-27 12:07:09 -0400169 }
170 }
171}