package graph; import logging.LogElement; import logging.LogElementList; import java.util.Vector; public abstract class Graph { private String name; private Vector> vertexes = new Vector<>(); private Vector> edges = new Vector<>(); public Graph() {} public Graph(String s) { this.name = s; } public void addEdge(MarkedEdge e) { edges.add(e); } public void addVertex(MarkedVertex n) { vertexes.add(n); } public boolean areAdjacent(MarkedVertex n1, MarkedVertex n2){ for (MarkedEdge edge: edges){ if (edge.getSource() == n1 && edge.getDestination() == n2 || edge.getDestination() == n1 && edge.getSource() == n2){ return true; } } return false; } public boolean areAdjacent(String s1, String s2){ for (MarkedEdge edge: edges){ if (edge.getSource().getName().equals(s1) && edge.getDestination().getName().equals(s2)){ return true; } else if (edge.getSource().getName().equals(s2) && edge.getDestination().getName().equals(s1)){ return true; } } return false; } public int degree() { return edges.size(); } public Vector> getAllEdges() { return this.edges; } public Vector> getAllVertexes() { return this.vertexes; } public String getName() { return this.name; } public abstract visualizationElements.Graph getVisualizedGraph(); public abstract LogElementList getLogList(); /* public Vector getNeighbors(Vertex n1){ Vector neighbors = new Vector<>(); for (MarkedEdge edge : edges) { if (edge.getSource().equals(n1)) { neighbors.add(edge.getDestination()); } else if (edge.getDestination().equals(n1)){ neighbors.add(edge.getSource()); } } return neighbors; } */ public boolean hasEdge(MarkedEdge e) { return edges.contains(e); } public boolean hasEdge(String s) { for (MarkedEdge edge : edges) { if (edge.getName().equals(s)) { return true; } } return false; } public boolean hasEdge(MarkedVertex v1, MarkedVertex v2) { for (MarkedEdge edge : edges) { if (edge.getSource().equals(v1) && edge.getDestination().equals(v2)) { return true; } else if (edge.getSource().equals(v2) && edge.getDestination().equals(v1)) { return true; } } return false; } public boolean hasEdge(String s1, String s2) { for (MarkedEdge edge : edges) { if (edge.getSource().getName().equals(s1) && edge.getDestination().getName().equals(s2)) { return true; } else if (edge.getSource().getName().equals(s2) && edge.getDestination().getName().equals(s1)) { return true; } } return false; } public boolean hasLoop(MarkedVertex n) { for (MarkedEdge edge : edges) { if (edge.getSource().equals(n) && edge.getDestination().equals(n)) { return true; } } return false; } public boolean hasLoop(String s) { for (MarkedEdge edge : edges) { if (edge.getSource().getName().equals(s) && edge.getDestination().getName().equals(s)) { return true; } } return false; } public Boolean hasVertex(MarkedVertex n) { return vertexes.contains(n); } public boolean hasVertex(String s) { for (MarkedVertex vertex : vertexes) { if (vertex.getName().equals(s)) { return true; } } return false; } public int numberOfEdges() { return edges.size(); } public int numberOfVertexes() { return vertexes.size(); } public boolean removeEdge(MarkedEdge e) { return edges.remove(e); } public boolean removeEdge(String s) { for (MarkedEdge edge : edges) { if (edge.getName().equals(s)) { return edges.remove(edge); } } return false; } public boolean removeVertex(MarkedVertex n) { return vertexes.remove(n); } public boolean removeVertex(String s) { for (MarkedVertex vertex : vertexes) { if (vertex.getName().equals(s)) { return vertexes.remove(vertex); } } return false; } public void setName(String n) { this.name = n; } @Override public String toString() { return "Graph{" + "name='" + name + '\'' + ", vertexes=" + vertexes + ", edges=" + edges + '}'; } }