diff options
Diffstat (limited to 'src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java')
-rw-r--r-- | src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java b/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java index 41d5880..bd80c00 100644 --- a/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java +++ b/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java @@ -14,7 +14,8 @@ public class MatrixGraph extends AbstractGraph { private Integer[][] matrix = null; // made in constructor /// foo - // We must be able to map vertices to index in matrix and back again + // We must be able to map vertices + // to index in matrix and back again private Vertex[] index2vertex; // made in constructor /// foo @@ -42,7 +43,8 @@ public class MatrixGraph extends AbstractGraph { } int index = vertex2index.size(); if (index >= index2vertex.length) { - throw new RuntimeException("Too many vertices in graph"); + throw new RuntimeException( + "Too many vertices in graph"); } vertex2index.put(v, index); index2vertex[index] = v; @@ -51,7 +53,9 @@ public class MatrixGraph extends AbstractGraph { } /// foo - public final void insertEdge(final Vertex v1, final Vertex v2, final int w) { + public final void insertEdge( + final Vertex v1, final Vertex v2, final int w + ) { matrix[getIndex(v1)][getIndex(v2)] = w; } @@ -60,11 +64,16 @@ public class MatrixGraph extends AbstractGraph { HashSet<Edge> edges = new HashSet<>(); for (int i = 0; i < numVertex; i++) { for (int j = 0; j < numVertex; j++) { - Integer weight = matrix[i][j]; // may be null + + // may be null + Integer weight = matrix[i][j]; if (weight == null) { continue; } - edges.add(new Edge(index2vertex[i], index2vertex[j], weight)); + edges.add(new Edge( + index2vertex[i], + index2vertex[j], + weight)); } } @@ -87,9 +96,11 @@ public class MatrixGraph extends AbstractGraph { } /// foo - public final Integer getWeight(final Vertex v1, final Vertex v2) { + public final Integer getWeight( + final Vertex v1, final Vertex v2 + ) { - // constant time operation - return matrix[vertex2index.get(v1)][vertex2index.get(v2)]; + // constant time operation + return matrix[vertex2index.get(v1)][vertex2index.get(v2)]; } } |