ProjektGraph/graph/NameDoesNotExistException.java

136 lines
3.4 KiB
Java
Raw Permalink Normal View History

2024-06-15 14:48:28 +00:00
package graph;
2024-06-25 15:18:34 +00:00
import java.util.Comparator;
2024-07-07 21:07:56 +00:00
/**
* Exception thrown when a user attempts to access a non-existent vertex by name.
*/
2024-06-26 00:20:36 +00:00
public class NameDoesNotExistException extends Exception {
2024-07-07 21:07:56 +00:00
/**
* Constructs a new NameDoesNotExistException with no detail message.
*/
2024-06-15 14:48:28 +00:00
public NameDoesNotExistException() {
super();
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* Constructs a new NameDoesNotExistException with the specified detail message.
*
* @param message The detail message.
*/
2024-06-15 14:48:28 +00:00
public NameDoesNotExistException(String message) {
super(message);
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* Constructs a new NameDoesNotExistException with the specified detail message and cause.
*
* @param message The detail message.
* @param cause The cause of the exception.
*/
2024-06-15 14:48:28 +00:00
public NameDoesNotExistException(String message, Throwable cause) {
super(message, cause);
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* 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.
*/
2024-06-15 14:48:28 +00:00
public NameDoesNotExistException(Throwable cause) {
super(cause);
}
}
2024-06-25 15:18:34 +00:00
2024-07-07 21:07:56 +00:00
/**
* Represents an element stored in a priority queue for graph algorithms.
*
* @param <T> The type of vertex marking associated with the element.
*/
2024-06-25 15:18:34 +00:00
class WrapperElement<T extends VertexMarking> {
// ATTRIBUTE
2024-07-07 21:07:56 +00:00
private MarkedVertex<T> element;
private double priority;
2024-06-25 15:18:34 +00:00
// KONSTRUKTOR
2024-07-07 21:07:56 +00:00
/**
* 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) {
2024-07-07 21:07:56 +00:00
this.element = element;
this.priority = priority;
2024-06-25 15:18:34 +00:00
}
// GET-ER
2024-07-07 21:07:56 +00:00
/**
* Retrieves the marked vertex stored in this wrapper element.
*
* @return The marked vertex.
*/
2024-06-25 15:18:34 +00:00
public MarkedVertex<T> getElement() {
2024-07-07 21:07:56 +00:00
return this.element;
2024-06-25 15:18:34 +00:00
}
2024-07-07 21:07:56 +00:00
/**
* Retrieves the priority associated with this wrapper element.
*
* @return The priority.
*/
public double getPriority() {
2024-07-07 21:07:56 +00:00
return this.priority;
2024-06-25 15:18:34 +00:00
}
2024-06-26 00:20:36 +00:00
// Ausgabe
2024-07-07 21:07:56 +00:00
/**
* Returns a string representation of this WrapperElement.
*
* @return A string representation containing the element and its priority.
*/
2024-06-26 00:20:36 +00:00
public String toString() {
2024-07-07 21:07:56 +00:00
return "WrapperElement{" +
"element=" + element +
", priority=" + priority +
'}';
2024-06-26 00:20:36 +00:00
}
2024-06-25 15:18:34 +00:00
}
2024-07-07 21:07:56 +00:00
/**
* Comparator for comparing WrapperElement objects based on their priority.
*
* @param <T> The type of vertex marking associated with the WrapperElement.
*/
2024-06-25 15:18:34 +00:00
class WrapperComparator<T extends VertexMarking> implements Comparator<WrapperElement<T>> {
2024-07-07 21:07:56 +00:00
/**
* 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.
*/
2024-06-25 15:18:34 +00:00
public int compare(WrapperElement<T> element1, WrapperElement<T> element2) {
return Double.compare(element1.getPriority(), element2.getPriority());
2024-06-25 15:18:34 +00:00
}
}