blob: dee4e883b003c4b97af0892846f4d67b4de84c95 [file] [log] [blame]
Yuta HIGUCHI06dc6b92014-09-25 16:06:16 -07001package org.onlab.onos.net;
2
3import java.util.Objects;
4
5import com.google.common.base.MoreObjects;
6
7// TODO Consider renaming.
8// it's an identifier for a Link, but it's not ElementId, so not using LinkId.
9/**
10 * Immutable representation of a link identity.
11 */
12public class LinkKey {
13
14 private final ConnectPoint src;
15 private final ConnectPoint dst;
16
17 /**
18 * Returns source connection point.
19 *
20 * @return source connection point
21 */
22 public ConnectPoint src() {
23 return src;
24 }
25
26 /**
27 * Returns destination connection point.
28 *
29 * @return destination connection point
30 */
31 public ConnectPoint dst() {
32 return dst;
33 }
34
35 /**
36 * Creates a link identifier with source and destination connection point.
37 *
38 * @param src source connection point
39 * @param dst destination connection point
40 */
41 public LinkKey(ConnectPoint src, ConnectPoint dst) {
42 this.src = src;
43 this.dst = dst;
44 }
45
46 @Override
47 public int hashCode() {
48 return Objects.hash(src(), dst);
49 }
50
51 @Override
52 public boolean equals(Object obj) {
53 if (this == obj) {
54 return true;
55 }
56 if (obj instanceof LinkKey) {
57 final LinkKey other = (LinkKey) obj;
58 return Objects.equals(this.src(), other.src()) &&
59 Objects.equals(this.dst, other.dst);
60 }
61 return false;
62 }
63
64 @Override
65 public String toString() {
66 return MoreObjects.toStringHelper(getClass())
67 .add("src", src())
68 .add("dst", dst)
69 .toString();
70 }
71}