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/portfolio2/Database.java | 9 ++++++--- .../com/example/portfolio2/MyDB.java | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/com.example.portfolio2') diff --git a/src/com.example.portfolio2/com/example/portfolio2/Database.java b/src/com.example.portfolio2/com/example/portfolio2/Database.java index a4a9271..a6a144a 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Database.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Database.java @@ -29,8 +29,9 @@ class Database { /// @param name activity name /// @return index of activity as integer int getActivityIndeks(final String name) { - if (name == null) + if (name == null) { return -1; + } ArrayList result = db.query("select indeks from activity a where name is '" + name + "';", "indeks"); return Integer.parseInt(result.getFirst()); @@ -69,11 +70,13 @@ class Database { /// @param program programme name /// @return ECTS points as String String getSumEcts(final String program) { - if (program == null) + if (program == null) { return "0"; + } ArrayList result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '" + program + "' group by student.studid ;", "total_ects"); - if (result.isEmpty()) + if (result.isEmpty()) { return "0"; + } return result.getFirst(); } diff --git a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java index 9b02d39..ea0f6d6 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java +++ b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java @@ -15,7 +15,9 @@ public class MyDB { /// foo MyDB() { - if (conn == null) open(); + if (conn == null) { + open(); + } } /// foo @@ -25,7 +27,9 @@ public class MyDB { conn = DriverManager.getConnection(url); } catch (SQLException e) { System.out.println("cannot open"); - if (conn != null) close(); + if (conn != null) { + close(); + } throw new RuntimeException(e); } ; @@ -34,7 +38,9 @@ public class MyDB { /// foo public void close() { try { - if (conn != null) conn.close(); + if (conn != null) { + conn.close(); + } } catch (SQLException e) { throw new RuntimeException(e); } @@ -44,7 +50,9 @@ public class MyDB { /// foo /// @param sql foo public void cmd(final String sql) { - if (conn == null) open(); + if (conn == null) { + open(); + } if (conn == null) { System.out.println("No connection"); return; @@ -73,7 +81,9 @@ public class MyDB { /// @return foo public ArrayList query(final String query, final String fld) { ArrayList res = new ArrayList<>(); - if (conn == null) open(); + if (conn == null) { + open(); + } if (conn == null) { System.out.println("No connection"); throw new RuntimeException("No connection"); -- cgit v1.2.3