package graph; import java.util.Objects; import java.util.Vector; public class UndirectedGraph extends Graph { public UndirectedGraph() { super(); } public UndirectedGraph(String s) { super(s); } public boolean areAdjacent(MarkedVertex n1, MarkedVertex n2) { return true; } public boolean areAdjacent(String s1, String s2) throws NameDoesNotExistException { return true; } public String toString() { return ""; } public int degree(MarkedVertex n) { int degree = 0; for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n) { degree += 1; } if (i.getDestination() == n) { degree += 1; } } return degree; } public int degree(String s) throws NameDoesNotExistException{ for (MarkedVertex i: this.getAllVertexes()) { if (Objects.equals(i.getName(), s)) { return degree(i); } } throw new NameDoesNotExistException("One of the Vertexes might not exist"); } public Vector> getNeighbours(MarkedVertex n) { Vector> neighbours = new Vector<>(); for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n && !neighbours.contains(i.getDestination())) { neighbours.add(i.getDestination()); } else if (i.getDestination() == n && !neighbours.contains(i.getSource())) { neighbours.add(i.getSource()); } } return neighbours; } }