From 4dc0f96a5b864118a0892a522829ff6bdedb337b Mon Sep 17 00:00:00 2001 From: HLeiTR Date: Thu, 8 Dec 2022 17:01:05 -0500 Subject: [PATCH] [*] Removed warning of duplicated lines in IntelliJ --- .../database/MySQLDatabaseGateway.java | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/billgates/database/MySQLDatabaseGateway.java b/src/main/java/billgates/database/MySQLDatabaseGateway.java index b2bc95c..8adee6a 100644 --- a/src/main/java/billgates/database/MySQLDatabaseGateway.java +++ b/src/main/java/billgates/database/MySQLDatabaseGateway.java @@ -196,6 +196,26 @@ WHERE date BETWEEN CAST('%s' AS DATETIME) AND CAST('%s' AS DATETIME) return entries; } + // This is a method specifically used to obtain: + // Value, time, currency, description, from, to, location + public List getBasicEntryInfo(ResultSet resultSet) throws SQLException { + double value = resultSet.getDouble("value"); + Timestamp date = resultSet.getTimestamp("date"); + String currency = resultSet.getString("currency"); + String description = resultSet.getString("description"); + String from = resultSet.getString("from"); + String to = resultSet.getString("to"); + String location = resultSet.getString("location"); + + return new ArrayList<>(List.of(value, + date, + currency, + description, + from, + to, + location)); + } + @Override public Entry getEntryData(int billId, int entryId) { int splitBillId; @@ -221,15 +241,19 @@ public Entry getEntryData(int billId, int entryId) { if (resultSet.next()) { // Note that, aside from the general types that we have here // All the rest objects will be parsed in a string format - value = resultSet.getDouble("value"); - Timestamp date = resultSet.getTimestamp("date"); - currency = resultSet.getString("currency"); - description = resultSet.getString("description"); - from = resultSet.getString("from"); - to = resultSet.getString("to"); - location = resultSet.getString("location"); + splitBillId = resultSet.getInt("split_bill_id"); + List result = getBasicEntryInfo(resultSet); + + value = (double) result.get(0); + Timestamp date = (Timestamp) result.get(1); + currency = (String) result.get(2); + description = (String) result.get(3); + from = (String) result.get(4); + to = (String) result.get(5); + location = (String) result.get(6); + Instant i = Instant.ofEpochMilli(date.getTime()); // We can pass in the different zones we want to convert in, @@ -283,6 +307,7 @@ public SplitterEntry getSplitEntryData(int billId, int entryId) { if (resultSet.next()) { // Note that, aside from the general types that we have here // All the rest objects will be parsed in a string format + value = resultSet.getDouble("value"); Timestamp date = resultSet.getTimestamp("date"); currency = resultSet.getString("currency");