package graph; import logging.LogElement; import logging.LogElementList; import java.util.Vector; class UndirectedGraph extends Graph { public UndirectedGraph() {} public UndirectedGraph(String s) { super(s); } LogElementList logList = new LogElementList<>(); // Erzeugen einer LogElementList für die Protokollierung private visualizationElements.Graph visualizedGraph; public int degree(MarkedVertex n) { int degree = 0; for (MarkedEdge edge : getAllEdges()) { if (edge.getSource().equals(n) || edge.getDestination().equals(n)) { degree++; } } return degree; } public int degree(String s) { for (MarkedVertex vertex : getAllVertexes()) { if (vertex.getName().equals(s)) { return degree(vertex); } } return 0; } public visualizationElements.Graph getVisualizedGraph() { return this.visualizedGraph; } public LogElementList getLogList(){ return this.logList; } public Vector> getNeighbours(MarkedVertex n) { Vector> neighbours = new Vector<>(); for (MarkedEdge edge : getAllEdges()) { if (edge.getSource().equals(n)) { neighbours.add((MarkedVertex) edge.getDestination()); } else if (edge.getDestination().equals(n)) { neighbours.add((MarkedVertex) edge.getSource()); } } return neighbours; } @Override public boolean areAdjacent(MarkedVertex n1, MarkedVertex n2) { for (MarkedEdge edge : getAllEdges()) { if ((edge.getSource().equals(n1) && edge.getDestination().equals(n2)) || (edge.getSource().equals(n2) && edge.getDestination().equals(n1))) { return true; } } return false; } @Override public boolean areAdjacent(String s1, String s2) { for (MarkedEdge edge : getAllEdges()) { if ((edge.getSource().getName().equals(s1) && edge.getDestination().getName().equals(s2)) || (edge.getSource().getName().equals(s2) && edge.getDestination().getName().equals(s1))) { return true; } } return false; } @Override public String toString() { return "UndirectedGraph{} " + super.toString(); } }