/** * @param vertexValues is the list of vertex values. * @param adjacencyMatrix is the adjacency matrix with the connections from the graph. * @param vertexIndex is the index of the vertex value to build the connection list. * @return a list of vertex values based on the connectivity of the given index on the adjacency * matrix. */ private static List<String> makeConnections( String[] vertexValues, boolean[][] adjacencyMatrix, int vertexIndex) { Preconditions.checkArgument(vertexValues != null, "The vertex values must be provided."); Preconditions.checkArgument(adjacencyMatrix != null, "The adjacency matrix must be provided."); Preconditions.checkArgument( vertexIndex >= 0, "The vertex index must be greater than or equals to 0."); List<String> connections = new SinglyLinkedList<>(); for (int i = 0; i < adjacencyMatrix.length; i++) { if (adjacencyMatrix[vertexIndex][i]) { connections.add(vertexValues[i]); } } return connections; }