From: AsamK Date: Sun, 12 Nov 2023 14:21:25 +0000 (+0100) Subject: Refactor getGroup method X-Git-Tag: v0.13.0~84 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/f06eeb01b971ad242cb209627744d7d8e1b03f47?hp=fbcc1cfb50b38b78f5e3fb986defaaa72f96f840 Refactor getGroup method --- diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java index a281622d..27d97fe5 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/groups/GroupStore.java @@ -150,23 +150,29 @@ public class GroupStore { 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); - } else if (groupId instanceof GroupIdV2 groupIdV2) { + } + case GroupIdV2 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) {