]> nmode's Git Repositories - signal-cli/commitdiff
Refactor getGroup method
authorAsamK <asamk@gmx.de>
Sun, 12 Nov 2023 14:21:25 +0000 (15:21 +0100)
committerAsamK <asamk@gmx.de>
Sun, 12 Nov 2023 14:21:29 +0000 (15:21 +0100)
lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java

index a281622d27cad5e6b595635afd1d68962766a931..27d97fe571516cf7d08a27f2a41cd1ba9f0a21e8 100644 (file)
@@ -150,23 +150,29 @@ public class GroupStore {
 
     public GroupInfo getGroup(GroupId groupId) {
         try (final var connection = database.getConnection()) {
 
     public GroupInfo getGroup(GroupId groupId) {
         try (final var connection = database.getConnection()) {
-            if (groupId instanceof GroupIdV1 groupIdV1) {
+            return getGroup(connection, groupId);
+        } catch (SQLException e) {
+            throw new RuntimeException("Failed read from group store", e);
+        }
+    }
+
+    public GroupInfo getGroup(final Connection connection, final GroupId groupId) throws SQLException {
+        switch (groupId) {
+            case GroupIdV1 groupIdV1 -> {
                 final var group = getGroup(connection, groupIdV1);
                 if (group != null) {
                     return group;
                 }
                 return getGroupV2ByV1Id(connection, groupIdV1);
                 final var group = getGroup(connection, groupIdV1);
                 if (group != null) {
                     return group;
                 }
                 return getGroupV2ByV1Id(connection, groupIdV1);
-            } else if (groupId instanceof GroupIdV2 groupIdV2) {
+            }
+            case GroupIdV2 groupIdV2 -> {
                 final var group = getGroup(connection, groupIdV2);
                 if (group != null) {
                     return group;
                 }
                 return getGroupV1ByV2Id(connection, groupIdV2);
             }
                 final var group = getGroup(connection, groupIdV2);
                 if (group != null) {
                     return group;
                 }
                 return getGroupV1ByV2Id(connection, groupIdV2);
             }
-        } catch (SQLException e) {
-            throw new RuntimeException("Failed read from group store", e);
         }
         }
-        throw new AssertionError("Invalid group id type");
     }
 
     public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {
     }
 
     public GroupInfoV1 getOrCreateGroupV1(GroupIdV1 groupId) {