]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
Renamed some classes/interfaces to make it clear they belong only to this project...
authorRoland Haeder <roland@mxchange.org>
Fri, 7 Aug 2015 06:32:47 +0000 (08:32 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 7 Aug 2015 06:32:47 +0000 (08:32 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

18 files changed:
Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java
Addressbook/src/org/mxchange/addressbook/client/BaseAddressbookClient.java
Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java
Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java
Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java
Addressbook/src/org/mxchange/addressbook/database/contact/AddressbookContactDatabaseConstants.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/database/contact/ContactDatabaseConstants.java [deleted file]
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java [deleted file]
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactFrontend.java [deleted file]
Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java [deleted file]
Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableAddressbookContact.java [new file with mode: 0644]
Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java [deleted file]
Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java
Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java

index 66834d9bd750aaa62262e33257f53f5b9370d86b..c14c64fa8e1ce3339a00542fe161918a963bbc9a 100644 (file)
@@ -146,15 +146,6 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App
                this.initBundle();
        }
 
-       /**
-        * Getter for printable application name
-        *
-        * @return A printable name
-        */
-       public static String printableTitle () {
-               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N
-       }
-
        /**
         * Bootstraps application
         */
@@ -240,6 +231,21 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App
                this.getLogger().debug("Main loop exit - shutting down ..."); //NOI18N
        }
 
+       /**
+        * Shuts down the application.
+        */
+       @Override
+       public void doShutdown () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+               
+               // Shutdown client
+               this.getClient().doShutdown();
+               
+               this.getLogger().info("End of program (last line)"); //NOI18N
+               System.exit(0);
+       }
+
        /**
         * Enables console client by setting propper flag
         */
@@ -348,17 +354,11 @@ public class AddressbookApplication extends BaseAddressbookSystem implements App
        }
 
        /**
-        * Shuts down the application.
+        * Getter for printable application name
+        *
+        * @return A printable name
         */
-       @Override
-       public void doShutdown () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Shutdown client
-               this.getClient().doShutdown();
-
-               this.getLogger().info("End of program (last line)"); //NOI18N
-               System.exit(0);
+       public static String printableTitle () {
+               return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N
        }
 }
index ff977bbf934d497992964463e9a92752daca9f59..faafb9d0a344f39565fa5de05102b0e21ab60820 100644 (file)
@@ -19,11 +19,11 @@ package org.mxchange.addressbook.client;
 import java.text.MessageFormat;
 import java.util.HashMap;
 import java.util.Map;
-import org.mxchange.addressbook.manager.contact.ContactManager;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
+import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
 import org.mxchange.addressbook.menu.Menu;
 import org.mxchange.jcore.client.BaseClient;
 import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.manager.database.ManageableDatabase;
 
 /**
  * A general addressbook client
@@ -114,7 +114,7 @@ public abstract class BaseAddressbookClient extends BaseClient {
                
                // Init contact manager with console client
                // @TODO Static initial amount of contacts
-               ManageableContact manager = new ContactManager((Client) this);
+               ManageableDatabase manager = new AddressbookContactManager((Client) this);
                
                // Set it here
                this.setContactManager(manager);
@@ -145,7 +145,7 @@ public abstract class BaseAddressbookClient extends BaseClient {
                }
 
                // Show menu
-               menu.show((Client) this);
+               menu.show(this);
 
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
index 3dbb7020d835d67af3ea0d346d8cfc9c31f9cc0a..5e8f7dab61d57806641088b4c288b73ba02a31a0 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.contact.Gender;
 import org.mxchange.addressbook.contact.user.UserContact;
 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
+import org.mxchange.addressbook.manager.contact.ManageableAddressbookContact;
 import org.mxchange.addressbook.menu.Menu;
 import org.mxchange.addressbook.menu.MenuTools;
 import org.mxchange.addressbook.menu.console.ConsoleMenu;
@@ -166,7 +166,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // Own street and number
                String streetNumber = manager.enterOwnStreet();
@@ -208,7 +208,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // Gender:
                Gender gender = manager.enterOwnGender();
@@ -250,7 +250,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // Phone number
                String phoneNumber = manager.enterOwnPhoneNumber();
@@ -284,7 +284,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.getLogger().trace("CALLED!"); //NOI18N
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // First ask for gender
                Gender gender = manager.enterOwnGender();
@@ -337,7 +337,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // @TODO Rewrite this ugly switch() block
                switch (choice) {
@@ -622,7 +622,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                char choice = this.enterChar(new char[] {'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) ");
 
                // Get manager and cast it
-               ManageableContact manager = (ManageableContact) this.getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getManager();
 
                // @TODO Get rid of this ugly switch block, too
                switch (choice) {
@@ -715,6 +715,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
        /**
         * Fills menu map with menu entries
         */
+       @Override
        protected final void fillMenuMap () {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
index 7a72c690b6babaa807e0d7abf28fa6126c952d30..244c73f266f34ac0b93d872f406245ce9822c6fa 100644 (file)
@@ -46,12 +46,12 @@ import javax.swing.border.TitledBorder;
 import javax.swing.table.TableModel;
 import org.mxchange.addressbook.BaseAddressbookSystem;
 import org.mxchange.addressbook.application.AddressbookApplication;
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.jcore.contact.Gender;
 import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
+import org.mxchange.addressbook.manager.contact.ManageableAddressbookContact;
 import org.mxchange.addressbook.model.contact.ContactTableModel;
 import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.contact.Gender;
 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
 
 /**
@@ -211,7 +211,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); //NOI18N
 
                // Get and cast manager instance
-               ManageableContact manager = (ManageableContact) this.getClient().getManager();
+               ManageableAddressbookContact manager = (ManageableAddressbookContact) this.getClient().getManager();
 
                // Has the user entered own data?
                if (manager.isOwnContactAdded()) {
@@ -241,7 +241,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
         * you may not want.
         *
         * @throws
-        * org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If
+        * org.mxchange.jcore.exceptions.FrameAlreadyInitializedException If
         * this method has been called twice
         */
        @Override
@@ -298,6 +298,30 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
+       /**
+        * Adds a new menu item with given key to menu instance
+        *
+        * @param menu Menu instance to add item to
+        * @param key Message key part
+        * @param listener Listener instance
+        */
+       private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
+               
+               // New instance
+               JMenuItem item = this.initMenuItemWithTooltip(key);
+               
+               // Add listener
+               item.addActionListener(listener);
+               
+               // Add item -> menu
+               menu.add(item);
+               
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
        /**
         * Adds a JTextField with label and tool tip to given panel
         *
@@ -644,7 +668,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                        @Override
                        public void actionPerformed (final ActionEvent e) {
                                try {
-                                       ManageableContact manager = (ManageableContact) self.getClient().getManager();
+                                       ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
                                        manager.doEnterOwnData();
                                } catch (final ContactAlreadyAddedException ex) {
                                        // Already added, log away
@@ -669,7 +693,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                         */
                        @Override
                        public void actionPerformed (final ActionEvent e) {
-                               ManageableContact manager = (ManageableContact) self.getClient().getManager();
+                               ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
                                manager.doChangeOwnData();
                        }
                });
@@ -687,7 +711,7 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                         */
                        @Override
                        public void actionPerformed (final ActionEvent e) {
-                               ManageableContact manager = (ManageableContact) self.getClient().getManager();
+                               ManageableAddressbookContact manager = (ManageableAddressbookContact) self.getClient().getManager();
                                manager.doAddOtherAddress();
                        }
                });
@@ -702,30 +726,6 @@ public class AddressbookFrame extends BaseAddressbookSystem implements ClientFra
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Adds a new menu item with given key to menu instance
-        *
-        * @param menu Menu instance to add item to
-        * @param key Message key part
-        * @param listener Listener instance
-        */
-       private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
-
-               // New instance
-               JMenuItem item = this.initMenuItemWithTooltip(key);
-
-               // Add listener
-               item.addActionListener(listener);
-
-               // Add item -> menu
-               menu.add(item);
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
        /**
         * Initializes name panel
         *
index 61cfc42e6b6b40168abf575ec03b3745423d0f9d..cd36ca0b2dc852b9d858cc12063ce46b334a2c05 100644 (file)
@@ -16,9 +16,9 @@
  */
 package org.mxchange.addressbook.client.gui;
 
-import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.FrameworkInterface;
 import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.contact.Contact;
 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
 
 /**
@@ -57,7 +57,7 @@ public interface ClientFrame extends FrameworkInterface {
         * Initializes frame
         *
         * @throws
-        * org.mxchange.addressbook.exceptions.FrameAlreadyInitializedException If
+        * org.mxchange.jcore.exceptions.FrameAlreadyInitializedException If
         * this method has been called twice
         */
        public void init () throws FrameAlreadyInitializedException;
index 90750c9e29a0bfb2ed5bca58c5e6b71c384327d7..e43e5acbb74804190ae3bfd384f60b108b018a17 100644 (file)
@@ -18,11 +18,11 @@ package org.mxchange.addressbook.client.gui;
 
 import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.addressbook.client.BaseAddressbookClient;
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.jcore.contact.Gender;
 import org.mxchange.addressbook.menu.Menu;
 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
 import org.mxchange.jcore.application.Application;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.contact.Gender;
 import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 
diff --git a/Addressbook/src/org/mxchange/addressbook/database/contact/AddressbookContactDatabaseConstants.java b/Addressbook/src/org/mxchange/addressbook/database/contact/AddressbookContactDatabaseConstants.java
new file mode 100644 (file)
index 0000000..48527ad
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.database.contact;
+
+/**
+ * A placeholder for some data
+ *
+ * @author Roland Haeder
+ */
+public final class AddressbookContactDatabaseConstants {
+       /**
+        * Column own_contact
+        */
+       public static final String COLUMN_NAME_OWN_CONTACT = "own_contact"; //NOI18N
+
+       /**
+        * No instances are allowed as this class only holds static attributes
+        */
+       private AddressbookContactDatabaseConstants () {
+       }
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/database/contact/ContactDatabaseConstants.java b/Addressbook/src/org/mxchange/addressbook/database/contact/ContactDatabaseConstants.java
deleted file mode 100644 (file)
index f42a164..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.database.contact;
-
-/**
- * A placeholder for some data
- *
- * @author Roland Haeder
- */
-public final class ContactDatabaseConstants {
-       /**
-        * Column own_contact
-        */
-       public static final String COLUMN_NAME_OWN_CONTACT = "own_contact"; //NOI18N
-
-       /**
-        * No instances are allowed as this class only holds static attributes
-        */
-       private ContactDatabaseConstants () {
-       }
-}
diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactDatabaseFrontend.java
new file mode 100644 (file)
index 0000000..7442ef7
--- /dev/null
@@ -0,0 +1,530 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.database.frontend.contact;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import org.mxchange.addressbook.contact.book.BookContact;
+import org.mxchange.addressbook.contact.user.UserContact;
+import org.mxchange.addressbook.database.contact.AddressbookContactDatabaseConstants;
+import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
+import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.jcore.database.storage.Storeable;
+import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+
+/**
+ * Stores and retrieves Contact instances
+ *
+ * @author Roland Haeder
+ */
+public class AddressbookContactDatabaseFrontend extends BaseDatabaseFrontend implements AddressbookContactFrontend {
+
+       /**
+        * Constructor which accepts a contact manager
+        *
+        * @param manager Manager instance
+        */
+       public AddressbookContactDatabaseFrontend (final AddressbookContactManager manager) {
+               // Call own constructor
+               this();
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("manager={0} - CALLED!", manager)); //NOI18N
+
+               // Manager instance must not be null
+               if (manager == null) {
+                       // Abort here
+                       throw new NullPointerException("manager is null"); //NOI18N
+               }
+
+               // Set contact manager
+               this.setContactManager(manager);
+       }
+
+       /**
+        * Basic constrcutor
+        */
+       protected AddressbookContactDatabaseFrontend () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Set "table" name
+               this.setTableName("contacts"); //NOI18N
+
+               try {
+                       // Initalize backend
+                       this.initBackend();
+               } catch (final UnsupportedDatabaseBackendException ex) {
+                       // Abort program
+                       this.abortProgramWithException(ex);
+               } catch (final SQLException ex) {
+                       // Abort here
+                       this.abortProgramWithException(ex);
+               }
+       }
+
+       /**
+        * Adds given contact instance to database
+        *
+        * @param contact Contact instance
+        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact instance is already found
+        */
+       @Override
+       public void addContact (final Contact contact) throws ContactAlreadyAddedException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Make sure the contact is set
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               try {
+                       // First check if the contact is there
+                       if (this.isContactFound(contact)) {
+                               // Already there
+                               throw new ContactAlreadyAddedException(contact);
+                       }
+
+                       // Then add it
+                       this.getBackend().store((Storeable) contact);
+               } catch (final IOException ex) {
+                       // Abort here
+                       this.abortProgramWithException(ex);
+               } catch (final BadTokenException ex) {
+                       // Abort here
+                       this.abortProgramWithException(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+       }
+
+       /**
+        * Shuts down the database layer
+        */
+       @Override
+       public void doShutdown () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Shutdown backend
+               this.getBackend().doShutdown();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Some "getter" for total contact count
+        *
+        * @return Total contact count
+        */
+       @Override
+       public int getContactsCount () throws SQLException {
+               // And deligate to backend
+               return this.getBackend().getTotalCount(); //NOI18N
+       }
+
+       /**
+        * Some "getter" for own contact instance
+        *
+        * @return Own contact instance
+        */
+       @Override
+       public Contact getOwnContact () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get row index back from backend
+               int rowIndex = this.getBackend().getRowIndexFromColumn(AddressbookContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("rowIndex={0}", rowIndex));
+
+               // Init instance
+               Contact contact = null;
+
+               try {
+                       // Now simply read the row
+                       contact = (Contact) this.getBackend().readRow(rowIndex);
+               } catch (final BadTokenException ex) {
+                       // Bad token found
+                       this.abortProgramWithException(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact));
+
+               // Return it
+               return contact;
+       }
+
+       /**
+        * Checks if given Contact is found
+        * 
+        * @param contact Contact instance to check
+        * @return Whether the given Contact instance is found
+        */
+       @Override
+       public boolean isContactFound (final Contact contact) throws BadTokenException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+
+               // contact should not be null
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Start iteration
+               Iterator<? extends Storeable> iterator = this.getBackend().iterator();
+
+               // Check all entries
+               while (iterator.hasNext()) {
+                       // Get next element
+                       Contact c = (Contact) iterator.next();
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("c={0},contact={1}", c, contact)); //NOI18N
+
+                       // Is it added?
+                       if (c.equals(contact)) {
+                               // Is found
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
+
+               // Return it
+               return isFound;
+       }
+
+       /**
+        * Checks whether own contact is found in database
+        *
+        * @return Whether own contact is found
+        */
+       @Override
+       public boolean isOwnContactFound () throws SQLException {
+               // Deligate this call to backend
+               return this.getBackend().isRowFound(AddressbookContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
+       }
+
+       /**
+        * Parses given line from database backend into a Storeable instance. Please
+        * note that not all backends need this.
+        *
+        * @param line Line from database backend
+        * @return A Storeable instance
+        */
+       @Override
+       public Storeable parseLineToStoreable (final String line) throws BadTokenException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
+
+               // Call inner method
+               Contact contact = this.parseLineToContact(line);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
+
+               // Return it
+               return (Storeable) contact;
+       }
+
+       /**
+        * Reads a single row and parses it to a contact instance
+        *
+        * @param rowIndex Row index (also how much to skip)
+        * @return Contact instance
+        */
+       @Override
+       public Contact readSingleContact (final int rowIndex) {
+               try {
+                       // Deligate this to backend instance
+                       return (Contact) this.getBackend().readRow(rowIndex);
+               } catch (final BadTokenException ex) {
+                       // Bad token found
+                       this.abortProgramWithException(ex);
+               }
+
+               // Bad state, should not be reached
+               throw new IllegalStateException("This should not be reached");
+       }
+
+       /**
+        * Parses given line and creates a Contact instance
+        * 
+        * @param line Raw line to parse
+        *
+        * @return Contact instance
+        */
+       private Contact parseLineToContact (final String line) throws BadTokenException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
+
+               // Init A lot variables
+               Long num = null;
+               Boolean bool = null;
+               Gender gender = null;
+               int count = 0;
+               Contact contact = null;
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N
+
+               // Then tokenize it
+               // @TODO Move this into separate method
+               StringTokenizer tokenizer = new StringTokenizer(line, ";"); //NOI18N
+
+               // Reset variables
+               count = 0;
+               contact = null;
+
+               // The tokens are now available, so get all
+               while (tokenizer.hasMoreElements()) {
+                       // Reset variables
+                       num = null;
+                       bool = null;
+
+                       // Get next token
+                       String token = tokenizer.nextToken();
+
+                       // If char " is at pos 2 (0,1,2), then cut it of there
+                       if ((token.charAt(0) != '"') && (token.charAt(2) == '"')) {
+                               // UTF-8 writer characters found
+                               token = token.substring(2);
+                       }
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("token={0}", token)); //NOI18N
+
+                       // Verify token, it must have double-quotes on each side
+                       if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { //NOI18N
+                               // Something bad was read
+                               throw new BadTokenException(token, count); //NOI18N
+                       }
+
+                       // All fine, so remove it
+                       String strippedToken = token.substring(1, token.length() - 1);
+
+                       // Is the string's content "null"?
+                       if (strippedToken.equals("null")) { //NOI18N
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken)); //NOI18N
+
+                               // This needs to be set to null
+                               strippedToken = null;
+                       }
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken)); //NOI18N
+
+                       // Now, let's try a number check, if no null
+                       if (strippedToken != null) {
+                               // Okay, no null, maybe the string bears a decimal number?
+                               try {
+                                       num = Long.valueOf(strippedToken);
+
+                                       // Debug message
+                                       this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); //NOI18N
+                               } catch (final NumberFormatException ex) {
+                                       // No number, then set default
+                                       num = null;
+                               }
+                       }
+
+                       // Now, let's try a boolean check, if no null
+                       if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { //NOI18N
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken)); //NOI18N
+
+                               // parseBoolean() is relaxed, so no exceptions
+                               bool = Boolean.valueOf(strippedToken);
+                       }
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("strippedToken={0},num={1},bool={2}", strippedToken, num, bool)); //NOI18N
+
+                       // Now, let's try a gender check, if no null
+                       if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) { //NOI18N
+                               // Get first character
+                               gender = Gender.fromChar(strippedToken.charAt(0));
+
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("strippedToken={0},gender={1}", strippedToken, gender)); //NOI18N
+
+                               // This instance must be there
+                               assert (gender instanceof Gender) : MessageFormat.format("gender is not set by Gender.fromChar({0})", strippedToken); //NOI18N
+                       }
+
+                       // Now it depends on the counter which position we need to check
+                       switch (count) {
+                               case 0: // isOwnContact
+                                       assert ((bool instanceof Boolean));
+
+                                       // Debug message
+                                       this.getLogger().debug(MessageFormat.format("bool={0}", bool)); //NOI18N
+
+                                       // Is it own contact?
+                                       if (true == bool) {
+                                               // Debug message
+                                               this.getLogger().debug("Creating UserContact object ..."); //NOI18N
+
+                                               // Own entry
+                                               contact = new UserContact();
+                                       } else {
+                                               // Debug message
+                                               this.getLogger().debug("Creating BookContact object ..."); //NOI18N
+
+                                               // Other contact
+                                               contact = new BookContact();
+                                       }
+                                       break;
+
+                               case 1: // Gender
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setGender(gender);
+                                       break;
+
+                               case 2: // Surname
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
+
+                                       // Update data
+                                       contact.setSurname(strippedToken);
+                                       break;
+
+                               case 3: // Family name
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
+
+                                       // Update data
+                                       contact.setFamilyName(strippedToken);
+                                       break;
+
+                               case 4: // Company name
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
+
+                                       // Update data
+                                       contact.setCompanyName(strippedToken);
+                                       break;
+
+                               case 5: // Street number
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setHouseNumber(num);
+                                       break;
+
+                               case 6: // ZIP code
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setZipCode(num);
+                                       break;
+
+                               case 7: // City name
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setCity(strippedToken);
+                                       break;
+
+                               case 8: // Country code
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setCountryCode(strippedToken);
+                                       break;
+
+                               case 9: // Phone number
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setPhoneNumber(strippedToken);
+                                       break;
+
+                               case 10: // Fax number
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setFaxNumber(strippedToken);
+                                       break;
+
+                               case 11: // Cellphone number
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setCellphoneNumber(strippedToken);
+                                       break;
+
+                               case 12: // Email address
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setEmailAddress(strippedToken);
+                                       break;
+
+                               case 13: // Birthday
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setBirthday(strippedToken);
+                                       break;
+
+                               case 14: // Comment
+                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
+
+                                       // Update data
+                                       contact.setComment(strippedToken);
+                                       break;
+
+                               default: // New data entry
+                                       this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); //NOI18N
+                                       break;
+                       }
+
+                       // Increment counter for next round
+                       count++;
+               }
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
+
+               // Return finished instance
+               return contact;
+       }
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/AddressbookContactFrontend.java
new file mode 100644 (file)
index 0000000..3b05869
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2015 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.database.frontend.contact;
+
+import java.sql.SQLException;
+import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.database.frontend.DatabaseFrontend;
+import org.mxchange.jcore.exceptions.BadTokenException;
+
+/**
+ *
+ * @author Roland Häder
+ */
+public interface AddressbookContactFrontend extends DatabaseFrontend {
+
+       /**
+        * Adds given contact instance to database
+        *
+        * @param contact Contact instance to add
+        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact is already added
+        */
+       public void addContact (final Contact contact) throws ContactAlreadyAddedException;
+
+       /**
+        * Shuts down the database layer
+        */
+       public void doShutdown ();
+
+       /**
+        * Some "getter" for total contacts count
+        *
+        * @return Total contacts count
+        * @throws java.sql.SQLException If any SQL error occurs
+        */
+       public int getContactsCount () throws SQLException;
+
+       /**
+        * Checks if given Contact is found
+        * 
+        * @param contact Contact instance to check
+        * @return Whether the given Contact instance is found
+        * @throws org.mxchange.jcore.exceptions.BadTokenException Continued throw
+        */
+       public boolean isContactFound (final Contact contact) throws BadTokenException;
+
+       /**
+        * Some "getter" for own contact instance
+        *
+        * @return Own contact instance
+        */
+       public Contact getOwnContact ();
+
+       /**
+        * Checks whether own contact is found
+        * 
+        * @return Whether own contact is found
+        * @throws java.sql.SQLException If any SQL error occurs
+        */
+       public boolean isOwnContactFound () throws SQLException;
+
+       /**
+        * Reads a single row and parses it to a contact instance
+        *
+        * @param rowIndex Row index (also how much to skip)
+        * @return Contact instance
+        */
+       public Contact readSingleContact (final int rowIndex);
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
deleted file mode 100644 (file)
index 8280ad0..0000000
+++ /dev/null
@@ -1,530 +0,0 @@
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.database.frontend.contact;
-
-import java.io.IOException;
-import java.sql.SQLException;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.jcore.contact.Gender;
-import org.mxchange.addressbook.contact.book.BookContact;
-import org.mxchange.addressbook.contact.user.UserContact;
-import org.mxchange.addressbook.database.contact.ContactDatabaseConstants;
-import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.addressbook.manager.contact.ContactManager;
-import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
-import org.mxchange.jcore.database.storage.Storeable;
-import org.mxchange.jcore.exceptions.BadTokenException;
-import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
-
-/**
- * Stores and retrieves Contact instances
- *
- * @author Roland Haeder
- */
-public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactFrontend {
-
-       /**
-        * Constructor which accepts a contact manager
-        *
-        * @param manager Manager instance
-        */
-       public ContactDatabaseFrontend (final ContactManager manager) {
-               // Call own constructor
-               this();
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("manager={0} - CALLED!", manager)); //NOI18N
-
-               // Manager instance must not be null
-               if (manager == null) {
-                       // Abort here
-                       throw new NullPointerException("manager is null"); //NOI18N
-               }
-
-               // Set contact manager
-               this.setContactManager(manager);
-       }
-
-       /**
-        * Basic constrcutor
-        */
-       protected ContactDatabaseFrontend () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Set "table" name
-               this.setTableName("contacts"); //NOI18N
-
-               try {
-                       // Initalize backend
-                       this.initBackend();
-               } catch (final UnsupportedDatabaseBackendException ex) {
-                       // Abort program
-                       this.abortProgramWithException(ex);
-               } catch (final SQLException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               }
-       }
-
-       /**
-        * Adds given contact instance to database
-        *
-        * @param contact Contact instance
-        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact instance is already found
-        */
-       @Override
-       public void addContact (final Contact contact) throws ContactAlreadyAddedException {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Make sure the contact is set
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               try {
-                       // First check if the contact is there
-                       if (this.isContactFound(contact)) {
-                               // Already there
-                               throw new ContactAlreadyAddedException(contact);
-                       }
-
-                       // Then add it
-                       this.getBackend().store((Storeable) contact);
-               } catch (final IOException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               } catch (final BadTokenException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-       }
-
-       /**
-        * Shuts down the database layer
-        */
-       @Override
-       public void doShutdown () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Shutdown backend
-               this.getBackend().doShutdown();
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Some "getter" for total contact count
-        *
-        * @return Total contact count
-        */
-       @Override
-       public int getContactsCount () throws SQLException {
-               // And deligate to backend
-               return this.getBackend().getTotalCount(); //NOI18N
-       }
-
-       /**
-        * Some "getter" for own contact instance
-        *
-        * @return Own contact instance
-        */
-       @Override
-       public Contact getOwnContact () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get row index back from backend
-               int rowIndex = this.getBackend().getRowIndexFromColumn(ContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("rowIndex={0}", rowIndex));
-
-               // Init instance
-               Contact contact = null;
-
-               try {
-                       // Now simply read the row
-                       contact = (Contact) this.getBackend().readRow(rowIndex);
-               } catch (final BadTokenException ex) {
-                       // Bad token found
-                       this.abortProgramWithException(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact));
-
-               // Return it
-               return contact;
-       }
-
-       /**
-        * Checks if given Contact is found
-        * 
-        * @param contact Contact instance to check
-        * @return Whether the given Contact instance is found
-        */
-       @Override
-       public boolean isContactFound (final Contact contact) throws BadTokenException {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
-
-               // contact should not be null
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Default is not found
-               boolean isFound = false;
-
-               // Start iteration
-               Iterator<? extends Storeable> iterator = this.getBackend().iterator();
-
-               // Check all entries
-               while (iterator.hasNext()) {
-                       // Get next element
-                       Contact c = (Contact) iterator.next();
-
-                       // Debug message
-                       this.getLogger().debug(MessageFormat.format("c={0},contact={1}", c, contact)); //NOI18N
-
-                       // Is it added?
-                       if (c.equals(contact)) {
-                               // Is found
-                               isFound = true;
-                               break;
-                       }
-               }
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
-
-               // Return it
-               return isFound;
-       }
-
-       /**
-        * Checks whether own contact is found in database
-        *
-        * @return Whether own contact is found
-        */
-       @Override
-       public boolean isOwnContactFound () throws SQLException {
-               // Deligate this call to backend
-               return this.getBackend().isRowFound(ContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
-       }
-
-       /**
-        * Parses given line from database backend into a Storeable instance. Please
-        * note that not all backends need this.
-        *
-        * @param line Line from database backend
-        * @return A Storeable instance
-        */
-       @Override
-       public Storeable parseLineToStoreable (final String line) throws BadTokenException {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
-
-               // Call inner method
-               Contact contact = this.parseLineToContact(line);
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
-
-               // Return it
-               return (Storeable) contact;
-       }
-
-       /**
-        * Reads a single row and parses it to a contact instance
-        *
-        * @param rowIndex Row index (also how much to skip)
-        * @return Contact instance
-        */
-       @Override
-       public Contact readSingleContact (final int rowIndex) {
-               try {
-                       // Deligate this to backend instance
-                       return (Contact) this.getBackend().readRow(rowIndex);
-               } catch (final BadTokenException ex) {
-                       // Bad token found
-                       this.abortProgramWithException(ex);
-               }
-
-               // Bad state, should not be reached
-               throw new IllegalStateException("This should not be reached");
-       }
-
-       /**
-        * Parses given line and creates a Contact instance
-        * 
-        * @param line Raw line to parse
-        *
-        * @return Contact instance
-        */
-       private Contact parseLineToContact (final String line) throws BadTokenException {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
-
-               // Init A lot variables
-               Long num = null;
-               Boolean bool = null;
-               Gender gender = null;
-               int count = 0;
-               Contact contact = null;
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N
-
-               // Then tokenize it
-               // @TODO Move this into separate method
-               StringTokenizer tokenizer = new StringTokenizer(line, ";"); //NOI18N
-
-               // Reset variables
-               count = 0;
-               contact = null;
-
-               // The tokens are now available, so get all
-               while (tokenizer.hasMoreElements()) {
-                       // Reset variables
-                       num = null;
-                       bool = null;
-
-                       // Get next token
-                       String token = tokenizer.nextToken();
-
-                       // If char " is at pos 2 (0,1,2), then cut it of there
-                       if ((token.charAt(0) != '"') && (token.charAt(2) == '"')) {
-                               // UTF-8 writer characters found
-                               token = token.substring(2);
-                       }
-
-                       // Debug message
-                       this.getLogger().debug(MessageFormat.format("token={0}", token)); //NOI18N
-
-                       // Verify token, it must have double-quotes on each side
-                       if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { //NOI18N
-                               // Something bad was read
-                               throw new BadTokenException(token, count); //NOI18N
-                       }
-
-                       // All fine, so remove it
-                       String strippedToken = token.substring(1, token.length() - 1);
-
-                       // Is the string's content "null"?
-                       if (strippedToken.equals("null")) { //NOI18N
-                               // Debug message
-                               this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken)); //NOI18N
-
-                               // This needs to be set to null
-                               strippedToken = null;
-                       }
-
-                       // Debug message
-                       this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken)); //NOI18N
-
-                       // Now, let's try a number check, if no null
-                       if (strippedToken != null) {
-                               // Okay, no null, maybe the string bears a decimal number?
-                               try {
-                                       num = Long.valueOf(strippedToken);
-
-                                       // Debug message
-                                       this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); //NOI18N
-                               } catch (final NumberFormatException ex) {
-                                       // No number, then set default
-                                       num = null;
-                               }
-                       }
-
-                       // Now, let's try a boolean check, if no null
-                       if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { //NOI18N
-                               // Debug message
-                               this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken)); //NOI18N
-
-                               // parseBoolean() is relaxed, so no exceptions
-                               bool = Boolean.valueOf(strippedToken);
-                       }
-
-                       // Debug message
-                       this.getLogger().debug(MessageFormat.format("strippedToken={0},num={1},bool={2}", strippedToken, num, bool)); //NOI18N
-
-                       // Now, let's try a gender check, if no null
-                       if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) { //NOI18N
-                               // Get first character
-                               gender = Gender.fromChar(strippedToken.charAt(0));
-
-                               // Debug message
-                               this.getLogger().debug(MessageFormat.format("strippedToken={0},gender={1}", strippedToken, gender)); //NOI18N
-
-                               // This instance must be there
-                               assert (gender instanceof Gender) : MessageFormat.format("gender is not set by Gender.fromChar({0})", strippedToken); //NOI18N
-                       }
-
-                       // Now it depends on the counter which position we need to check
-                       switch (count) {
-                               case 0: // isOwnContact
-                                       assert ((bool instanceof Boolean));
-
-                                       // Debug message
-                                       this.getLogger().debug(MessageFormat.format("bool={0}", bool)); //NOI18N
-
-                                       // Is it own contact?
-                                       if (true == bool) {
-                                               // Debug message
-                                               this.getLogger().debug("Creating UserContact object ..."); //NOI18N
-
-                                               // Own entry
-                                               contact = new UserContact();
-                                       } else {
-                                               // Debug message
-                                               this.getLogger().debug("Creating BookContact object ..."); //NOI18N
-
-                                               // Other contact
-                                               contact = new BookContact();
-                                       }
-                                       break;
-
-                               case 1: // Gender
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setGender(gender);
-                                       break;
-
-                               case 2: // Surname
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
-
-                                       // Update data
-                                       contact.setSurname(strippedToken);
-                                       break;
-
-                               case 3: // Family name
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
-
-                                       // Update data
-                                       contact.setFamilyName(strippedToken);
-                                       break;
-
-                               case 4: // Company name
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-                                       assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N
-
-                                       // Update data
-                                       contact.setCompanyName(strippedToken);
-                                       break;
-
-                               case 5: // Street number
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setHouseNumber(num);
-                                       break;
-
-                               case 6: // ZIP code
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setZipCode(num);
-                                       break;
-
-                               case 7: // City name
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setCity(strippedToken);
-                                       break;
-
-                               case 8: // Country code
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setCountryCode(strippedToken);
-                                       break;
-
-                               case 9: // Phone number
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setPhoneNumber(strippedToken);
-                                       break;
-
-                               case 10: // Fax number
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setFaxNumber(strippedToken);
-                                       break;
-
-                               case 11: // Cellphone number
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setCellphoneNumber(strippedToken);
-                                       break;
-
-                               case 12: // Email address
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setEmailAddress(strippedToken);
-                                       break;
-
-                               case 13: // Birthday
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setBirthday(strippedToken);
-                                       break;
-
-                               case 14: // Comment
-                                       assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N
-
-                                       // Update data
-                                       contact.setComment(strippedToken);
-                                       break;
-
-                               default: // New data entry
-                                       this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); //NOI18N
-                                       break;
-                       }
-
-                       // Increment counter for next round
-                       count++;
-               }
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
-
-               // Return finished instance
-               return contact;
-       }
-}
diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactFrontend.java
deleted file mode 100644 (file)
index 0630391..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2015 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.database.frontend.contact;
-
-import java.sql.SQLException;
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.jcore.database.frontend.DatabaseFrontend;
-import org.mxchange.jcore.exceptions.BadTokenException;
-
-/**
- *
- * @author Roland Häder
- */
-public interface ContactFrontend extends DatabaseFrontend {
-
-       /**
-        * Adds given contact instance to database
-        *
-        * @param contact Contact instance to add
-        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact is already added
-        */
-       public void addContact (final Contact contact) throws ContactAlreadyAddedException;
-
-       /**
-        * Shuts down the database layer
-        */
-       public void doShutdown ();
-
-       /**
-        * Some "getter" for total contacts count
-        *
-        * @return Total contacts count
-        * @throws java.sql.SQLException If any SQL error occurs
-        */
-       public int getContactsCount () throws SQLException;
-
-       /**
-        * Checks if given Contact is found
-        * 
-        * @param contact Contact instance to check
-        * @return Whether the given Contact instance is found
-        * @throws org.mxchange.jcore.exceptions.BadTokenException Continued throw
-        */
-       public boolean isContactFound (final Contact contact) throws BadTokenException;
-
-       /**
-        * Some "getter" for own contact instance
-        *
-        * @return Own contact instance
-        */
-       public Contact getOwnContact ();
-
-       /**
-        * Checks whether own contact is found
-        * 
-        * @return Whether own contact is found
-        * @throws java.sql.SQLException If any SQL error occurs
-        */
-       public boolean isOwnContactFound () throws SQLException;
-
-       /**
-        * Reads a single row and parses it to a contact instance
-        *
-        * @param rowIndex Row index (also how much to skip)
-        * @return Contact instance
-        */
-       public Contact readSingleContact (final int rowIndex);
-}
diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/AddressbookContactManager.java
new file mode 100644 (file)
index 0000000..b85e9d3
--- /dev/null
@@ -0,0 +1,792 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.manager.contact;
+
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import org.mxchange.addressbook.client.AddressbookClient;
+import org.mxchange.addressbook.database.frontend.contact.AddressbookContactDatabaseFrontend;
+import org.mxchange.addressbook.database.frontend.contact.AddressbookContactFrontend;
+import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.exceptions.BadTokenException;
+import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
+import org.mxchange.jcore.manager.BaseManager;
+
+/**
+ * A manager for contacts.
+ *
+ * @author Roland Haeder
+ * @version 0.0
+ */
+public class AddressbookContactManager extends BaseManager implements ManageableAddressbookContact {
+
+       /**
+        * Column name list
+        */
+       private final List<String> columnNames;
+
+       /**
+        * A AddressbookContactFrontend instance
+        */
+       private final AddressbookContactFrontend contactDatabase;
+
+       /**
+        * Translated column name list
+        */
+       private final List<String> translatedColumnNames;
+
+       /**
+        * Constructor which accepts maxContacts for maximum (initial) contacts and
+        * a client instance.
+        *
+        * @param client Client instance to use
+        */
+       public AddressbookContactManager (final Client client) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
+
+               // Make sure all parameters are set correctly
+               if (client == null) {
+                       // Abort here
+                       throw new NullPointerException("client is null"); //NOI18N
+               }
+
+               // Set client instance
+               this.setClient(client);
+
+               // Init database connection
+               this.contactDatabase = new AddressbookContactDatabaseFrontend(this);
+
+               // Initialize list
+               this.columnNames = new ArrayList<>(15);
+               this.translatedColumnNames = new ArrayList<>(15);
+
+               // And fill it
+               this.fillColumnNamesFromBundle();
+
+               // Debug message
+               //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
+       }
+
+       /**
+        * Adds given Contact instance to list
+        *
+        * @param contact Contact instance to add
+        */
+       @Override
+       public void addContact (final Contact contact)  throws ContactAlreadyAddedException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+
+               // Contact instance must not be null
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Add it
+               this.getContactDatabase().addContact(contact);
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Let the user add a new other address
+        */
+       @Override
+       public void doAddOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+       }
+
+       /**
+        * Let the user change address data
+        *
+        * @param contact Instance to change data
+        */
+       @Override
+       public void doChangeAddressData (final Contact contact) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+
+               // Contact must not be null
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               // First display it again
+               client.displayAddressBox(contact);
+
+               // Is it own data?
+               if (contact.isOwnContact()) {
+                       // Deligate to client
+                       client.doChangeOwnAddressData(contact);
+               } else {
+                       // Other contact's address data to change
+                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Let the user change "name data"
+        *
+        * @param contact Instance to change data
+        */
+       @Override
+       public void doChangeNameData (final Contact contact) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+
+               // Contact must not be null
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               // First display them again
+               client.displayNameBox(contact);
+
+               // Is this own data?
+               if (contact.isOwnContact()) {
+                       // Re-ask own data
+                       client.doChangeOwnNameData(contact);
+               } else {
+                       // Then re-ask them ...
+                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Let the user change other address
+        */
+       @Override
+       public void doChangeOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+       }
+
+       /**
+        * Let the user change other data
+        *
+        * @param contact Instance to change data
+        * @todo Didn't handle birthday
+        */
+       @Override
+       public void doChangeOtherData (final Contact contact) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+
+               // Contact must not be null
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               // First display them again
+               client.displayOtherDataBox(contact);
+
+               // Is this own data?
+               if (contact.isOwnContact()) {
+                       // Re-ask own data
+                       client.doChangeOwnOtherData(contact);
+               } else {
+                       // Then re-ask them ...
+                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Allows the user to change his/her own data
+        */
+       @Override
+       public void doChangeOwnData () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               /*
+                * First check if the user has registered own contact, before that
+                * nothing can be changed.
+                */
+               if (!this.isOwnContactAdded()) {
+                       // Not added
+                       this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben."); //NOI18N
+
+                       // Skip any below code
+                       return;
+               }
+
+               // Instance
+               Contact contact = this.getOwnContact();
+
+               // It must be found
+               assert (contact instanceof Contact);
+
+               // Display contact
+               contact.show(this.getClient());
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               try {
+                       // Ask user what to change
+                       client.userChooseChangeContactData(contact);
+               } catch (final UnhandledUserChoiceException ex) {
+                       this.getLogger().catching(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Let the user delete other address
+        */
+       @Override
+       public void doDeleteOtherAddress () {
+               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+       }
+
+       /**
+        * Asks user for own data
+        */
+       @Override
+       public void doEnterOwnData () throws ContactAlreadyAddedException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Is own contact already added?
+               if (this.isOwnContactAdded()) {
+                       // Don't continue here
+                       throw new ContactAlreadyAddedException();
+               }
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               // Deligate this call to the client
+               Contact contact = client.doEnterOwnData();
+
+               // Is it set?
+               if (contact instanceof Contact) {
+                       // Add it to contact "book"
+                       this.registerContact(contact);
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       @Override
+       public void doListContacts () {
+               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+       }
+
+       @Override
+       public void doSearchContacts () {
+               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+       }
+
+       /**
+        * Shuts down this contact manager
+        */
+       @Override
+       public void doShutdown () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Shut down the database layer
+               this.getContactDatabase().doShutdown();
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Asks the user for his/her cellphone number
+        *
+        * @return User's cellphone number
+        */
+       @Override
+       public String enterOwnCellNumber () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);
+       }
+
+       /**
+        * Asks the user for his/her city's name
+        *
+        * @return City's name of the user
+        */
+       @Override
+       public String enterOwnCity () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
+       }
+
+       /**
+        * Asks the user for his/her city's name
+        *
+        * @return City's name of the user
+        */
+       @Override
+       public String enterOwnComment () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);
+       }
+
+       /**
+        * Asks the user for his/her company name
+        *
+        * @return User's company name
+        */
+       @Override
+       public String enterOwnCompanyName () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);
+       }
+
+       /**
+        * Asks user for his/her own country code
+        *
+        * @return User's own country code
+        */
+       @Override
+       public String enterOwnCountryCode () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();
+       }
+
+       /**
+        * Asks user for his/her own country code
+        *
+        * @return User's own country code
+        */
+       @Override
+       public String enterOwnEmailAddress () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);
+       }
+
+       /**
+        * Asks the user for family name
+        *
+        * @return Family name of the user
+        */
+       @Override
+       public String enterOwnFamilyName () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);
+       }
+
+       /**
+        * Asks the user for family name
+        *
+        * @return Family name of the user
+        */
+       @Override
+       public String enterOwnFaxNumber () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
+       }
+
+       /**
+        * Asks the user for gender, until a valid has been entered
+        *
+        * @return Gender of the user
+        */
+       @Override
+       public Gender enterOwnGender () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
+       }
+
+       /**
+        * Asks the user for phone number
+        *
+        * @return Phone number of the user
+        */
+       @Override
+       public String enterOwnPhoneNumber () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);
+       }
+
+       /**
+        * Asks the user for own street (including number)
+        *
+        * @return Own street an number
+        */
+       @Override
+       public String enterOwnStreet () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
+       }
+
+       /**
+        * Asks the user for surname
+        *
+        * @return Surname of the user
+        */
+       @Override
+       public String enterOwnSurname () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
+       }
+
+       /**
+        * Asks the user for own ZIP code
+        *
+        * @return ZIP code
+        */
+       @Override
+       public int enterOwnZipCode () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Get and cast client instance
+               AddressbookClient client = (AddressbookClient) this.getClient();
+
+               return client.enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");
+       }
+
+       @Override
+       public final int getColumnCount () {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
+
+               return this.columnNames.size();
+       }
+
+       /**
+        * Getter for column name at given index.
+        *
+        * @param columnIndex Column index
+        * @return Database column name
+        */
+       @Override
+       public String getColumnName (final int columnIndex) {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
+
+               // Get column name at index
+               return this.columnNames.get(columnIndex);
+       }
+
+       /**
+        * Getter for translated column name at given index.
+        *
+        * @param columnIndex Column index
+        * @return Human-readable column name
+        */
+       @Override
+       public String getTranslatedColumnName (final int columnIndex) {
+               assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
+
+               // Get column name at index
+               return this.translatedColumnNames.get(columnIndex);
+       }
+
+       /**
+        * Somewhat "getter" for value from given row and column index
+        *
+        * @param rowIndex Row index
+        * @param columnIndex Column index
+        * @return Value from given row/column
+        */
+       @Override
+       public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex));
+
+               // Then get specific row from database which is a Contact instance
+               Contact contact = this.getContactDatabase().readSingleContact(rowIndex);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
+
+               // It may return null
+               if (contact == null) {
+                       // Nothing found
+                       this.getLogger().warn("contact is null - returning null ...");
+                       return null;
+               }
+
+               // Convert column index -> name
+               String columnName = this.getColumnName(columnIndex);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("columnName={0}", columnName));
+
+               // Now get that column
+               Object value = contact.getValueFromColumn(columnName);
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value));
+
+               // Return it
+               return value;
+       }
+
+       /**
+        * Checks whether own contact is already added by checking all entries for
+        * isOwnContact flag
+        *
+        * @return Whether own contact is already added
+        */
+       @Override
+       public boolean isOwnContactAdded () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Init variable
+               boolean isAdded = false;
+
+               try {
+                       // Deligate this call to frontend
+                       isAdded = this.getContactDatabase().isOwnContactFound();
+               } catch (final SQLException ex) {
+                       // Something bad happened
+                       this.abortProgramWithException(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
+
+               // Return result
+               return isAdded;
+       }
+
+       /**
+        * Adds given contact to address book and flushes all entries to database
+        *
+        * @param contact Contact being added
+        * @todo Add check for book size
+        */
+       @Override
+       public void registerContact (final Contact contact) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+
+               // Sanity check
+               if (contact == null) {
+                       // Abort here
+                       throw new NullPointerException("contact is null"); //NOI18N
+               }
+
+               // Debug message
+               /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); //NOI18N
+               try {
+                       // Check if contact is found
+                       if (this.getContactDatabase().isContactFound(contact)) {
+                               // Contact already added
+                               // @todo Do something here
+                       } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
+                               // Own contact already added
+                               // @todo Do something
+                       }
+
+                       // Add contact to internal list
+                       this.addContact(contact);
+               } catch (final ContactAlreadyAddedException ex) {
+                       // Abort here
+                       this.abortProgramWithException(ex);
+               } catch (final BadTokenException ex) {
+                       // Abort here
+                       this.abortProgramWithException(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+
+       /**
+        * Getter for size
+        *
+        * @return size of contact "book"
+        */
+       @Override
+       public final int size () {
+               // Init size
+               int size = -1;
+
+               try {
+                       size = this.getContactDatabase().getContactsCount();
+               } catch (final SQLException ex) {
+                       // Something happened
+                       this.abortProgramWithException(ex);
+               }
+
+               // Return amount
+               return size;
+       }
+
+       /**
+        * Fills the column names array with strings from bundle
+        */
+       private void fillColumnNamesFromBundle () {
+               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
+               assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
+
+               // Debug message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // First get an iterator from key set to iterate over
+               Iterator<String> iterator = this.getBundle().keySet().iterator();
+
+               // Then iterate over all
+               while (iterator.hasNext()) {
+                       // Get next element
+                       String key = iterator.next();
+
+                       // Does the key start with AddressbookContactManager.columnName ?
+                       if (key.startsWith("ContactManager.columnName")) { //NOI18N
+                               // This is the wanted entry.
+                               this.getLogger().debug(MessageFormat.format("key={0}", key)); //NOI18N
+
+                               // Convert string to array based on delimiter '.'
+                               String[] tokens = this.getArrayFromString(key, ".", 4);
+
+                               // Token array must contain 4 elements (AddressbookContactManager.columnName.foo.text)
+                               assert(tokens.length == 4) : MessageFormat.format("Array tokens contains not 4 elements: {0}", Arrays.toString(tokens));
+
+                               // Get pre-last element
+                               String columnName = tokens[tokens.length - 2];
+
+                               // Debug message
+                               this.getLogger().debug(MessageFormat.format("columnName={0} - adding ...", columnName));
+
+                               // So add it
+                               this.columnNames.add(columnName);
+                               this.translatedColumnNames.add(this.getBundle().getString(key));
+                       }
+               }
+
+               // Debug message
+               this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
+       }
+
+       /**
+        * A AddressbookContactFrontend instance
+        *
+        * @return the database
+        */
+       private AddressbookContactFrontend getContactDatabase () {
+               return this.contactDatabase;
+       }
+
+       /**
+        * "Getter" for own contact instance or null if not found
+        *
+        * @return Contact instance or null
+        */
+       private Contact getOwnContact () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Deligate this call to database frontend
+               Contact contact = this.getContactDatabase().getOwnContact();
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
+
+               // Return instance or null
+               return contact;
+       }
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java
deleted file mode 100644 (file)
index 3ab62fc..0000000
+++ /dev/null
@@ -1,793 +0,0 @@
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.manager.contact;
-
-import java.sql.SQLException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import org.mxchange.addressbook.client.AddressbookClient;
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.jcore.contact.Gender;
-import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend;
-import org.mxchange.addressbook.database.frontend.contact.ContactFrontend;
-import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.jcore.client.Client;
-import org.mxchange.jcore.exceptions.BadTokenException;
-import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
-import org.mxchange.jcore.manager.BaseManager;
-
-/**
- * A manager for contacts, please note that this implementation loads the whole
- * list into RAM.
- *
- * @author Roland Haeder
- * @version 0.0
- */
-public class ContactManager extends BaseManager implements ManageableContact {
-
-       /**
-        * Column name list
-        */
-       private final List<String> columnNames;
-
-       /**
-        * Translated column name list
-        */
-       private final List<String> translatedColumnNames;
-
-       /**
-        * A ContactFrontend instance
-        */
-       private final ContactFrontend contactDatabase;
-
-       /**
-        * Constructor which accepts maxContacts for maximum (initial) contacts and
-        * a client instance.
-        *
-        * @param client Client instance to use
-        */
-       public ContactManager (final Client client) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
-
-               // Make sure all parameters are set correctly
-               if (client == null) {
-                       // Abort here
-                       throw new NullPointerException("client is null"); //NOI18N
-               }
-
-               // Set client instance
-               this.setClient(client);
-
-               // Init database connection
-               this.contactDatabase = new ContactDatabaseFrontend(this);
-
-               // Initialize list
-               this.columnNames = new ArrayList<>(15);
-               this.translatedColumnNames = new ArrayList<>(15);
-
-               // And fill it
-               this.fillColumnNamesFromBundle();
-
-               // Debug message
-               //* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);
-       }
-
-       /**
-        * Adds given Contact instance to list
-        *
-        * @param contact Contact instance to add
-        */
-       @Override
-       public void addContact (final Contact contact)  throws ContactAlreadyAddedException {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
-
-               // Contact instance must not be null
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Add it
-               this.getContactDatabase().addContact(contact);
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Let the user add a new other address
-        */
-       @Override
-       public void doAddOtherAddress () {
-               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
-       }
-
-       /**
-        * Let the user change address data
-        *
-        * @param contact Instance to change data
-        */
-       @Override
-       public void doChangeAddressData (final Contact contact) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
-
-               // Contact must not be null
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               // First display it again
-               client.displayAddressBox(contact);
-
-               // Is it own data?
-               if (contact.isOwnContact()) {
-                       // Deligate to client
-                       client.doChangeOwnAddressData(contact);
-               } else {
-                       // Other contact's address data to change
-                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Let the user change "name data"
-        *
-        * @param contact Instance to change data
-        */
-       @Override
-       public void doChangeNameData (final Contact contact) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
-
-               // Contact must not be null
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               // First display them again
-               client.displayNameBox(contact);
-
-               // Is this own data?
-               if (contact.isOwnContact()) {
-                       // Re-ask own data
-                       client.doChangeOwnNameData(contact);
-               } else {
-                       // Then re-ask them ...
-                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Let the user change other address
-        */
-       @Override
-       public void doChangeOtherAddress () {
-               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
-       }
-
-       /**
-        * Let the user change other data
-        *
-        * @param contact Instance to change data
-        * @todo Didn't handle birthday
-        */
-       @Override
-       public void doChangeOtherData (final Contact contact) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
-
-               // Contact must not be null
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               // First display them again
-               client.displayOtherDataBox(contact);
-
-               // Is this own data?
-               if (contact.isOwnContact()) {
-                       // Re-ask own data
-                       client.doChangeOwnOtherData(contact);
-               } else {
-                       // Then re-ask them ...
-                       throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Allows the user to change his/her own data
-        */
-       @Override
-       public void doChangeOwnData () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               /*
-                * First check if the user has registered own contact, before that
-                * nothing can be changed.
-                */
-               if (!this.isOwnContactAdded()) {
-                       // Not added
-                       this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben."); //NOI18N
-
-                       // Skip any below code
-                       return;
-               }
-
-               // Instance
-               Contact contact = this.getOwnContact();
-
-               // It must be found
-               assert (contact instanceof Contact);
-
-               // Display contact
-               contact.show(this.getClient());
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               try {
-                       // Ask user what to change
-                       client.userChooseChangeContactData(contact);
-               } catch (final UnhandledUserChoiceException ex) {
-                       this.getLogger().catching(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Let the user delete other address
-        */
-       @Override
-       public void doDeleteOtherAddress () {
-               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
-       }
-
-       /**
-        * Asks user for own data
-        */
-       @Override
-       public void doEnterOwnData () throws ContactAlreadyAddedException {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Is own contact already added?
-               if (this.isOwnContactAdded()) {
-                       // Don't continue here
-                       throw new ContactAlreadyAddedException();
-               }
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               // Deligate this call to the client
-               Contact contact = client.doEnterOwnData();
-
-               // Is it set?
-               if (contact instanceof Contact) {
-                       // Add it to contact "book"
-                       this.registerContact(contact);
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       @Override
-       public void doListContacts () {
-               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
-       }
-
-       @Override
-       public void doSearchContacts () {
-               throw new UnsupportedOperationException("Not supported yet."); //NOI18N
-       }
-
-       /**
-        * Shuts down this contact manager
-        */
-       @Override
-       public void doShutdown () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Shut down the database layer
-               this.getContactDatabase().doShutdown();
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Asks the user for his/her cellphone number
-        *
-        * @return User's cellphone number
-        */
-       @Override
-       public String enterOwnCellNumber () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);
-       }
-
-       /**
-        * Asks the user for his/her city's name
-        *
-        * @return City's name of the user
-        */
-       @Override
-       public String enterOwnCity () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);
-       }
-
-       /**
-        * Asks the user for his/her city's name
-        *
-        * @return City's name of the user
-        */
-       @Override
-       public String enterOwnComment () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);
-       }
-
-       /**
-        * Asks the user for his/her company name
-        *
-        * @return User's company name
-        */
-       @Override
-       public String enterOwnCompanyName () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);
-       }
-
-       /**
-        * Asks user for his/her own country code
-        *
-        * @return User's own country code
-        */
-       @Override
-       public String enterOwnCountryCode () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();
-       }
-
-       /**
-        * Asks user for his/her own country code
-        *
-        * @return User's own country code
-        */
-       @Override
-       public String enterOwnEmailAddress () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);
-       }
-
-       /**
-        * Asks the user for family name
-        *
-        * @return Family name of the user
-        */
-       @Override
-       public String enterOwnFamilyName () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);
-       }
-
-       /**
-        * Asks the user for family name
-        *
-        * @return Family name of the user
-        */
-       @Override
-       public String enterOwnFaxNumber () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);
-       }
-
-       /**
-        * Asks the user for gender, until a valid has been entered
-        *
-        * @return Gender of the user
-        */
-       @Override
-       public Gender enterOwnGender () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
-       }
-
-       /**
-        * Asks the user for phone number
-        *
-        * @return Phone number of the user
-        */
-       @Override
-       public String enterOwnPhoneNumber () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);
-       }
-
-       /**
-        * Asks the user for own street (including number)
-        *
-        * @return Own street an number
-        */
-       @Override
-       public String enterOwnStreet () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false);
-       }
-
-       /**
-        * Asks the user for surname
-        *
-        * @return Surname of the user
-        */
-       @Override
-       public String enterOwnSurname () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);
-       }
-
-       /**
-        * Asks the user for own ZIP code
-        *
-        * @return ZIP code
-        */
-       @Override
-       public int enterOwnZipCode () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Get and cast client instance
-               AddressbookClient client = (AddressbookClient) this.getClient();
-
-               return client.enterInt(0, 99_999, "Bitte geben Sie Ihre Postleitzahl ein: ");
-       }
-
-       @Override
-       public final int getColumnCount () {
-               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
-
-               return this.columnNames.size();
-       }
-
-       /**
-        * Getter for column name at given index.
-        *
-        * @param columnIndex Column index
-        * @return Database column name
-        */
-       @Override
-       public String getColumnName (final int columnIndex) {
-               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
-
-               // Get column name at index
-               return this.columnNames.get(columnIndex);
-       }
-
-       /**
-        * Getter for translated column name at given index.
-        *
-        * @param columnIndex Column index
-        * @return Human-readable column name
-        */
-       @Override
-       public String getTranslatedColumnName (final int columnIndex) {
-               assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
-
-               // Get column name at index
-               return this.translatedColumnNames.get(columnIndex);
-       }
-
-       /**
-        * Somewhat "getter" for value from given row and column index
-        *
-        * @param rowIndex Row index
-        * @param columnIndex Column index
-        * @return Value from given row/column
-        */
-       @Override
-       public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex));
-
-               // Then get specific row from database which is a Contact instance
-               Contact contact = this.getContactDatabase().readSingleContact(rowIndex);
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("contact={0}", contact));
-
-               // It may return null
-               if (contact == null) {
-                       // Nothing found
-                       this.getLogger().warn("contact is null - returning null ...");
-                       return null;
-               }
-
-               // Convert column index -> name
-               String columnName = this.getColumnName(columnIndex);
-
-               // Debug message
-               this.getLogger().debug(MessageFormat.format("columnName={0}", columnName));
-
-               // Now get that column
-               Object value = contact.getValueFromColumn(columnName);
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value));
-
-               // Return it
-               return value;
-       }
-
-       /**
-        * Checks whether own contact is already added by checking all entries for
-        * isOwnContact flag
-        *
-        * @return Whether own contact is already added
-        */
-       @Override
-       public boolean isOwnContactAdded () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Init variable
-               boolean isAdded = false;
-
-               try {
-                       // Deligate this call to frontend
-                       isAdded = this.getContactDatabase().isOwnContactFound();
-               } catch (final SQLException ex) {
-                       // Something bad happened
-                       this.abortProgramWithException(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
-
-               // Return result
-               return isAdded;
-       }
-
-       /**
-        * Adds given contact to address book and flushes all entries to database
-        *
-        * @param contact Contact being added
-        * @todo Add check for book size
-        */
-       @Override
-       public void registerContact (final Contact contact) {
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
-
-               // Sanity check
-               if (contact == null) {
-                       // Abort here
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Debug message
-               /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); //NOI18N
-               try {
-                       // Check if contact is found
-                       if (this.getContactDatabase().isContactFound(contact)) {
-                               // Contact already added
-                               // @todo Do something here
-                       } else if ((contact.isOwnContact()) && (this.isOwnContactAdded())) {
-                               // Own contact already added
-                               // @todo Do something
-                       }
-
-                       // Add contact to internal list
-                       this.addContact(contact);
-               } catch (final ContactAlreadyAddedException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               } catch (final BadTokenException ex) {
-                       // Abort here
-                       this.abortProgramWithException(ex);
-               }
-
-               // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
-       }
-
-       /**
-        * Getter for size
-        *
-        * @return size of contact "book"
-        */
-       @Override
-       public final int size () {
-               // Init size
-               int size = -1;
-
-               try {
-                       size = this.getContactDatabase().getContactsCount();
-               } catch (final SQLException ex) {
-                       // Something happened
-                       this.abortProgramWithException(ex);
-               }
-
-               // Return amount
-               return size;
-       }
-
-       /**
-        * Fills the column names array with strings from bundle
-        */
-       private void fillColumnNamesFromBundle () {
-               assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N
-               assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
-
-               // Debug message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // First get an iterator from key set to iterate over
-               Iterator<String> iterator = this.getBundle().keySet().iterator();
-
-               // Then iterate over all
-               while (iterator.hasNext()) {
-                       // Get next element
-                       String key = iterator.next();
-
-                       // Does the key start with ContactManager.columnName ?
-                       if (key.startsWith("ContactManager.columnName")) { //NOI18N
-                               // This is the wanted entry.
-                               this.getLogger().debug(MessageFormat.format("key={0}", key)); //NOI18N
-
-                               // Convert string to array based on delimiter '.'
-                               String[] tokens = this.getArrayFromString(key, ".", 4);
-
-                               // Token array must contain 4 elements (ContactManager.columnName.foo.text)
-                               assert(tokens.length == 4) : MessageFormat.format("Array tokens contains not 4 elements: {0}", Arrays.toString(tokens));
-
-                               // Get pre-last element
-                               String columnName = tokens[tokens.length - 2];
-
-                               // Debug message
-                               this.getLogger().debug(MessageFormat.format("columnName={0} - adding ...", columnName));
-
-                               // So add it
-                               this.columnNames.add(columnName);
-                               this.translatedColumnNames.add(this.getBundle().getString(key));
-                       }
-               }
-
-               // Debug message
-               this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
-       }
-
-       /**
-        * A ContactFrontend instance
-        *
-        * @return the database
-        */
-       private ContactFrontend getContactDatabase () {
-               return this.contactDatabase;
-       }
-
-       /**
-        * "Getter" for own contact instance or null if not found
-        *
-        * @return Contact instance or null
-        */
-       private Contact getOwnContact () {
-               // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
-
-               // Deligate this call to database frontend
-               Contact contact = this.getContactDatabase().getOwnContact();
-
-               // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
-
-               // Return instance or null
-               return contact;
-       }
-}
diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableAddressbookContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableAddressbookContact.java
new file mode 100644 (file)
index 0000000..6511730
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.manager.contact;
+
+import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcore.contact.Contact;
+import org.mxchange.jcore.contact.Gender;
+import org.mxchange.jcore.manager.database.ManageableDatabase;
+
+/**
+ *
+ * @author Roland Haeder
+ */
+public interface ManageableAddressbookContact extends ManageableDatabase {
+       /**
+        * Allows the user to enter own cellphone number.
+        *
+        * @return Cellphone number
+        */
+       public String enterOwnCellNumber ();
+
+       /**
+        * Allows the user to enter own city name.
+        *
+        * @return City name
+        */
+       public String enterOwnCity ();
+
+       /**
+        * Allows the user to enter comment for own entry.
+        *
+        * @return Comment
+        */
+       public String enterOwnComment ();
+
+       /**
+        * Allows the user to enter own company name.
+        *
+        * @return Company name
+        */
+       public String enterOwnCompanyName ();
+
+       /**
+        * Allows the user to enter own country code.
+        *
+        * @return Country code
+        */
+       public String enterOwnCountryCode ();
+
+       /**
+        * Allows the user to enter own email address.
+        *
+        * @return Email address
+        */
+       public String enterOwnEmailAddress ();
+
+       /**
+        * Allows the user to enter own family name.
+        *
+        * @return Family name
+        */
+       public String enterOwnFamilyName ();
+
+       /**
+        * Allows the user to enter own fax number.
+        *
+        * @return Fax number
+        */
+       public String enterOwnFaxNumber ();
+
+       /**
+        * Allows the user to enter own gender.
+        *
+        * @return Gender
+        */
+       public Gender enterOwnGender ();
+
+       /**
+        * Allows the user to enter own phone number.
+        *
+        * @return Phone number
+        */
+       public String enterOwnPhoneNumber ();
+
+       /**
+        * Allows the user to enter own street and house number.
+        *
+        * @return Street and house number
+        */
+       public String enterOwnStreet ();
+
+       /**
+        * Allows the user to enter own surname.
+        *
+        * @return Surname
+        */
+       public String enterOwnSurname ();
+
+       /**
+        * Allows the user to enter own ZIP code.
+        *
+        * @return ZIP code
+        */
+       public int enterOwnZipCode ();
+
+       /**
+        * List all contacts
+        */
+       public void doListContacts ();
+
+       /**
+        * Adds given contact to address book
+        *
+        * @param contact Contact being added
+        * @todo Add check for book size
+        */
+       public void registerContact (final Contact contact);
+
+       /**
+        * Adds given Contact instance to list
+        *
+        * @param contact Contact instance to add
+        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact is already added
+        */
+       public void addContact (final Contact contact) throws ContactAlreadyAddedException;
+
+       /**
+        * Let the user add a new other address
+        */
+       public void doAddOtherAddress ();
+
+       /**
+        * The user can change address data, like street, ZIP code, city and country
+        * of given Contact instance.
+        *
+        * @param contact Instance to change data
+        */
+       public void doChangeAddressData (final Contact contact);
+
+       /**
+        * The user can change name data, like gender, surname, family name and
+        * company name (if business contact).
+        *
+        * @param contact Instance to change data
+        */
+       public void doChangeNameData (final Contact contact);
+
+       /**
+        * Let the user change other address
+        */
+       public void doChangeOtherAddress ();
+
+       /**
+        * The user can change other data, like phone numbers or comments.
+        *
+        * @param contact Instance to change data
+        */
+       public void doChangeOtherData (final Contact contact);
+
+       /**
+        * Let the user change own data
+        */
+       public void doChangeOwnData ();
+
+       /**
+        * Let the user delete other address
+        */
+       public void doDeleteOtherAddress ();
+
+       /**
+        * Asks user for own data
+        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If own contact is already added
+        */
+       public void doEnterOwnData () throws ContactAlreadyAddedException;
+
+       /**
+        * Searches address book for a contact
+        */
+       public void doSearchContacts ();
+
+       /**
+        * Checks whether own contact is already added by checking all entries for
+        * isOwnContact flag
+        *
+        * @return Whether own contact is already added
+        */
+       public boolean isOwnContactAdded ();
+}
diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java
deleted file mode 100644 (file)
index 277ae35..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.manager.contact;
-
-import org.mxchange.jcore.contact.Contact;
-import org.mxchange.jcore.contact.Gender;
-import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
-import org.mxchange.jcore.manager.Manageable;
-
-/**
- *
- * @author Roland Haeder
- */
-public interface ManageableContact extends Manageable {
-       /**
-        * Allows the user to enter own cellphone number.
-        *
-        * @return Cellphone number
-        */
-       public String enterOwnCellNumber ();
-
-       /**
-        * Allows the user to enter own city name.
-        *
-        * @return City name
-        */
-       public String enterOwnCity ();
-
-       /**
-        * Allows the user to enter comment for own entry.
-        *
-        * @return Comment
-        */
-       public String enterOwnComment ();
-
-       /**
-        * Allows the user to enter own company name.
-        *
-        * @return Company name
-        */
-       public String enterOwnCompanyName ();
-
-       /**
-        * Allows the user to enter own country code.
-        *
-        * @return Country code
-        */
-       public String enterOwnCountryCode ();
-
-       /**
-        * Allows the user to enter own email address.
-        *
-        * @return Email address
-        */
-       public String enterOwnEmailAddress ();
-
-       /**
-        * Allows the user to enter own family name.
-        *
-        * @return Family name
-        */
-       public String enterOwnFamilyName ();
-
-       /**
-        * Allows the user to enter own fax number.
-        *
-        * @return Fax number
-        */
-       public String enterOwnFaxNumber ();
-
-       /**
-        * Allows the user to enter own gender.
-        *
-        * @return Gender
-        */
-       public Gender enterOwnGender ();
-
-       /**
-        * Allows the user to enter own phone number.
-        *
-        * @return Phone number
-        */
-       public String enterOwnPhoneNumber ();
-
-       /**
-        * Allows the user to enter own street and house number.
-        *
-        * @return Street and house number
-        */
-       public String enterOwnStreet ();
-
-       /**
-        * Allows the user to enter own surname.
-        *
-        * @return Surname
-        */
-       public String enterOwnSurname ();
-
-       /**
-        * Allows the user to enter own ZIP code.
-        *
-        * @return ZIP code
-        */
-       public int enterOwnZipCode ();
-
-       /**
-        * Getter for column count
-        *
-        * @return Column count
-        */
-       public int getColumnCount ();
-
-       /**
-        * List all contacts
-        */
-       public void doListContacts ();
-
-       /**
-        * Getter for column name at given index.
-        *
-        * @param columnIndex Column index
-        * @return Database column name
-        */
-       public String getColumnName (final int columnIndex);
-
-       /**
-        * Getter for translated column name at given index.
-        *
-        * @param columnIndex Column index
-        * @return Human-readable column name
-        */
-       public String getTranslatedColumnName (int columnIndex);
-
-       /**
-        * Somewhat "getter" for value from given row and column index
-        *
-        * @param rowIndex Row index
-        * @param columnIndex Column index
-        * @return Value from given row/column
-        */
-       public Object getValueFromRowColumn (final int rowIndex, final int columnIndex);
-
-       /**
-        * Adds given contact to address book
-        *
-        * @param contact Contact being added
-        * @todo Add check for book size
-        */
-       public void registerContact (final Contact contact);
-
-       /**
-        * Adds given Contact instance to list
-        *
-        * @param contact Contact instance to add
-        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If the contact is already added
-        */
-       public void addContact (final Contact contact) throws ContactAlreadyAddedException;
-
-       /**
-        * Let the user add a new other address
-        */
-       public void doAddOtherAddress ();
-
-       /**
-        * The user can change address data, like street, ZIP code, city and country
-        * of given Contact instance.
-        *
-        * @param contact Instance to change data
-        */
-       public void doChangeAddressData (final Contact contact);
-
-       /**
-        * The user can change name data, like gender, surname, family name and
-        * company name (if business contact).
-        *
-        * @param contact Instance to change data
-        */
-       public void doChangeNameData (final Contact contact);
-
-       /**
-        * Let the user change other address
-        */
-       public void doChangeOtherAddress ();
-
-       /**
-        * The user can change other data, like phone numbers or comments.
-        *
-        * @param contact Instance to change data
-        */
-       public void doChangeOtherData (final Contact contact);
-
-       /**
-        * Let the user change own data
-        */
-       public void doChangeOwnData ();
-
-       /**
-        * Let the user delete other address
-        */
-       public void doDeleteOtherAddress ();
-
-       /**
-        * Asks user for own data
-        * @throws org.mxchange.addressbook.exceptions.ContactAlreadyAddedException If own contact is already added
-        */
-       public void doEnterOwnData () throws ContactAlreadyAddedException;
-
-       /**
-        * Searches address book for a contact
-        */
-       public void doSearchContacts ();
-
-       /**
-        * Checks whether own contact is already added by checking all entries for
-        * isOwnContact flag
-        *
-        * @return Whether own contact is already added
-        */
-       public boolean isOwnContactAdded ();
-
-       /**
-        * Getter for size
-        *
-        * @return size of contact "book"
-        */
-       public int size ();
-}
index 5139c00d1d092d2cef5d4e79813d1ecff5f5ec33..965f68ab0a58a820f19cec3407745b906e0b4329 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.addressbook.menu.console;
 
 import java.text.MessageFormat;
-import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.addressbook.menu.AddressbookMenu;
 import org.mxchange.addressbook.menu.BaseMenu;
 import org.mxchange.addressbook.menu.Menu;
@@ -49,6 +48,6 @@ public class ConsoleMenu extends BaseMenu implements Menu {
                this.initMenu(menuType, client);
 
                // Add all items
-               AddressbookMenu.addItemsToList(this.getMenuList(), menuType, (AddressbookClient) client);
+               AddressbookMenu.addItemsToList(this.getMenuList(), menuType, client);
        }
 }
index 6c3b930fcb8f830ae77cf4277ede0649b4645167..5446a83db3af2cd31abbba5d924cb1e2447fa408 100644 (file)
@@ -18,8 +18,8 @@ package org.mxchange.addressbook.model.contact;
 
 import java.text.MessageFormat;
 import javax.swing.table.TableModel;
-import org.mxchange.addressbook.manager.contact.ManageableContact;
 import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.manager.database.ManageableDatabase;
 import org.mxchange.jcore.model.BaseModel;
 
 /**
@@ -57,7 +57,7 @@ public class ContactTableModel extends BaseModel implements TableModel {
        @Override
        public int getColumnCount () {
                // Get manager
-               ManageableContact manager = (ManageableContact) this.getClient().getManager();
+               ManageableDatabase manager = (ManageableDatabase) this.getClient().getManager();
 
                // Deligate this call to contact manager
                return manager.getColumnCount();
@@ -66,7 +66,7 @@ public class ContactTableModel extends BaseModel implements TableModel {
        @Override
        public String getColumnName (final int columnIndex) {
                // Get manager
-               ManageableContact manager = (ManageableContact) this.getClient().getManager();
+               ManageableDatabase manager = (ManageableDatabase) this.getClient().getManager();
 
                // Deligate this call to contact manager
                return manager.getTranslatedColumnName(columnIndex);
@@ -75,7 +75,7 @@ public class ContactTableModel extends BaseModel implements TableModel {
        @Override
        public int getRowCount () {
                // Get manager
-               ManageableContact manager = (ManageableContact) this.getClient().getManager();
+               ManageableDatabase manager = (ManageableDatabase) this.getClient().getManager();
 
                // Deligate this call to contact manager
                return manager.size();
@@ -84,7 +84,7 @@ public class ContactTableModel extends BaseModel implements TableModel {
        @Override
        public Object getValueAt (final int rowIndex, final int columnIndex) {
                // Get manager
-               ManageableContact manager = (ManageableContact) this.getClient().getManager();
+               ManageableDatabase manager = (ManageableDatabase) this.getClient().getManager();
 
                // Deligate this call to contact manager
                return manager.getValueFromRowColumn(rowIndex, columnIndex);