void createVertex(int x, int y) { for (Vertex vertex : allVertexes) { if (vertex.checkPosition(x, y)) { return; } } Vertex newVertex = new Vertex("N" + x + "_" + y, x, y); allVertexes.add(newVertex); for (Vertex checkVertex : allVertexes) { int diffX = Math.abs(checkVertex.getxPosition() - newVertex.getxPosition()); int diffY = Math.abs(checkVertex.getyPosition() - newVertex.getyPosition()); if ((diffX == 1) != (diffY == 1)) { if ((diffX == 0) != (diffY == 0)) { checkVertex.addAdjacentVertex(newVertex); } } } }
synchronized void toggleAdjecent(int x, int y) { Vertex tempAdjecentVertex = null; for (Vertex adjecentVertex : selectedVertex.getAdjacencyList()) { if (adjecentVertex.getxPosition() == x && adjecentVertex.getyPosition() == y) { tempAdjecentVertex = adjecentVertex; break; } } if (tempAdjecentVertex != null) { selectedVertex.getAdjacencyList().remove(tempAdjecentVertex); return; } Vertex tempNewAdjecentVertex = null; for (Vertex vertex : allVertexes) { if (vertex.checkPosition(x, y)) { tempNewAdjecentVertex = vertex; } } selectedVertex.getAdjacencyList().add(tempNewAdjecentVertex); }