2024-06-15 14:48:28 +00:00
|
|
|
package graph;
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Abstract class representing an edge in a graph.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public abstract class Edge {
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
// ATTRIBUTES
|
2024-06-15 19:55:30 +00:00
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/** The name of the edge. */
|
2024-06-15 14:48:28 +00:00
|
|
|
private String name;
|
2024-07-07 21:07:56 +00:00
|
|
|
|
|
|
|
/** The source vertex of the edge. */
|
2024-06-15 14:48:28 +00:00
|
|
|
private Vertex source;
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/** The destination vertex of the edge. */
|
|
|
|
private Vertex destination;
|
2024-06-15 14:48:28 +00:00
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
// CONSTRUCTORS
|
2024-06-15 19:55:30 +00:00
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Default constructor initializes the edge with empty name and null source and destination vertices.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public Edge() {
|
|
|
|
this.name = "";
|
|
|
|
this.source = null;
|
|
|
|
this.destination = null;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public Edge(String s, Vertex n1, Vertex n2) {
|
|
|
|
this.name = s;
|
|
|
|
this.source = n1;
|
|
|
|
this.destination = n2;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
// GETTERS
|
2024-06-15 14:48:28 +00:00
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the name of the edge.
|
|
|
|
*
|
|
|
|
* @return The name of the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public String getName() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the source vertex of the edge.
|
|
|
|
*
|
|
|
|
* @return The source vertex of the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public Vertex getSource() {
|
|
|
|
return this.source;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the destination vertex of the edge.
|
|
|
|
*
|
|
|
|
* @return The destination vertex of the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public Vertex getDestination() {
|
|
|
|
return this.destination;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Abstract method to retrieve the screen representation of the edge for visualization.
|
|
|
|
*
|
|
|
|
* @return The visualizationElements.Edge representing the screen edge.
|
|
|
|
*/
|
2024-07-02 22:46:21 +00:00
|
|
|
public abstract visualizationElements.Edge getScreenEdge();
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
// SETTERS
|
2024-07-02 22:46:21 +00:00
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Sets the name of the edge.
|
|
|
|
*
|
|
|
|
* @param s The name to set for the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public void setName(String s) {
|
|
|
|
this.name = s;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Sets the source vertex of the edge.
|
|
|
|
*
|
|
|
|
* @param n The source vertex to set for the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public void setSource(Vertex n) {
|
|
|
|
this.source = n;
|
|
|
|
}
|
|
|
|
|
2024-07-07 21:07:56 +00:00
|
|
|
/**
|
|
|
|
* Sets the destination vertex of the edge.
|
|
|
|
*
|
|
|
|
* @param n The destination vertex to set for the edge.
|
|
|
|
*/
|
2024-06-15 14:48:28 +00:00
|
|
|
public void setDestination(Vertex n) {
|
|
|
|
this.destination = n;
|
|
|
|
}
|
|
|
|
}
|
2024-07-07 21:07:56 +00:00
|
|
|
|