Open Kilda Java Documentation
Rule.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.model.rule;
17 
19 
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import com.fasterxml.jackson.annotation.JsonProperty;
22 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
23 import com.google.common.base.MoreObjects;
24 
25 import java.io.Serializable;
26 import java.util.Objects;
27 
31 @JsonSerialize
32 @JsonInclude(JsonInclude.Include.NON_NULL)
33 public class Rule extends BaseMessage {
37  private static final long serialVersionUID = 1L;
38 
42  @JsonProperty(RuleConstants.FLOW_ID)
43  protected String flowId;
44 
48  @JsonProperty(RuleConstants.COOKIE)
49  protected int cookie;
50 
54  @JsonProperty(RuleConstants.SWITCH_ID)
55  protected String switchId;
56 
60  public Rule() {
61  super();
62  }
63 
71  public Rule(@JsonProperty(RuleConstants.FLOW_ID) String flowId,
72  @JsonProperty(RuleConstants.COOKIE) int cookie,
73  @JsonProperty(RuleConstants.SWITCH_ID) String switchId) {
74  super();
75  this.switchId = switchId;
76  this.cookie = cookie;
77  this.flowId = flowId;
78  }
79 
85  public String getFlowId() {
86  return flowId;
87  }
88 
94  public void setFlowId(String flowId) {
95  this.flowId = flowId;
96  }
97 
103  public String getSwitchId() {
104  return switchId;
105  }
106 
112  public void setSwitchId(String switchId) {
113  this.switchId = switchId;
114  }
115 
121  public int getCookie() {
122  return cookie;
123  }
124 
130  public void setCookie(int cookie) {
131  this.cookie = cookie;
132  }
133 
137  @Override
138  public boolean equals(Object object) {
139  if (this == object) {
140  return true;
141  }
142 
143  if (object == null || getClass() != object.getClass()) {
144  return false;
145  }
146 
147  Rule that = (Rule) object;
148  return Objects.equals(getFlowId(), that.getFlowId())
149  && Objects.equals(getSwitchId(), that.getSwitchId())
150  && getCookie() == that.getCookie();
151  }
152 
156  @Override
157  public int hashCode() {
158  return Objects.hash(getFlowId(), getCookie(), getSwitchId());
159  }
160 
164  @Override
165  public String toString() {
166  return MoreObjects.toStringHelper(this)
167  .add(RuleConstants.FLOW_ID, flowId)
168  .add(RuleConstants.COOKIE, cookie)
169  .add(RuleConstants.SWITCH_ID, switchId)
170  .toString();
171  }
172 }
Rule(@JsonProperty(RuleConstants.FLOW_ID) String flowId, @JsonProperty(RuleConstants.COOKIE) int cookie, @JsonProperty(RuleConstants.SWITCH_ID) String switchId)
Definition: Rule.java:71
void setSwitchId(String switchId)
Definition: Rule.java:112
void setFlowId(String flowId)
Definition: Rule.java:94
boolean equals(Object object)
Definition: Rule.java:138