Open Kilda Java Documentation
ImmutablePair.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;
17 
18 import com.fasterxml.jackson.annotation.JsonCreator;
19 import com.fasterxml.jackson.annotation.JsonInclude;
20 import com.fasterxml.jackson.annotation.JsonProperty;
21 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
22 import com.google.common.base.MoreObjects;
23 
24 import java.io.Serializable;
25 import java.util.Objects;
26 
27 @JsonSerialize
28 @JsonInclude(JsonInclude.Include.NON_NULL)
29 public class ImmutablePair<L, R> implements Serializable {
30  static final long serialVersionUID = 1L;
31 
32  @JsonProperty("forward")
33  public final L left;
34 
35  @JsonProperty("reverse")
36  public final R right;
37 
38  @Override
39  public String toString() {
40  return MoreObjects.toStringHelper(this)
41  .add("forward", left)
42  .add("reverse", right)
43  .toString();
44  }
45 
46  @Override
47  public boolean equals(Object object) {
48  if (this == object) {
49  return true;
50  }
51  if (object == null || getClass() != object.getClass()) {
52  return false;
53  }
54 
55  ImmutablePair flowPair = (ImmutablePair) object;
56  return Objects.equals(getLeft(), flowPair.getLeft()) &&
57  Objects.equals(getRight(), flowPair.getRight());
58  }
59 
60  @Override
61  public int hashCode() {
62  return Objects.hash(getLeft(), getRight());
63  }
64 
65  @JsonCreator
66  public ImmutablePair(@JsonProperty("forward") L left, @JsonProperty("reverse") R right) {
67  this.left = left;
68  this.right = right;
69  }
70 
71  public L getLeft() {
72  return left;
73  }
74 
75  public R getRight() {
76  return right;
77  }
78 }
ImmutablePair(@JsonProperty("forward") L left, @JsonProperty("reverse") R right)