Open Kilda Java Documentation
PortInfoData.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.messaging.info.event;
17 
18 import static com.google.common.base.MoreObjects.toStringHelper;
19 
22 
23 import com.fasterxml.jackson.annotation.JsonCreator;
24 import com.fasterxml.jackson.annotation.JsonInclude;
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
27 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
28 
29 import java.util.Objects;
30 
34 @JsonSerialize
35 @JsonInclude(JsonInclude.Include.NON_NULL)
36 @JsonPropertyOrder({
37  "switch_id",
38  "port_no",
39  "max_capacity",
40  "state"})
41 public class PortInfoData extends InfoData {
45  private static final long serialVersionUID = 1L;
46 
50  @JsonProperty("switch_id")
51  private SwitchId switchId;
52 
56  @JsonProperty("port_no")
57  private int portNo;
61  @JsonProperty("max_capacity")
62  private Integer maxCapacity;
63 
67  @JsonProperty("state")
68  private PortChangeType state;
69 
73  public PortInfoData() {
74  }
75 
82  this.switchId = path.getSwitchId();
83  this.portNo = path.getPortNo();
84  this.state = PortChangeType.OTHER_UPDATE;
85  }
86 
94  public PortInfoData(final SwitchId switchId, final int portNo, final PortChangeType state) {
95  this.switchId = switchId;
96  this.portNo = portNo;
97  this.state = state;
98  }
99 
108  @JsonCreator
109  public PortInfoData(@JsonProperty("switch_id") final SwitchId switchId,
110  @JsonProperty("port_no") final int portNo,
111  @JsonProperty("max_capacity") final Integer maxCapacity,
112  @JsonProperty("state") final PortChangeType state) {
113  this.switchId = switchId;
114  this.portNo = portNo;
115  this.maxCapacity = maxCapacity;
116  this.state = state;
117  }
118 
125  return switchId;
126  }
127 
133  public void setSwitchId(final SwitchId switchId) {
134  this.switchId = switchId;
135  }
136 
142  public int getPortNo() {
143  return portNo;
144  }
145 
151  public void setPortNo(final int portNo) {
152  this.portNo = portNo;
153  }
154 
160  public Integer getMaxCapacity() {
161  return maxCapacity;
162  }
163 
169  public void setMaxCapacity(final int maxCapacity) {
170  this.maxCapacity = maxCapacity;
171  }
172 
179  return state;
180  }
181 
187  public void setState(final PortChangeType state) {
188  this.state = state;
189  }
190 
194  @Override
195  public String toString() {
196  return toStringHelper(this)
197  .add("switch_id", switchId)
198  .add("port_no", portNo)
199  .add("max_capacity", maxCapacity)
200  .add("state", state)
201  .toString();
202  }
203 
207  @Override
208  public int hashCode() {
209  return Objects.hash(switchId, portNo, maxCapacity, state);
210  }
211 
215  @Override
216  public boolean equals(Object object) {
217  if (this == object) {
218  return true;
219  }
220  if (object == null || getClass() != object.getClass()) {
221  return false;
222  }
223 
224  PortInfoData that = (PortInfoData) object;
225  return Objects.equals(getSwitchId(), that.getSwitchId())
226  && Objects.equals(getPortNo(), that.getPortNo())
227  && Objects.equals(getMaxCapacity(), that.getMaxCapacity())
228  && Objects.equals(getState(), that.getState());
229  }
230 }
void setState(final PortChangeType state)
PortInfoData(@JsonProperty("switch_id") final SwitchId switchId, @JsonProperty("port_no") final int portNo, @JsonProperty("max_capacity") final Integer maxCapacity, @JsonProperty("state") final PortChangeType state)
PortInfoData(final SwitchId switchId, final int portNo, final PortChangeType state)