ProjektGraph/graph/NameDoesNotExistException.java
i23007 deaffff595 Merge branch 'main' of https://gitea.hb.dhbw-stuttgart.de/i23024/ProjektGraph
# Conflicts:
#	graph/DirectedGraph.java
#	graph/Graph.java
#	graph/NameDoesNotExistException.java
#	graph/UndirectedGraph.java
#	out/production/ProjektGraph/graph/Graph.class
#	out/production/ProjektGraph/graph/WrapperComparator.class
#	out/production/ProjektGraph/graph/WrapperElement.class
2024-07-08 17:51:11 +02:00

136 lines
3.4 KiB
Java

package graph;
import java.util.Comparator;
/**
* Exception thrown when a user attempts to access a non-existent vertex by name.
*/
public class NameDoesNotExistException extends Exception {
/**
* Constructs a new NameDoesNotExistException with no detail message.
*/
public NameDoesNotExistException() {
super();
}
/**
* Constructs a new NameDoesNotExistException with the specified detail message.
*
* @param message The detail message.
*/
public NameDoesNotExistException(String message) {
super(message);
}
/**
* Constructs a new NameDoesNotExistException with the specified detail message and cause.
*
* @param message The detail message.
* @param cause The cause of the exception.
*/
public NameDoesNotExistException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new NameDoesNotExistException with the specified cause and a detail message
* that includes the cause's description.
*
* @param cause The cause of the exception.
*/
public NameDoesNotExistException(Throwable cause) {
super(cause);
}
}
/**
* Represents an element stored in a priority queue for graph algorithms.
*
* @param <T> The type of vertex marking associated with the element.
*/
class WrapperElement<T extends VertexMarking> {
// ATTRIBUTE
private MarkedVertex<T> element;
private double priority;
// KONSTRUKTOR
/**
* Constructs a WrapperElement with the specified marked vertex and priority.
*
* @param element The marked vertex to wrap.
* @param priority The priority associated with the element.
*/
public WrapperElement(MarkedVertex<T> element, double priority) {
this.element = element;
this.priority = priority;
}
// GET-ER
/**
* Retrieves the marked vertex stored in this wrapper element.
*
* @return The marked vertex.
*/
public MarkedVertex<T> getElement() {
return this.element;
}
/**
* Retrieves the priority associated with this wrapper element.
*
* @return The priority.
*/
public double getPriority() {
return this.priority;
}
// Ausgabe
/**
* Returns a string representation of this WrapperElement.
*
* @return A string representation containing the element and its priority.
*/
public String toString() {
return "WrapperElement{" +
"element=" + element +
", priority=" + priority +
'}';
}
}
/**
* Comparator for comparing WrapperElement objects based on their priority.
*
* @param <T> The type of vertex marking associated with the WrapperElement.
*/
class WrapperComparator<T extends VertexMarking> implements Comparator<WrapperElement<T>> {
/**
* Compares two WrapperElement objects based on their priorities.
*
* @param element1 The first WrapperElement to compare.
* @param element2 The second WrapperElement to compare.
* @return A negative integer, zero, or a positive integer as the first element's
* priority is less than, equal to, or greater than the second element's priority.
*/
public int compare(WrapperElement<T> element1, WrapperElement<T> element2) {
return Double.compare(element1.getPriority(), element2.getPriority());
}
}