From 3738c1fc8b2fa92b819b1ff948b3b39de60757b7 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 29 Apr 2025 08:09:28 +0200 Subject: always use brace in for- and if-construct --- .../com/example/portfolio3/AdjListGraph.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java') diff --git a/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java b/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java index 88e54d6..f90172e 100644 --- a/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java +++ b/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java @@ -20,23 +20,27 @@ public class AdjListGraph extends AbstractGraph { /// foo public void insertEdge(final Vertex v1, final Vertex v2, final int w) { Edge e = new Edge(v1, v2, w); - if (!outEdge.containsKey(e.from())) + if (!outEdge.containsKey(e.from())) { outEdge.put(e.from(), new HashSet()); + } outEdge.get(e.from()).add(e); } /// foo public Collection edges() { Set edges = new HashSet<>(); - for (Vertex v: outEdge.keySet())edges.addAll(outEdge.get(v)); + for (Vertex v: outEdge.keySet()) { + edges.addAll(outEdge.get(v)); + } return edges; } /// foo public Collection outEdge(final Vertex v) { - if (!outEdge.containsKey(v)) + if (!outEdge.containsKey(v)) { return new HashSet(); + } return outEdge.get(v); } @@ -45,11 +49,13 @@ public class AdjListGraph extends AbstractGraph { public Integer getWeight(final Vertex v1, final Vertex v2) { // linear in number of outedges from vertices - if (!outEdge.containsKey(v1)) + if (!outEdge.containsKey(v1)) { return null; + } for (Edge e: outEdge.get(v1)) { - if (e.to() == v2) + if (e.to() == v2) { return e.weight(); + } } return null; -- cgit v1.2.3