Open Kilda Java Documentation
BaseInstallFlow.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.command.flow;
17 
18 import static com.google.common.base.MoreObjects.toStringHelper;
19 import static org.openkilda.messaging.Utils.FLOW_ID;
21 
23 
24 import com.fasterxml.jackson.annotation.JsonCreator;
25 import com.fasterxml.jackson.annotation.JsonInclude;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
28 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
29 
30 import java.util.Objects;
31 
36 @JsonSerialize
37 @JsonInclude(JsonInclude.Include.NON_NULL)
38 @JsonPropertyOrder({
39  TRANSACTION_ID,
40  FLOW_ID,
41  "cookie",
42  "switch_id",
43  "input_port",
44  "output_port"})
45 public class BaseInstallFlow extends BaseFlow {
49  private static final long serialVersionUID = 1L;
50 
54  @JsonProperty("input_port")
55  protected Integer inputPort;
56 
60  @JsonProperty("output_port")
61  protected Integer outputPort;
62 
74  @JsonCreator
75  public BaseInstallFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
76  @JsonProperty(FLOW_ID) final String id,
77  @JsonProperty("cookie") final Long cookie,
78  @JsonProperty("switch_id") final SwitchId switchId,
79  @JsonProperty("input_port") final Integer inPort,
80  @JsonProperty("output_port") final Integer outPort) {
81  super(transactionId, id, cookie, switchId);
82  setInputPort(inPort);
83  setOutputPort(outPort);
84  }
85 
91  public Integer getInputPort() {
92  return inputPort;
93  }
94 
100  public void setInputPort(final Integer inputPort) {
101  if (inputPort == null) {
102  throw new IllegalArgumentException("need to set input_port");
103  } else if (inputPort < 0L) {
104  throw new IllegalArgumentException("need to set positive value for input_port");
105  }
106  this.inputPort = inputPort;
107  }
108 
114  public Integer getOutputPort() {
115  return outputPort;
116  }
117 
123  public void setOutputPort(final Integer outputPort) {
124  if (outputPort == null) {
125  throw new IllegalArgumentException("need to set output_port");
126  } else if (outputPort < 0L) {
127  throw new IllegalArgumentException("need to set positive value for output_port");
128  }
129  this.outputPort = outputPort;
130  }
131 
135  @Override
136  public String toString() {
137  return toStringHelper(this)
138  .add(TRANSACTION_ID, transactionId)
139  .add(FLOW_ID, id)
140  .add("cookie", cookie)
141  .add("switch_id", switchId)
142  .add("input_port", inputPort)
143  .add("output_port", outputPort)
144  .toString();
145  }
146 
150  @Override
151  public boolean equals(Object object) {
152  if (this == object) {
153  return true;
154  }
155  if (object == null || getClass() != object.getClass()) {
156  return false;
157  }
158 
159  BaseInstallFlow that = (BaseInstallFlow) object;
160  return Objects.equals(getTransactionId(), that.getTransactionId())
161  && Objects.equals(getId(), that.getId())
162  && Objects.equals(getCookie(), that.getCookie())
163  && Objects.equals(getSwitchId(), that.getSwitchId())
164  && Objects.equals(getInputPort(), that.getInputPort())
165  && Objects.equals(getOutputPort(), that.getOutputPort());
166  }
167 
171  @Override
172  public int hashCode() {
173  return Objects.hash(transactionId, id, cookie, switchId, inputPort, outputPort);
174  }
175 }
static final String TRANSACTION_ID
Definition: Utils.java:39
static final String FLOW_ID
Definition: Utils.java:61