From f6b7d2d27cb8b83568e20d96d30c8f35bd920120 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 20 Jul 2015 12:41:20 +0200 Subject: [PATCH] Added calculation for average lines in database file + check for add() call MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by:Roland Häder --- .../backend/csv/CsvDatabaseBackend.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java index b898e9b..e191b31 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java @@ -191,9 +191,15 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken // First rewind this.rewind(); + // Get file size and divide it by 140 (possible average length of one line) + int lines = Math.round(this.length() / 140 + 0.5f); + + // Debug message + this.getLogger().debug(MessageFormat.format("lines={0}", lines)); + // Instance list // @TODO The maximum length could be guessed from file size? - List list = new ArrayList<>(); + List list = new ArrayList<>(lines); // Init variables StringTokenizer tokenizer; @@ -416,10 +422,22 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken count++; } + // Debug message + this.getLogger().debug(MessageFormat.format("contact={0}", contact)); + // Is the contact read? if (contact instanceof Contact) { // Then add it - assert(list.add(contact)); + boolean added = list.add(contact); + + // Debug message + this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); + + // Has it been added? + if (!added) { + // Not added + this.getLogger().warn("Contact object has not been added."); + } } } -- 2.39.5