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 The type of vertex marking associated with the element. */ class WrapperElement { // ATTRIBUTE private MarkedVertex 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 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 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 The type of vertex marking associated with the WrapperElement. */ class WrapperComparator implements Comparator> { /** * 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 element1, WrapperElement element2) { return Double.compare(element1.getPriority(), element2.getPriority()); } }