]> git.mxchange.org Git - jaddressbook-lib.git/commitdiff
Added calculation for average lines in database file + check for add() call
authorRoland Haeder <roland@mxchange.org>
Mon, 20 Jul 2015 10:41:20 +0000 (12:41 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 20 Jul 2015 10:43:02 +0000 (12:43 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java

index b898e9be168303638282f077f8376c12c4d34c4f..e191b31dcb3d762d22df6a9b3eca31cfb9fed29a 100644 (file)
@@ -191,9 +191,15 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken
        // First rewind\r
        this.rewind();\r
 \r
+       // Get file size and divide it by 140 (possible average length of one line)\r
+       int lines = Math.round(this.length() / 140 + 0.5f);\r
+\r
+       // Debug message\r
+       this.getLogger().debug(MessageFormat.format("lines={0}", lines));\r
+\r
        // Instance list\r
        // @TODO The maximum length could be guessed from file size?\r
-       List<Contact> list = new ArrayList<>();\r
+       List<Contact> list = new ArrayList<>(lines);\r
 \r
        // Init variables\r
        StringTokenizer tokenizer;\r
@@ -416,10 +422,22 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken
                count++;\r
            }\r
 \r
+           // Debug message\r
+           this.getLogger().debug(MessageFormat.format("contact={0}", contact));\r
+\r
            // Is the contact read?\r
            if (contact instanceof Contact) {\r
                // Then add it\r
-               assert(list.add(contact));\r
+               boolean added = list.add(contact);\r
+\r
+               // Debug message\r
+               this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added));\r
+\r
+               // Has it been added?\r
+               if (!added) {\r
+                   // Not added\r
+                   this.getLogger().warn("Contact object has not been added.");\r
+               }\r
            }\r
        }\r
 \r