Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 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; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 22 | import org.onosproject.net.pi.model.PiActionProfileId; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 27 | * Instance of a member of an action profile in a protocol-independent pipeline. |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 28 | */ |
| 29 | @Beta |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 30 | public final class PiActionProfileMember implements PiEntity { |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [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 PiActionProfileMemberId memberId; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 34 | private final PiAction action; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 35 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 36 | private PiActionProfileMember(PiActionProfileId actionProfileId, |
| 37 | PiActionProfileMemberId memberId, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 38 | PiAction action) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 39 | this.actionProfileId = actionProfileId; |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 40 | this.memberId = memberId; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 41 | this.action = action; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the identifier of this member. |
| 46 | * |
| 47 | * @return member identifier |
| 48 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 49 | public PiActionProfileMemberId id() { |
| 50 | return memberId; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 54 | * 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 Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 63 | * Returns the action associated to this member. |
| 64 | * |
| 65 | * @return action |
| 66 | */ |
| 67 | public PiAction action() { |
| 68 | return action; |
| 69 | } |
| 70 | |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 71 | @Override |
Carmelo Cascone | 5bc7e10 | 2018-02-18 18:27:55 -0800 | [diff] [blame] | 72 | public PiEntityType piEntityType() { |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 73 | return PiEntityType.ACTION_PROFILE_MEMBER; |
Carmelo Cascone | 5bc7e10 | 2018-02-18 18:27:55 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 77 | public boolean equals(Object o) { |
| 78 | if (this == o) { |
| 79 | return true; |
| 80 | } |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 81 | if (!(o instanceof PiActionProfileMember)) { |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 82 | return false; |
| 83 | } |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 84 | PiActionProfileMember that = (PiActionProfileMember) o; |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 85 | return Objects.equal(actionProfileId, that.actionProfileId) && |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 86 | Objects.equal(memberId, that.memberId) && |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 87 | Objects.equal(action, that.action); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public int hashCode() { |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 92 | return Objects.hashCode(actionProfileId, memberId, action); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return MoreObjects.toStringHelper(this) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 98 | .add("actionProfile", actionProfileId) |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 99 | .add("id", memberId) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 100 | .add("action", action) |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 101 | .toString(); |
| 102 | } |
| 103 | |
| 104 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 105 | * Returns a new builder of action profile members. |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 106 | * |
| 107 | * @return member builder |
| 108 | */ |
| 109 | public static Builder builder() { |
| 110 | return new Builder(); |
| 111 | } |
| 112 | |
| 113 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 114 | * Builder of action profile members. |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 115 | */ |
| 116 | public static final class Builder { |
| 117 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 118 | private PiActionProfileId actionProfileId; |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 119 | private PiActionProfileMemberId memberId; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 120 | private PiAction action; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 121 | |
| 122 | private Builder() { |
| 123 | // Hides constructor. |
| 124 | } |
| 125 | |
| 126 | /** |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 127 | * 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 Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 138 | * Sets the identifier of this member. |
| 139 | * |
| 140 | * @param id member identifier |
| 141 | * @return this |
| 142 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 143 | public Builder withId(PiActionProfileMemberId id) { |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 144 | this.memberId = id; |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 145 | 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 Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 160 | * Creates a new action profile member. |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 161 | * |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 162 | * @return action profile member |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 163 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 164 | public PiActionProfileMember build() { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 165 | checkNotNull(actionProfileId); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 166 | checkNotNull(memberId); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 167 | checkNotNull(action); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 168 | return new PiActionProfileMember(actionProfileId, memberId, action); |
Carmelo Cascone | b2e3dba | 2017-07-27 12:07:09 -0400 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | } |