From: Roland Haeder Date: Mon, 20 Jul 2015 10:41:20 +0000 (+0200) Subject: Added calculation for average lines in database file + check for add() call X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f6b7d2d27cb8b83568e20d96d30c8f35bd920120;p=jbonuscard-lib.git Added calculation for average lines in database file + check for add() call Signed-off-by:Roland Häder --- 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."); + } } }