2 * Copyright (c) 2015 NEC Corporation
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this
7 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.vtn.manager.internal.util.inventory;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.impl.topology.rev150209.vtn.topology.VtnLink;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
17 * {@code LinkEdge} describes an edge of network topology.
19 public final class LinkEdge {
21 * The source switch port of this edge.
23 private final SalPort sourcePort;
26 * The destination switch port of this edge.
28 private final SalPort destinationPort;
31 * Construct a new instance.
33 * @param vlink A {@link VtnLink} instance.
34 * @throws NullPointerException
35 * {@code vlink} is {@code null}.
36 * @throws IllegalArgumentException
37 * An invalid instance is specified to {@code vlink}.
39 public LinkEdge(VtnLink vlink) {
40 sourcePort = SalPort.create(vlink.getSource());
41 if (sourcePort == null) {
42 throw new IllegalArgumentException(
43 "Source port is not configured: " + vlink);
46 destinationPort = SalPort.create(vlink.getDestination());
47 if (destinationPort == null) {
48 throw new IllegalArgumentException(
49 "Destination port is not configured: " + vlink);
54 * Construct a new instance.
56 * @param link A {@link Link} instance.
57 * @throws NullPointerException
58 * {@code link} is {@code null}.
59 * @throws IllegalArgumentException
60 * An invalid instance is specified to {@code link}.
62 public LinkEdge(Link link) {
63 sourcePort = SalPort.create(link.getSource());
64 if (sourcePort == null) {
65 throw new IllegalArgumentException(
66 "Source port is not configured: " + link);
69 destinationPort = SalPort.create(link.getDestination());
70 if (destinationPort == null) {
71 throw new IllegalArgumentException(
72 "Destination port is not configured: " + link);
77 * Return the source port of this edge.
79 * @return A {@link SalPort} instance which represents the source
80 * switch port of the edge.
82 public SalPort getSourcePort() {
87 * Return the destination port of this edge.
89 * @return A {@link SalPort} instance which represents the destination
90 * switch port of the edge.
92 public SalPort getDestinationPort() {
93 return destinationPort;
97 * Determine whether the given object is identical to this object.
99 * @param o An object to be compared.
100 * @return {@code true} if identical. Otherwise {@code false}.
103 public boolean equals(Object o) {
107 if (o == null || !getClass().equals(o.getClass())) {
111 LinkEdge le = (LinkEdge)o;
112 return (sourcePort.equals(le.sourcePort) &&
113 destinationPort.equals(le.destinationPort));
117 * Return the hash code of this object.
119 * @return The hash code.
122 public int hashCode() {
123 return sourcePort.hashCode() + destinationPort.hashCode() * 31;
127 * Return a string representation of this object.
129 * @return A string representation of this object.
132 public String toString() {
133 StringBuilder builder = new StringBuilder("LinkEdge[");
134 builder.append(sourcePort).append(" -> ").append(destinationPort).
137 return builder.toString();