]> git.mxchange.org Git - jfinancials-swing.git/blobdiff - src/org/mxchange/addressbook/client/console/ConsoleClient.java
Prepared for upcoming rewrite:
[jfinancials-swing.git] / src / org / mxchange / addressbook / client / console / ConsoleClient.java
index ecfbd4dfa4d8e21aa2576a31ce6fb13341127014..5deface1b526c4c01d336563c8f9adfc89f16f01 100644 (file)
@@ -32,16 +32,16 @@ import org.mxchange.addressbook.menu.MenuTools;
 import org.mxchange.addressbook.menu.console.ConsoleMenu;
 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
 import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem;
-import org.mxchange.addressbook.model.contact.user.UserContact;
 import org.mxchange.jcore.application.Application;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.model.contact.Contact;
+import org.mxchange.jcore.model.contact.UserContact;
 import org.mxchange.jcore.model.contact.gender.Gender;
 import org.mxchange.jcore.model.contact.gender.GenderUtils;
 
 /**
  * A client for the console
- *
+ * <p>
  * @author Roland Haeder
  */
 public class ConsoleClient extends BaseAddressbookClient implements AddressbookClient {
@@ -53,12 +53,12 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
 
        /**
         * Parameterless constructor
-        *
+        * <p>
         * @param application An instance of an Application class
         */
        public ConsoleClient (final Application application) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", application)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("application={0} - CALLED!", application)); //NOI18N
 
                // Set application instance
                this.setApplication(application);
@@ -67,18 +67,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.scanner = new Scanner(System.in, "UTF-8"); //NOI18N
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Displays a textual address "box" of given contact
-        *
-        * @param contact Contact to show address for
-        */
        @Override
        public void displayAddressBox (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -90,18 +85,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.outputMessage(MessageFormat.format("Strasse, PLZ Ort, Land: {0}\n{1} {2}\n{3}", contact.getStreet(), contact.getZipCode(), contact.getCity(), contact.getCountryCode()));
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Displays a textual name "box" of given contact
-        *
-        * @param contact Contact to show name for
-        */
        @Override
        public void displayNameBox (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -126,18 +116,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Displays a textual other data "box" of given contact
-        *
-        * @param contact Contact to show other data for
-        */
        @Override
        public void displayOtherDataBox (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -149,13 +134,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.outputMessage(MessageFormat.format("Telefonnumer: {0}\nFaxnummer: {1}\nHandy: {2}\nKommentar:\n{3}", contact.getPhoneNumber(), contact.getFaxNumber(), contact.getCellphoneNumber(), contact.getComment()));
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doChangeOwnAddressData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -191,13 +176,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                contact.setCountryCode(countryCode);
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doChangeOwnNameData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -233,13 +218,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                contact.setCompanyName(companyName);
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doChangeOwnOtherData (final Contact contact) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Is it null?
                if (null == contact) {
@@ -279,13 +264,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                contact.setComment(comment);
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public Contact doEnterOwnData () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get manager and cast it
                ManageableContactAddressbook manager = (ManageableContactAddressbook) this.getManager();
@@ -293,8 +278,8 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                // First ask for gender
                Gender gender = manager.enterOwnGender();
 
-               // 2nd for surname
-               String surname = manager.enterOwnFirstName();
+               // 2nd for first name
+               String firstName = manager.enterOwnFirstName();
 
                // And 3rd for family name
                String familyName = manager.enterOwnFamilyName();
@@ -303,36 +288,32 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                String companyName = manager.enterOwnCompanyName();
 
                // Construct UserContact instance
-               Contact contact = new UserContact(gender, surname, familyName, companyName);
+               Contact contact = new UserContact(gender, firstName, familyName, companyName);
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
 
                // And return object
                return contact;
        }
 
-       /**
-        * Shutdown this client
-        */
        @Override
        public void doShutdown () throws SQLException, IOException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Parent call
                super.doShutdown();
 
                // TODO Add other shutdown stuff
-
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doUserMenuChoice () throws UnhandledUserChoiceException {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Get all access keys from menu
                char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());
@@ -381,14 +362,14 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                                        manager.doDeleteOtherAddress();
                                        break;
 
-                       case '0':
-                               try {
-                                       // Program exit
-                                       this.getApplication().doShutdown();
-                               } catch (final SQLException | IOException ex) {
-                                       this.abortProgramWithException(ex);
-                               }
-                               break;
+                               case '0':
+                                       try {
+                                               // Program exit
+                                               this.getApplication().doShutdown();
+                                       } catch (final SQLException | IOException ex) {
+                                               this.abortProgramWithException(ex);
+                                       }
+                                       break;
 
                                default:
                                        // TODO throw own exception
@@ -400,20 +381,13 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Asks the the user to enter a single character which must match validChars
-        *
-        * @param       validChars Valid chars that are accepted
-        * @param       message Message to user
-        * @return      Allowed character
-        */
        @Override
        public char enterChar (final char[] validChars, final String message) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("validChars={0},message={1} - CALLED!", Arrays.toString(validChars), message)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("validChars={0},message={1} - CALLED!", Arrays.toString(validChars), message)); //NOI18N
 
                // The validChars must not null be null and filled with at least one char
                if (null == validChars) {
@@ -439,22 +413,16 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
 
                // Return read char
                return input;
        }
 
-       /**
-        * Asks the user to enter his/her gender
-        *
-        * @param message Message to the user
-        * @return Gender enum
-        */
        @Override
        public Gender enterGender (final String message) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("message={0} - CALLED!", message)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("message={0} - CALLED!", message)); //NOI18N
 
                // Get valid chars
                char[] validChars = Gender.validChars();
@@ -468,31 +436,23 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                Gender g = Gender.fromChar(gender);
 
                // g must not be null
-               assert(g instanceof Gender) : "g is not set."; //NOI18N
+               assert (g instanceof Gender) : "g is not set."; //NOI18N
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("g={0} - EXIT!", g)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("g={0} - EXIT!", g)); //NOI18N
 
                // Return it
                return g;
        }
 
-       /**
-        * Reads an integer (int) with a textural message from the user
-        *
-        * @param minimum Minimum allowed number
-        * @param maximum Maximum allowed number
-        * @param message Messager to display in console
-        * @return
-        */
        @Override
        public int enterInt (final int minimum, final int maximum, final String message) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("minimum={0},maximum={1},message={2} - CALLED!", minimum, maximum, message)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("minimum={0},maximum={1},message={2} - CALLED!", minimum, maximum, message)); //NOI18N
 
                // Minimum should not be below zero
-               assert (minimum >= 0);
-               assert (maximum > minimum);
+               assert (minimum >= 0) : MessageFormat.format("minimum={0} is below zero", minimum); //NOI18N
+               assert (maximum > minimum) : MessageFormat.format("maximum {0} is smaller than minimum {1}", maximum, minimum); //NOI18N
 
                // Init input
                int input = -1;
@@ -506,25 +466,16 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
 
                // Return it
                return input;
        }
 
-       /**
-        * Reads a string of minimum and maximum length from the user
-        *
-        * @param minLength     Minimum length of the string to read
-        * @param maxLength     Maximum length of the string to read
-        * @param message       Message to user
-        * @param allowEmpty Whether to allow empty string
-        * @return Entered string by user or null for empty strings
-        */
        @Override
        public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("minLength={0},maxLength={1},message={2}allowEmpty={3} - CALLED!", minLength, maxLength, message, allowEmpty)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("minLength={0},maxLength={1},message={2}allowEmpty={3} - CALLED!", minLength, maxLength, message, allowEmpty)); //NOI18N
 
                // Check on length, e.g. country codes are excactly 2 chars long
                assert (maxLength >= minLength);
@@ -542,33 +493,22 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N
 
                // Return it
                return input;
        }
 
-       /**
-        * Returns a console menu item
-        *
-        * @param accessKey Key to access the menu
-        * @param text Text to show to user
-        * @return A SelectableMenuItem
-        * TODO Make sure the access key is unique
-        */
        @Override
        public SelectableMenuItem getMenuItem (final char accessKey, final String text) {
                // Return a new console menu item
                return new ConsoleMenuItem(accessKey, text);
        }
 
-       /**
-        * Initializes this client
-        */
        @Override
        public void init () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Init contact manager here
                try {
@@ -582,55 +522,39 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.fillMenuMap();
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
-       /**
-        * Displays textural message to the user
-        *
-        * @param message
-        */
        @Override
        public void outputMessage (final String message) {
                System.out.println(message);
        }
 
-       /**
-        * Shows textural menu on console
-        */
        @Override
        public void showCurrentMenu () {
                this.showMenu(this.getCurrentMenu());
        }
 
-       /**
-        * Shows given menu entry to user
-        *
-        * @param item Menu entry
-        */
        @Override
        public void showEntry (final SelectableMenuItem item) {
                // Access key then text
-               this.outputMessage(MessageFormat.format("[{0}] {1}", item.getAccessKey(), item.getText()));
+               this.outputMessage(MessageFormat.format("[{0}] {1}", item.getAccessKey(), item.getText())); //NOI18N
        }
 
-       /**
-        * Shows a textural message to the user
-        */
        @Override
        public void showWelcome () {
-               this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle()));
-               this.outputMessage("");
-               this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");
+               this.outputMessage(MessageFormat.format("Welcome to {0}", AddressbookApplication.printableTitle())); //NOI18N
+               this.outputMessage(""); //NOI18N
+               this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software"); //NOI18N
 
                // Debug message
-               this.getLogger().debug("Intro shown to user"); //NOI18N
+               this.getLogger().logDebug("Intro shown to user"); //NOI18N
        }
 
        @Override
        public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -668,12 +592,12 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 
        /**
         * Reads one character
-        *
+        * <p>
         * @return A single character
         */
        private char readChar () {
@@ -681,7 +605,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                String input = this.readString();
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("input={0}", input)); //NOI18N
+               this.getLogger().logDebug(MessageFormat.format("input={0}", input)); //NOI18N
 
                // This must be only one character
                if (input.length() != 1) {
@@ -695,7 +619,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
 
        /**
         * Reads an integer (int) from user
-        *
+        * <p>
         * @return An integer number
         */
        private int readInt () {
@@ -703,7 +627,7 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                String input = this.readString();
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("input={0}", input)); //NOI18N
+               this.getLogger().logDebug(MessageFormat.format("input={0}", input)); //NOI18N
 
                // Init number with invalid value
                int num = -1;
@@ -713,11 +637,11 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                        num = Integer.parseInt(input);
                } catch (final NumberFormatException e) {
                        this.outputMessage("Bitte geben Sie nur Zahlen ein!");
-                       this.getLogger().warn(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); //NOI18N
+                       this.getLogger().logWarning(MessageFormat.format("No numbers-only entered. input={0},message={1}", input, e.getMessage())); //NOI18N
                }
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("num={0} - EXIT!", num)); //NOI18N
+               this.getLogger().logTrace(MessageFormat.format("num={0} - EXIT!", num)); //NOI18N
 
                // Return read number
                return num;
@@ -725,20 +649,17 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
 
        /**
         * Reads a string from a scanner until RETURN is pressed
-        *
+        * <p>
         * @return Read string from scanner
         */
        private String readString () {
                return this.scanner.nextLine();
        }
 
-       /**
-        * Fills menu map with menu entries
-        */
        @Override
        protected final void fillMenuMap () {
                // Trace message
-               this.getLogger().trace("CALLED!"); //NOI18N
+               this.getLogger().logTrace("CALLED!"); //NOI18N
 
                // Initialize first (main) menu
                Menu menu = new ConsoleMenu("main", this); //NOI18N
@@ -747,6 +668,6 @@ public class ConsoleClient extends BaseAddressbookClient implements AddressbookC
                this.getMenus().put("main", menu); //NOI18N
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               this.getLogger().logTrace("EXIT!"); //NOI18N
        }
 }