blob: d3ff0f455da1f9cfbe47336b1a56635fcfb101bd [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.
tom95329eb2014-10-06 08:40:06 -07009
Yuta HIGUCHI06dc6b92014-09-25 16:06:16 -070010/**
11 * Immutable representation of a link identity.
12 */
13public class LinkKey {
14
15 private final ConnectPoint src;
16 private final ConnectPoint dst;
17
18 /**
19 * Returns source connection point.
20 *
21 * @return source connection point
22 */
23 public ConnectPoint src() {
24 return src;
25 }
26
27 /**
28 * Returns destination connection point.
29 *
30 * @return destination connection point
31 */
32 public ConnectPoint dst() {
33 return dst;
34 }
35
36 /**
37 * Creates a link identifier with source and destination connection point.
38 *
39 * @param src source connection point
40 * @param dst destination connection point
41 */
42 public LinkKey(ConnectPoint src, ConnectPoint dst) {
43 this.src = src;
44 this.dst = dst;
45 }
46
tom95329eb2014-10-06 08:40:06 -070047 /**
48 * Creates a link identifier for the specified link.
49 *
50 * @param link link descriptor
51 */
52 public LinkKey(Link link) {
53 this(link.src(), link.dst());
54 }
55
Yuta HIGUCHI06dc6b92014-09-25 16:06:16 -070056 @Override
57 public int hashCode() {
58 return Objects.hash(src(), dst);
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (this == obj) {
64 return true;
65 }
66 if (obj instanceof LinkKey) {
67 final LinkKey other = (LinkKey) obj;
68 return Objects.equals(this.src(), other.src()) &&
69 Objects.equals(this.dst, other.dst);
70 }
71 return false;
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("src", src())
78 .add("dst", dst)
79 .toString();
80 }
81}