]> git.mxchange.org Git - jaddressbook-share-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java
A lot refacturings ...
[jaddressbook-share-lib.git] / Addressbook / src / org / mxchange / addressbook / client / console / ConsoleClient.java
index bbefa9e05969d8e0faba7ba3c0ca2ea817fd778e..b523a138b1d47632993679a7a07d7a66c8e46ad4 100644 (file)
@@ -26,6 +26,7 @@ import org.mxchange.addressbook.client.Client;
 import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.contact.Gender;
 import org.mxchange.addressbook.contact.user.UserContact;
+import org.mxchange.addressbook.exceptions.ContactAlreadyAddedException;
 import org.mxchange.addressbook.exceptions.UnhandledUserChoiceException;
 import org.mxchange.addressbook.menu.Menu;
 import org.mxchange.addressbook.menu.MenuTools;
@@ -72,12 +73,12 @@ public class ConsoleClient extends BaseClient implements Client {
        @Override
        public void displayAddressBox (final Contact contact) {
                // Trace message
-               this.getLogger().trace("contact=" + contact + " - CALLED!"); //NOI18N
+               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Simple display ...
@@ -100,7 +101,7 @@ public class ConsoleClient extends BaseClient implements Client {
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Get translated gender as the user may want to see "Mr.", "Mrs."
@@ -136,7 +137,7 @@ public class ConsoleClient extends BaseClient implements Client {
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Cellphone and such ...
@@ -154,13 +155,13 @@ public class ConsoleClient extends BaseClient implements Client {
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Make sure it is own contact
                if (!contact.isOwnContact()) {
                        // Not own contact
-                       throw new IllegalArgumentException("Contact is not own data.");
+                       throw new IllegalArgumentException("Contact is not own data."); //NOI18N
                }
 
                // Own address data
@@ -190,13 +191,13 @@ public class ConsoleClient extends BaseClient implements Client {
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Make sure it is own contact
                if (!contact.isOwnContact()) {
                        // Not own contact
-                       throw new IllegalArgumentException("Contact is not own data.");
+                       throw new IllegalArgumentException("Contact is not own data."); //NOI18N
                }
 
                // Gender:
@@ -226,13 +227,13 @@ public class ConsoleClient extends BaseClient implements Client {
                // Is it null?
                if (contact == null) {
                        // Abort here
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                }
 
                // Make sure it is own contact
                if (!contact.isOwnContact()) {
                        // Not own contact
-                       throw new IllegalArgumentException("Contact is not own data.");
+                       throw new IllegalArgumentException("Contact is not own data."); //NOI18N
                }
 
                // Phone number
@@ -314,8 +315,14 @@ public class ConsoleClient extends BaseClient implements Client {
 
                // @TODO Rewrite this ugly switch() block
                switch (choice) {
-                       case '1': // Enter/add own data
-                               this.getContactManager().doEnterOwnData();
+                       case '1':
+                               try {
+                                       // Enter/add own data
+                                       this.getContactManager().doEnterOwnData();
+                               } catch (final ContactAlreadyAddedException ex) {
+                                       // Already added
+                                       this.outputMessage("Sie haben bereits Ihre eigenen Daten eingegeben.");
+                               }
                                break;
 
                        case '2': // Change own data
@@ -348,7 +355,7 @@ public class ConsoleClient extends BaseClient implements Client {
 
                        default:
                                // @TODO throw own exception
-                               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice));
+                               throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); //NOI18N
                }
 
                // Trace message
@@ -370,10 +377,10 @@ public class ConsoleClient extends BaseClient implements Client {
                // The validChars must not null be null and filled with at least one char
                if (validChars == null) {
                        // Is null
-                       throw new NullPointerException("validChars is null");
+                       throw new NullPointerException("validChars is null"); //NOI18N
                } else if (validChars.length == 0) {
                        // Is not filled
-                       throw new IllegalArgumentException("validChars is not filled.");
+                       throw new IllegalArgumentException("validChars is not filled."); //NOI18N
                }
 
                char input = 0;
@@ -420,10 +427,10 @@ public class ConsoleClient extends BaseClient implements Client {
                Gender g = Gender.fromChar(gender);
 
                // g must not be null
-               assert(g instanceof Gender) : "g is not set.";
+               assert(g instanceof Gender) : "g is not set."; //NOI18N
 
                // Trace message
-               this.getLogger().trace("g=" + g + " - EXIT!"); //NOI18N
+               this.getLogger().trace(MessageFormat.format("g={0} - EXIT!", g)); //NOI18N
 
                // Return it
                return g;
@@ -458,7 +465,7 @@ public class ConsoleClient extends BaseClient implements Client {
                }
 
                // Trace message
-               this.getLogger().trace("input=" + input + " - EXIT!"); //NOI18N
+               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
 
                // Return it
                return input;
@@ -558,7 +565,7 @@ public class ConsoleClient extends BaseClient implements Client {
        @Override
        public void showEntry (final SelectableMenuItem item) {
                // Access key then text
-               this.outputMessage("[" + item.getAccessKey() + "] " + item.getText());
+               this.outputMessage(MessageFormat.format("[{0}] {1}", item.getAccessKey(), item.getText()));
        }
 
        /**