2 * Copyright (c) 2019 Orange. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.graph.impl;
11 import static com.google.common.base.Preconditions.checkArgument;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.graph.ConnectedEdge;
15 import org.opendaylight.graph.ConnectedVertex;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Edge;
19 * This Class implements the Connected Edge used by the Connected Graph for path computation algorithms.
21 * @author Olivier Dugeon
22 * @author Philippe Niger
25 public class ConnectedEdgeImpl implements ConnectedEdge {
27 /* Reference to Source and Destination Connected Vertex within the Connected Graph */
28 private ConnectedVertexImpl source;
29 private ConnectedVertexImpl destination;
31 /* Reference to the Edge within the Graph associated to the Connected Graph */
34 /* Edge key in the Connected Graph */
37 public ConnectedEdgeImpl(@NonNull Long key) {
38 checkArgument(key != 0, "Edge Key must not be equal to 0");
43 public ConnectedEdgeImpl(@NonNull Edge edge) {
44 checkArgument(edge.getEdgeId().longValue() != 0, "Edge Key must not be equal to 0");
46 this.ceid = edge.getEdgeId().longValue();
50 * When edge is removed, we must disconnect source and destination Connected Vertices.
57 * Set Connected Vertex as source.
59 * @param vertex Vertex
61 public ConnectedEdgeImpl setSource(ConnectedVertexImpl vertex) {
67 * Set Connected Vertex as destination.
69 * @param vertex Vertex
71 public ConnectedEdgeImpl setDestination(ConnectedVertexImpl vertex) {
77 * Disconnect source Connected Vertex.
79 public void disconnectSource() {
81 source.removeOutput(this);
87 * Disconnect destination Connected Vertex.
89 public void disconnectDestination() {
90 if (destination != null) {
91 destination.removeInput(this);
97 * Disconnect both source and destination Connected Vertices.
99 public void disconnect() {
101 disconnectDestination();
105 * Set associated Edge to this Connected Edge.
109 public ConnectedEdgeImpl setEdge(Edge edge) {
115 public @NonNull Long getKey() {
120 public ConnectedVertex getSource() {
125 public ConnectedVertex getDestination() {
126 return this.destination;
130 public Edge getEdge() {
135 * Returns the name of the associated Edge if set or the interface address otherwise.
137 * @return Edge name or interface address
140 public String toString() {
144 if (edge.getName() != null) {
145 return edge.getName();
147 if (edge.getEdgeAttributes() != null) {
148 if (edge.getEdgeAttributes().getLocalAddress() != null) {
149 return edge.getEdgeAttributes().getLocalAddress().toString();
151 if (edge.getEdgeAttributes().getLocalIdentifier() != null) {
152 return edge.getEdgeAttributes().getLocalIdentifier().toString();
155 return "Unknown Edge";