ProjektGraph/graph/Edge.java
2024-07-07 23:07:56 +02:00

109 lines
2.3 KiB
Java

package graph;
/**
* Abstract class representing an edge in a graph.
*/
public abstract class Edge {
// ATTRIBUTES
/** The name of the edge. */
private String name;
/** The source vertex of the edge. */
private Vertex source;
/** The destination vertex of the edge. */
private Vertex destination;
// CONSTRUCTORS
/**
* Default constructor initializes the edge with empty name and null source and destination vertices.
*/
public Edge() {
this.name = "";
this.source = null;
this.destination = null;
}
/**
* Constructor initializes the edge with a specified name, source, and destination vertices.
*
* @param s The name of the edge.
* @param n1 The source vertex of the edge.
* @param n2 The destination vertex of the edge.
*/
public Edge(String s, Vertex n1, Vertex n2) {
this.name = s;
this.source = n1;
this.destination = n2;
}
// GETTERS
/**
* Retrieves the name of the edge.
*
* @return The name of the edge.
*/
public String getName() {
return this.name;
}
/**
* Retrieves the source vertex of the edge.
*
* @return The source vertex of the edge.
*/
public Vertex getSource() {
return this.source;
}
/**
* Retrieves the destination vertex of the edge.
*
* @return The destination vertex of the edge.
*/
public Vertex getDestination() {
return this.destination;
}
/**
* Abstract method to retrieve the screen representation of the edge for visualization.
*
* @return The visualizationElements.Edge representing the screen edge.
*/
public abstract visualizationElements.Edge getScreenEdge();
// SETTERS
/**
* Sets the name of the edge.
*
* @param s The name to set for the edge.
*/
public void setName(String s) {
this.name = s;
}
/**
* Sets the source vertex of the edge.
*
* @param n The source vertex to set for the edge.
*/
public void setSource(Vertex n) {
this.source = n;
}
/**
* Sets the destination vertex of the edge.
*
* @param n The destination vertex to set for the edge.
*/
public void setDestination(Vertex n) {
this.destination = n;
}
}