*/\r
private ManageableContact contactManager;\r
\r
+ /**\r
+ * Name of used database table, handled over to backend\r
+ */\r
+ private String tableName;\r
+\r
/**\r
* Initialize object\r
*/\r
\r
/**\r
* Application instance\r
+ * \r
* @return the application\r
*/\r
public Application getApplication () {\r
return this.application;\r
}\r
\r
- /**\r
- * Application instance\r
- * @param application the application to set\r
- */\r
- protected void setApplication (final Application application) {\r
- this.application = application;\r
- }\r
-\r
/**\r
* Client instance\r
+ * \r
* @return the client\r
*/\r
public Client getClient () {\r
return this.client;\r
}\r
\r
- /**\r
- * Client instance\r
- * @param client the client to set\r
- */\r
- protected void setClient (final Client client) {\r
- this.client = client;\r
- }\r
-\r
/**\r
* Contact manager instance\r
* @return the contactManager\r
* Contact manager instance\r
* @param contactManager the contactManager to set\r
*/\r
- protected void setContactManager(final ManageableContact contactManager) {\r
+ protected void setContactManager (final ManageableContact contactManager) {\r
this.contactManager = contactManager;\r
}\r
\r
+ /**\r
+ * Client instance\r
+ * @param client the client to set\r
+ */\r
+ protected void setClient (final Client client) {\r
+ this.client = client;\r
+ }\r
+\r
+ /**\r
+ * Application instance\r
+ *\r
+ * @param application the application to set\r
+ */\r
+ protected void setApplication(final Application application) {\r
+ this.application = application;\r
+ }\r
+\r
/**\r
* Getter for logger\r
*\r
return this.LOG;\r
}\r
\r
+ /**\r
+ * Name of used database table, handled over to backend\r
+ * \r
+ * @return the tableName\r
+ */\r
+ protected String getTableName () {\r
+ return this.tableName;\r
+ }\r
+\r
+ /**\r
+ * Name of used database table, handled over to backend\r
+ * \r
+ * @param tableName the tableName to set\r
+ */\r
+ protected void setTableName (final String tableName) {\r
+ this.tableName = tableName;\r
+ }\r
+\r
/**\r
* Initializes contact manager\r
* @param client Client instance\r
protected void initContactManager (final Client client) {\r
// Debug message\r
this.getLogger().debug("Initializing contact manager ...");\r
-\r
+ \r
// Init contact manager with console client\r
// @TODO Static initial amount of contacts\r
ManageableContact manager = new ContactManager (100, client);\r
-\r
+ \r
// Set it here\r
this.setContactManager(manager);\r
-\r
+ \r
// Debug message\r
this.getLogger().debug("Contact manager has been initialized.");\r
}\r
*/\r
package org.mxchange.addressbook.contact;\r
\r
+import java.util.Objects;\r
import org.mxchange.addressbook.BaseFrameworkSystem;\r
import org.mxchange.addressbook.client.Client;\r
\r
*\r
* @param object Other possible contact class\r
* @return Whether both contacts are same\r
+ * @todo Needs a lot improvements\r
*/\r
@Override\r
public boolean equals (Object object) {\r
+ // Is it same type?\r
+ if (!(object instanceof BaseContact)) {\r
+ // Not equal types\r
+ return false;\r
+ } else if (!(object instanceof Contact)) {\r
+ // Not correct interface\r
+ return false;\r
+ }\r
+\r
// Try to cast\r
- BaseContact c = (BaseContact) object;\r
+ Contact contact = (Contact) object;\r
\r
- /*\r
- * Now test some data @todo Definedly needs improvement\r
- */\r
- return ((this.getGender() == c.getGender())\r
- && (this.getSurname().toLowerCase().equals(c.getSurname().toLowerCase()))\r
- && (this.getFamilyName().toLowerCase().equals(c.getFamilyName().toLowerCase())));\r
+ // Now test some data @todo Definedly needs improvement\r
+ return ((this.getGender() == contact.getGender())\r
+ && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))\r
+ && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));\r
}\r
\r
/**\r
this.zipCode = zipCode;\r
}\r
\r
+ @Override\r
+ public int hashCode () {\r
+ int hash = 7;\r
+ hash = 79 * hash + Objects.hashCode(this.getFamilyName());\r
+ hash = 79 * hash + this.getGender();\r
+ hash = 79 * hash + Objects.hashCode(this.getSurname());\r
+ return hash;\r
+ }\r
+\r
/**\r
* Checks whether the contact is user's own data\r
*\r
this.setFamilyName(familyName);\r
this.setCompanyName(companyName);\r
}\r
+\r
+ /**\r
+ * Updates other data in this Contact instance\r
+ * \r
+ * @param phoneNumber Phone number\r
+ * @param cellphoneNumber Cellphone number\r
+ * @param faxNumber Fax number\r
+ * @param emailAddress Email address\r
+ * @param comment Comments\r
+ */\r
+ public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String comment) {\r
+ // Set all\r
+ this.setPhoneNumber(phoneNumber);\r
+ this.setCellphoneNumber(cellphoneNumber);\r
+ this.setFaxNumber(faxNumber);\r
+ this.setEmailAddress(emailAddress);\r
+ this.setComment(comment);\r
+ }\r
+\r
+ /**\r
+ * "Serializes" this object into a CSV string (this time with semicolons)\r
+ * \r
+ * @return "CSV-serialized" version of the stored data\r
+ */\r
+ public String getCsvStringFromStoreableObject () {\r
+ // Get all together\r
+ String csvString = String.format(\r
+ "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",\r
+ this.getGender(),\r
+ this.getSurname(),\r
+ this.getFamilyName(),\r
+ this.getCompanyName(),\r
+ this.getStreet(),\r
+ this.getZipCode(),\r
+ this.getCity(),\r
+ this.getCountryCode(),\r
+ this.getPhoneNumber(),\r
+ this.getFaxNumber(),\r
+ this.getCellphoneNumber(),\r
+ this.getEmailAddress(),\r
+ this.getBirthday(),\r
+ this.getComment()\r
+ );\r
+\r
+ // Then return it\r
+ return csvString;\r
+ }\r
}\r
* @param companyName Company name\r
*/\r
public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);\r
+\r
+ /**\r
+ * Updates other data in this Contact instance\r
+ * \r
+ * @param phoneNumber Phone number\r
+ * @param cellNumber Cellphone number\r
+ * @param faxNumber Fax number\r
+ * @param email Email address\r
+ * @param comment Comments\r
+ */\r
+ public void updateOtherData (final String phoneNumber, final String cellNumber, final String faxNumber, final String email, final String comment);\r
}\r
\r
import org.mxchange.addressbook.contact.BaseContact;\r
import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\r
\r
/**\r
* A contact that can be placed into "contact books"\r
* @version 0.0\r
* @since 0.0\r
*/\r
-public class BookContact extends BaseContact implements Contact {\r
+public class BookContact extends BaseContact implements Contact, StoreableCsv {\r
\r
}\r
\r
import org.mxchange.addressbook.contact.Contact;\r
import org.mxchange.addressbook.contact.book.BookContact;\r
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\r
\r
/**\r
*\r
* @author Roland Haeder\r
* @todo After a Collection has been used in ContactManager, change to BaseContact\r
*/\r
-public class UserContact extends BookContact implements Contact {\r
+public class UserContact extends BookContact implements Contact, StoreableCsv {\r
\r
/**\r
* Creates own contact entry\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.backend;\r
+\r
+import java.io.IOException;\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+\r
+/**\r
+ * A generic interface for database frontends\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface DatabaseBackend extends FrameworkInterface {\r
+ /**\r
+ * Stores an object in the database.\r
+ * \r
+ * @param object Object to store in database\r
+ * @throws java.io.IOException From inner class\r
+ */\r
+ public void store (final Storeable object) throws IOException;\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.backend.csv;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+class BaseDatabaseBackend extends BaseFrameworkSystem {\r
+ /**\r
+ * No instances from this class\r
+ */\r
+ protected BaseDatabaseBackend () {\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.backend.csv;\r
+\r
+import java.io.DataOutput;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.io.RandomAccessFile;\r
+import java.text.MessageFormat;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
+import org.mxchange.addressbook.database.storage.csv.StoreableCsv;\r
+\r
+/**\r
+ * A database backend with CSV file as storage implementation\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class CsvDatabaseBackend extends BaseDatabaseBackend implements DatabaseBackend {\r
+ /**\r
+ * Output stream for this storage engine\r
+ */\r
+ private RandomAccessFile storageFile;\r
+\r
+ /**\r
+ * Constructor with table name\r
+ * \r
+ * @param tableName Name of "table"\r
+ */\r
+ public CsvDatabaseBackend (final String tableName) {\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName));\r
+\r
+ // Set table name here, too\r
+ this.setTableName(tableName);\r
+\r
+ // Construct file name\r
+ String fileName = String.format("data/table_%s.csv", tableName);\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));\r
+\r
+ try {\r
+ // Try to initialize the storage (file instance)\r
+ this.storageFile = new RandomAccessFile(fileName, "rw");\r
+ } catch (final FileNotFoundException ex) {\r
+ // Did not work\r
+ this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString()));\r
+ System.exit(1);\r
+ }\r
+\r
+ // Output message\r
+ this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName));\r
+ }\r
+\r
+ /**\r
+ * Stores given object by "visiting" it\r
+ *\r
+ * @param object An object implementing Storeable\r
+ * @throws java.io.IOException From "inner" class\r
+ */\r
+ @Override\r
+ public void store (final Storeable object) throws IOException{\r
+ // Make sure the instance is there (DataOutput flawor)\r
+ assert(this.storageFile instanceof DataOutput);\r
+\r
+ // Try to cast it, this will fail if the interface is not implemented\r
+ StoreableCsv csv = (StoreableCsv) object;\r
+\r
+ // Now get the object that needs to be stored\r
+ String str = csv.getCsvStringFromStoreableObject();\r
+\r
+ // Debug message\r
+ this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));\r
+\r
+ // The string is now a valid CSV string\r
+ this.storageFile.writeUTF(str);\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.frontend;\r
+\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.database.backend.DatabaseBackend;\r
+import org.mxchange.addressbook.database.backend.csv.CsvDatabaseBackend;\r
+\r
+/**\r
+ * General database frontend class\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class BaseDatabaseFrontend extends BaseFrameworkSystem {\r
+\r
+ /**\r
+ * Instance for database backend\r
+ */\r
+ private DatabaseBackend backend;\r
+\r
+ /**\r
+ * No instances from this class\r
+ */\r
+ protected BaseDatabaseFrontend () {\r
+ }\r
+\r
+ /**\r
+ * Instance for database backend\r
+ * \r
+ * @return the backend\r
+ */\r
+ protected DatabaseBackend getBackend () {\r
+ return this.backend;\r
+ }\r
+\r
+ /**\r
+ * Instance for database backend\r
+ * \r
+ * @param backend the backend to set\r
+ */\r
+ protected void setBackend (final DatabaseBackend backend) {\r
+ this.backend = backend;\r
+ }\r
+\r
+ /**\r
+ * Initialize backend\r
+ */\r
+ protected void initBackend () {\r
+ // Instance backend\r
+ this.backend = new CsvDatabaseBackend(this.getTableName());\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.frontend;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ * A generic interface for database frontends\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface DatabaseWrapper extends FrameworkInterface {\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.frontend.contact;\r
+\r
+import java.io.IOException;\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;\r
+\r
+/**\r
+ * Stores and retrieves Contact instances\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {\r
+ /**\r
+ * Basic constrcutor\r
+ */\r
+ public ContactDatabaseFrontend () {\r
+ super();\r
+\r
+ // Set "table" name\r
+ this.setTableName("contacts");\r
+\r
+ // Initalize backend\r
+ this.initBackend();\r
+ }\r
+\r
+ @Override\r
+ public void addContact (final Contact contact) {\r
+ try {\r
+ // Try to cast the object and handle it over to the backend\r
+ this.getBackend().store((Storeable) contact);\r
+ } catch (final IOException ex) {\r
+ this.getLogger().error("Cannot write contact to storage: " + ex.getMessage());\r
+ System.exit(1);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Häder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.frontend.contact;\r
+\r
+import org.mxchange.addressbook.contact.Contact;\r
+import org.mxchange.addressbook.database.frontend.DatabaseWrapper;\r
+\r
+/**\r
+ *\r
+ * @author Roland Häder\r
+ */\r
+public interface ContactWrapper extends DatabaseWrapper {\r
+ /**\r
+ * Adds a Contact instance to database\r
+ * \r
+ * @param contact Contact instance to add(store) to database\r
+ */\r
+ public void addContact (final Contact contact);\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.storage;\r
+\r
+import org.mxchange.addressbook.FrameworkInterface;\r
+\r
+/**\r
+ *An interface for objects being stored in databases\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public interface Storeable extends FrameworkInterface {\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2015 KLC\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.database.storage.csv;\r
+\r
+import org.mxchange.addressbook.database.storage.Storeable;\r
+\r
+/**\r
+ *\r
+ * @author KLC\r
+ */\r
+public interface StoreableCsv extends Storeable {\r
+ /**\r
+ * Getter for a CSV-formated string from object\r
+ * @return \r
+ */\r
+ public String getCsvStringFromStoreableObject ();\r
+}\r
import org.mxchange.addressbook.client.Client;\r
import org.mxchange.addressbook.contact.Contact;\r
import org.mxchange.addressbook.contact.user.UserContact;\r
+import org.mxchange.addressbook.database.frontend.contact.ContactDatabaseFrontend;\r
+import org.mxchange.addressbook.database.frontend.contact.ContactWrapper;\r
import org.mxchange.addressbook.manager.BaseManager;\r
\r
/**\r
- * A manager for contacts\r
+ * A manager for contacts, please note that this implementation loads the whole\r
+ * list into RAM.\r
*\r
* @author Roland Haeder\r
* @version 0.0\r
public class ContactManager extends BaseManager implements ManageableContact {\r
\r
/**\r
- * All contacts\r
+ * A ContactWrapper instance\r
+ */\r
+ private final ContactWrapper contactDatabase;\r
+\r
+ /**\r
+ * A list of all contacts\r
*/\r
private final List<Contact> contacts;\r
\r
// Init contacts\r
this.contacts = new ArrayList<>(maxContacts);\r
\r
+ // Init database connection\r
+ this.contactDatabase = new ContactDatabaseFrontend();\r
+\r
// Debug message\r
//* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);\r
\r
// Debug message\r
/* NOISY-DEBUG: */ this.getLogger().debug("Adding '" + contact.getSurname() + "' '" + contact.getFamilyName() + "' at pos '" + this.size () + "' ...");\r
\r
- // Add contact\r
+ // Add contact to internal list\r
this.contacts.add(contact);\r
+\r
+ /*\r
+ * @TODO This call doesn't make sense, it would cause that only one\r
+ * entry exist in storage. A better solution is to iterate over all\r
+ * contacts and add them. This may also require to rewrite the database\r
+ * layer a little. For demonstrational purposes, this should be fine.\r
+ */\r
+\r
+ // Add object to database\r
+ this.getContactDatabase().addContact(contact);\r
}\r
\r
/**\r
String familyName = this.enterOwnFamilyName();\r
\r
// And company\r
- String companyName = this.enterCompanyName();\r
+ String companyName = this.enterOwnCompanyName();\r
\r
// Update contact instance\r
contact.updateNameData(gender, surname, familyName, companyName);\r
*/\r
@Override\r
public void doChangeOtherData (final Contact contact, final Client client) {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ // First display them again\r
+ client.displayOtherDataBox(contact);\r
+\r
+ // Is this own data?\r
+ if (contact.isOwnContact()) {\r
+ // Re-ask own data\r
+ // Phone number\r
+ String phoneNumber = this.enterOwnPhoneNumber();\r
+\r
+ // Phone number\r
+ String cellNumber = this.enterOwnCellNumber();\r
+\r
+ // Fax number\r
+ String faxNumber = this.enterOwnFaxNumber();\r
+\r
+ // Email address\r
+ String email = this.enterOwnEmailAddress();\r
+\r
+ // Comment\r
+ String comment = this.enterOwnComment();\r
+\r
+ // Update contact instance\r
+ contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, comment);\r
+ } else {\r
+ // Then re-ask them ...\r
+ throw new UnsupportedOperationException("Changing contact entries not finished.");\r
+ }\r
}\r
\r
/**\r
String familyName = this.enterOwnFamilyName();\r
\r
// Company name ...\r
- String companyName = this.enterCompanyName();\r
+ String companyName = this.enterOwnCompanyName();\r
\r
// Construct UserContact instance\r
Contact contact = new UserContact(gender, surname, familyName, companyName);\r
}\r
\r
/**\r
- * Asks the user for his/her company name\r
- * @return \r
+ * Asks the user for his/her cellphone number\r
+ * \r
+ * @return User's cellphone number\r
*/\r
- private String enterCompanyName () {\r
- return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);\r
+ private String enterOwnCellNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true);\r
}\r
\r
/**\r
* Asks the user for his/her city's name\r
- * \r
+ *\r
* @return City's name of the user\r
*/\r
private String enterOwnCity () {\r
return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false);\r
}\r
\r
+ /**\r
+ * Asks the user for his/her city's name\r
+ *\r
+ * @return City's name of the user\r
+ */\r
+ private String enterOwnComment () {\r
+ return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true);\r
+ }\r
+\r
+ /**\r
+ * Asks the user for his/her company name\r
+ * \r
+ * @return User's company name\r
+ */\r
+ private String enterOwnCompanyName () {\r
+ return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);\r
+ }\r
+\r
/**\r
* Asks user for his/her own country code\r
* \r
return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase();\r
}\r
\r
+ /**\r
+ * Asks user for his/her own country code\r
+ * \r
+ * @return User's own country code\r
+ */\r
+ private String enterOwnEmailAddress () {\r
+ return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true);\r
+ }\r
+\r
/**\r
* Asks the user for family name\r
+ * \r
* @return Family name of the user\r
*/\r
private String enterOwnFamilyName () {\r
return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);\r
}\r
\r
+ /**\r
+ * Asks the user for family name\r
+ * \r
+ * @return Family name of the user\r
+ */\r
+ private String enterOwnFaxNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true);\r
+ }\r
+\r
/**\r
* Asks the user for gender, until a valid has been entered\r
+ * \r
* @return Gender of the user\r
*/\r
private char enterOwnGender () {\r
return this.getClient().enterChar(new char[] {'M', 'F', 'C'}, "Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");\r
}\r
\r
+ /**\r
+ * Asks the user for phone number\r
+ * \r
+ * @return Phone number of the user\r
+ */\r
+ private String enterOwnPhoneNumber () {\r
+ return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true);\r
+ }\r
+\r
/**\r
* Asks the user for own street (including number)\r
*/\r
// Return result\r
return isAdded;\r
}\r
+\r
+ /**\r
+ * A ContactWrapper instance\r
+ *\r
+ * @return the database\r
+ */\r
+ private ContactWrapper getContactDatabase () {\r
+ return this.contactDatabase;\r
+ }\r
}\r