modified LinkKey creation to follow other id objects
Change-Id: Ie70444f9069486d0251482464595f5835cf12539
diff --git a/core/api/src/main/java/org/onlab/onos/net/LinkKey.java b/core/api/src/main/java/org/onlab/onos/net/LinkKey.java
index d3ff0f4..56c96e0 100644
--- a/core/api/src/main/java/org/onlab/onos/net/LinkKey.java
+++ b/core/api/src/main/java/org/onlab/onos/net/LinkKey.java
@@ -1,7 +1,11 @@
package org.onlab.onos.net;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Objects;
+import org.onlab.onos.net.link.LinkDescription;
+
import com.google.common.base.MoreObjects;
// TODO Consider renaming.
@@ -10,7 +14,7 @@
/**
* Immutable representation of a link identity.
*/
-public class LinkKey {
+public final class LinkKey {
private final ConnectPoint src;
private final ConnectPoint dst;
@@ -39,18 +43,40 @@
* @param src source connection point
* @param dst destination connection point
*/
- public LinkKey(ConnectPoint src, ConnectPoint dst) {
- this.src = src;
- this.dst = dst;
+ private LinkKey(ConnectPoint src, ConnectPoint dst) {
+ this.src = checkNotNull(src);
+ this.dst = checkNotNull(dst);
+ }
+
+ /**
+ * Creates a link identifier with source and destination connection point.
+ *
+ * @param src source connection point
+ * @param dst destination connection point
+ * @return a link identifier
+ */
+ public static LinkKey linkKey(ConnectPoint src, ConnectPoint dst) {
+ return new LinkKey(src, dst);
}
/**
* Creates a link identifier for the specified link.
*
* @param link link descriptor
+ * @return a link identifier
*/
- public LinkKey(Link link) {
- this(link.src(), link.dst());
+ public static LinkKey linkKey(Link link) {
+ return new LinkKey(link.src(), link.dst());
+ }
+
+ /**
+ * Creates a link identifier for the specified link.
+ *
+ * @param desc link description
+ * @return a link identifier
+ */
+ public static LinkKey linkKey(LinkDescription desc) {
+ return new LinkKey(desc.src(), desc.dst());
}
@Override
@@ -65,7 +91,7 @@
}
if (obj instanceof LinkKey) {
final LinkKey other = (LinkKey) obj;
- return Objects.equals(this.src(), other.src()) &&
+ return Objects.equals(this.src, other.src) &&
Objects.equals(this.dst, other.dst);
}
return false;
@@ -74,7 +100,7 @@
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
- .add("src", src())
+ .add("src", src)
.add("dst", dst)
.toString();
}