From 9ad193b51551b58af5a9eef70810933f0f6033ee Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 28 Jul 2015 15:27:51 +0200 Subject: [PATCH] =?utf8?q?Added=20a=20lot=20trace=20messages=20+=20sanity?= =?utf8?q?=20checks=20for=20null=20references=20and=20such=20things=20Sign?= =?utf8?q?ed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/AddressbookApplication.java | 51 +++-- .../addressbook/client/BaseClient.java | 19 ++ .../client/console/ConsoleClient.java | 162 ++++++++++++- .../client/gui/AddressbookFrame.java | 92 ++++++++ .../addressbook/client/gui/SwingClient.java | 10 +- .../addressbook/contact/BaseContact.java | 35 ++- .../addressbook/contact/user/UserContact.java | 7 + .../backend/csv/Base64CsvDatabaseBackend.java | 157 ++++++++----- .../frontend/BaseDatabaseFrontend.java | 6 + .../contact/ContactDatabaseFrontend.java | 35 ++- .../application/ApplicationManager.java | 21 ++ .../manager/contact/ContactManager.java | 215 +++++++++++++++--- .../manager/contact/ManageableContact.java | 10 +- .../addressbook/menu/AddressbookMenu.java | 19 +- .../mxchange/addressbook/menu/BaseMenu.java | 19 ++ .../mxchange/addressbook/menu/MenuTools.java | 4 +- .../addressbook/menu/console/ConsoleMenu.java | 11 + .../menu/item/console/ConsoleMenuItem.java | 17 +- .../mxchange/addressbook/model/BaseModel.java | 51 +++++ .../model/contact/ContactTableModel.java | 10 + 20 files changed, 816 insertions(+), 135 deletions(-) diff --git a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java index 2f4f185..7471512 100644 --- a/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java +++ b/Addressbook/src/org/mxchange/addressbook/application/AddressbookApplication.java @@ -77,12 +77,12 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli /** * Application title */ - public static final String APP_TITLE = "Adressbuch"; + public static final String APP_TITLE = "Adressbuch"; //NOI18N /** * Application version */ - public static final String APP_VERSION = "0.0"; + public static final String APP_VERSION = "0.0"; //NOI18N /** * Self instance @@ -113,7 +113,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli * @return A printable name */ public static String printableTitle () { - return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); + return MessageFormat.format("{0} v{1}", APP_TITLE, APP_VERSION); //NOI18N } /** @@ -121,7 +121,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli */ @Override public void doBootstrap () { - this.getLogger().debug("Initializing application ..."); + this.getLogger().debug("Initializing application ..."); //NOI18N // Init client variable Client client = null; @@ -129,19 +129,19 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli // Is console or Swing choosen? if (this.isConsole()) { // Debug message - this.getLogger().debug("Initializing console client ..."); + this.getLogger().debug("Initializing console client ..."); //NOI18N // Init console client instance client = new ConsoleClient(this); } else if (this.isGui()) { // Debug message - this.getLogger().debug("Initializing GUI (Swing) client ..."); + this.getLogger().debug("Initializing GUI (Swing) client ..."); //NOI18N // Init console instance client = new SwingClient(this); } else { // Not client choosen - this.getLogger().error("No client choosen. Cannot launch."); + this.getLogger().error("No client choosen. Cannot launch."); //NOI18N System.exit(1); } @@ -153,6 +153,9 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli // The application is running at this point this.getClient().enableIsRunning(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -161,14 +164,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli @Override public void doMainLoop () { // Debug message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // @TODO The application should be running now // Output introduction this.showIntro(); // Set current menu to main - this.getClient().setCurrentMenu("main"); + this.getClient().setCurrentMenu("main"); //NOI18N // --- Main loop starts here --- while (this.getClient().isRunning()) { @@ -192,14 +195,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli // --- Main loop ends here --- // Debug message - this.getLogger().debug("Main loop exit - shutting down ..."); + this.getLogger().debug("Main loop exit - shutting down ..."); //NOI18N } /** * Enables console client by setting propper flag */ private void enableConsoleClient () { - this.getLogger().debug("Enabling console client (may become optional client) ..."); + this.getLogger().debug("Enabling console client (may become optional client) ..."); //NOI18N this.consoleClient = true; this.guiClient = false; } @@ -208,7 +211,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli * Enables GUI client by setting propper flag */ private void enableGuiClient () { - this.getLogger().debug("Enabling GUI client (may become new default client) ..."); + this.getLogger().debug("Enabling GUI client (may become new default client) ..."); //NOI18N this.consoleClient = false; this.guiClient = true; } @@ -239,17 +242,20 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli * @param args Arguments from program launch */ private void parseArguments (final String[] args) { + // Trace message + this.getLogger().trace(MessageFormat.format("args()={0} - CALLED!", args.length)); //NOI18N + // Debug message - this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); + this.getLogger().debug(MessageFormat.format("Parsing {0} arguments ...", args.length)); //NOI18N for (final String arg : args) { // Switch on it switch (arg) { - case "-console": + case "-console": //NOI18N enableConsoleClient(); break; - case "-gui": + case "-gui": //NOI18N enableGuiClient(); break; } @@ -260,8 +266,14 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli * Show introduction which depends on client */ private void showIntro () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Let the client show it this.getClient().showWelcome(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -270,7 +282,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli * @param args Arguments handled to program */ private void start (final String args[]) { - this.getLogger().info("Program is started."); + this.getLogger().info("Program is started."); //NOI18N // Parse arguments this.parseArguments(args); @@ -279,7 +291,7 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli ApplicationManager.getManager(this).start(); // Good bye, but this should not be reached ... - this.getLogger().warn("Unusual exit reached."); + this.getLogger().warn("Unusual exit reached."); //NOI18N this.doShutdown(); } @@ -298,10 +310,13 @@ public class AddressbookApplication extends BaseFrameworkSystem implements Appli */ @Override public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Shutdown client this.getClient().doShutdown(); - this.getLogger().info("End of program (last line)"); + this.getLogger().info("End of program (last line)"); //NOI18N System.exit(0); } diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java index 54d8bc3..6bd281f 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.client; +import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; import org.mxchange.addressbook.BaseFrameworkSystem; @@ -59,11 +60,17 @@ public abstract class BaseClient extends BaseFrameworkSystem { * Shutdown method for all clients */ public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Disable client this.disableIsRunning(); // Shuts down contact manager this.getContactManager().doShutdown(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -147,6 +154,9 @@ public abstract class BaseClient extends BaseFrameworkSystem { * Initializes contact manager */ protected void initContactManager () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Debug message this.getLogger().debug("Initializing contact manager ..."); @@ -159,6 +169,9 @@ public abstract class BaseClient extends BaseFrameworkSystem { // Debug message this.getLogger().debug("Contact manager has been initialized."); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -167,6 +180,9 @@ public abstract class BaseClient extends BaseFrameworkSystem { * @param menuType Given menu to show */ protected void showMenu (final String menuType) { + // Trace message + this.getLogger().trace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N + Menu menu = this.getMenu(menuType); // Is the menu set? @@ -178,5 +194,8 @@ public abstract class BaseClient extends BaseFrameworkSystem { // Show menu menu.show((Client) this); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 9de67f1..bbefa9e 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -51,13 +51,17 @@ public class ConsoleClient extends BaseClient implements Client { * @param application An instance of an Application class */ public ConsoleClient (final Application application) { - super(); + // Trace message + this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", application)); //NOI18N // Set application instance this.setApplication(application); // Init scanner instance this.scanner = new Scanner(System.in); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -67,8 +71,20 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public void displayAddressBox (final Contact contact) { + // Trace message + this.getLogger().trace("contact=" + contact + " - CALLED!"); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Simple display ... 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 } /** @@ -78,6 +94,15 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public void displayNameBox (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Get translated gender as the user may want to see "Mr.", "Mrs." String gender = contact.getTranslatedGender(); @@ -93,6 +118,9 @@ public class ConsoleClient extends BaseClient implements Client { // Company contact this.outputMessage(MessageFormat.format("Firma: {0}\nAnsprechpartner: {1} {2} {3}", companyName, gender, contact.getSurname(), contact.getFamilyName())); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -102,12 +130,33 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public void displayOtherDataBox (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Cellphone and such ... 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 } @Override public void doChangeOwnAddressData (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Make sure it is own contact if (!contact.isOwnContact()) { // Not own contact @@ -128,10 +177,22 @@ public class ConsoleClient extends BaseClient implements Client { // Update address data contact.updateAddressData(street, zipCode, city, countryCode); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override public void doChangeOwnNameData (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Make sure it is own contact if (!contact.isOwnContact()) { // Not own contact @@ -152,10 +213,22 @@ public class ConsoleClient extends BaseClient implements Client { // Update contact instance contact.updateNameData(gender, surname, familyName, companyName); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override public void doChangeOwnOtherData (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // Is it null? + if (contact == null) { + // Abort here + throw new NullPointerException("contact is null"); + } + // Make sure it is own contact if (!contact.isOwnContact()) { // Not own contact @@ -179,10 +252,16 @@ public class ConsoleClient extends BaseClient implements Client { // Update contact instance contact.updateOtherData(phoneNumber, cellNumber, faxNumber, email, null, comment); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override public Contact doEnterOwnData () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // First ask for gender Gender gender = this.getContactManager().enterOwnGender(); @@ -198,6 +277,9 @@ public class ConsoleClient extends BaseClient implements Client { // Construct UserContact instance Contact contact = new UserContact(gender, surname, familyName, companyName); + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N + // And return object return contact; } @@ -207,14 +289,23 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Parent call super.doShutdown(); // @TODO Add other shutdown stuff + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override public void doUserMenuChoice () throws UnhandledUserChoiceException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Get all access keys from menu char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu()); @@ -259,6 +350,9 @@ public class ConsoleClient extends BaseClient implements Client { // @TODO throw own exception throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -270,6 +364,18 @@ public class ConsoleClient extends BaseClient implements Client { */ @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 + + // 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"); + } else if (validChars.length == 0) { + // Is not filled + throw new IllegalArgumentException("validChars is not filled."); + } + char input = 0; // Sort array, else binarySearch() won't work @@ -284,6 +390,9 @@ public class ConsoleClient extends BaseClient implements Client { input = this.readChar(); } + // Trace message + this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N + // Return read char return input; } @@ -296,6 +405,9 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public Gender enterGender (final String message) { + // Trace message + this.getLogger().trace(MessageFormat.format("message={0} - CALLED!", message)); //NOI18N + // Get valid chars char[] validChars = Gender.validChars(); @@ -307,6 +419,12 @@ public class ConsoleClient extends BaseClient implements Client { // Now get a Gender instance back Gender g = Gender.fromChar(gender); + // g must not be null + assert(g instanceof Gender) : "g is not set."; + + // Trace message + this.getLogger().trace("g=" + g + " - EXIT!"); //NOI18N + // Return it return g; } @@ -321,6 +439,9 @@ public class ConsoleClient extends BaseClient implements Client { */ @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 + // Minimum should not be below zero assert (minimum >= 0); assert (maximum > minimum); @@ -336,6 +457,9 @@ public class ConsoleClient extends BaseClient implements Client { input = this.readInt(); } + // Trace message + this.getLogger().trace("input=" + input + " - EXIT!"); //NOI18N + // Return it return input; } @@ -351,6 +475,9 @@ public class ConsoleClient extends BaseClient implements Client { */ @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 + // Check on length, e.g. country codes are excactly 2 chars long assert (maxLength >= minLength); @@ -366,6 +493,9 @@ public class ConsoleClient extends BaseClient implements Client { input = this.readString(); } + // Trace message + this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N + // Return it return input; } @@ -389,11 +519,17 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override public void init () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init contact manager here this.initContactManager(); // Fill menu map this.fillMenuMap(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -440,21 +576,30 @@ public class ConsoleClient extends BaseClient implements Client { @Override public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { + // 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"); + } + // Ask the user for editing [name], [a]ddress or [other] data 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) "); // @TODO Get rid of this ugly switch block, too switch (choice) { case 'n': // Name data - this.getContactManager().doChangeNameData(contact, this); + this.getContactManager().doChangeNameData(contact); break; case 'a': // Address data - this.getContactManager().doChangeAddressData(contact, this); + this.getContactManager().doChangeAddressData(contact); break; case 'o': // Other data - this.getContactManager().doChangeOtherData(contact, this); + this.getContactManager().doChangeOtherData(contact); break; case 'x': // Exit this menu @@ -465,6 +610,9 @@ public class ConsoleClient extends BaseClient implements Client { // @TODO throw own exception throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -524,10 +672,16 @@ public class ConsoleClient extends BaseClient implements Client { */ @Override protected final void fillMenuMap () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Initialize first (main) menu Menu menu = new ConsoleMenu("main", this); // Add it this.getMenus().put("main", menu); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index ea74026..4a7a9c8 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -139,10 +139,16 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Set client here this.setClient(client); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override public Contact doEnterOwnData () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Is the "add contact" window visible? if (this.addContact.isVisible()) { // Something bad happened @@ -155,6 +161,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Make other window visible this.addContact.setVisible(true); + // Trace message + this.getLogger().trace("Returning null : EXIT!"); //NOI18N + // Return value is not supported return null; } @@ -164,8 +173,14 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame */ @Override public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // First only show shutdown status this.updateStatus("shutdown"); //NOI18N + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @@ -174,11 +189,17 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame */ @Override public void enableMainWindow () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Enable it again this.frame.setEnabled(true); // Request focus for this window this.frame.requestFocus(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -208,6 +229,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // All done here this.updateStatus("done"); //NOI18N + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -235,6 +259,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Set flag this.isInitialized = true; + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -253,13 +280,21 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame */ @Override public void shutdownApplication () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // To do this, the frame must be initialized if (!this.isInitialized()) { // Not initalized, so bad call this.getLogger().fatal("Bad call of shutdownApplication(). Please report this."); //NOI18N return; } + + // Call shutdown method this.getClient().getApplication().doShutdown(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -304,6 +339,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * Initializes "add contact" dialog */ private void initAddContactDialog () { + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N + // Instance dialog and set title this.addContact = new JDialog(); this.addContact.setTitle(this.generateFrameTitle("dialog.addContact")); //NOI18N @@ -366,6 +404,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // x)Only for developing: /* DEBUG: */ this.addContact.setVisible(true); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -374,6 +415,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * @param dialog A JDialog instance to this components to */ private void initAddressDataPanel (final JDialog dialog) { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Panel "address" input boxes JPanel addressPanel = new JPanel(); addressPanel.setLayout(new BoxLayout(addressPanel, BoxLayout.Y_AXIS)); @@ -502,6 +546,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Add panel to dialog dialog.add(addressPanel); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -556,12 +603,18 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Init other windows initOtherDialogs(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Initializes the menu system */ private void initMenuSystem () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init menu bar, menu and item instances JMenuBar menuBar = new JMenuBar(); JMenu menu; @@ -644,6 +697,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Add menu bar -> frame this.frame.add(menuBar, BorderLayout.NORTH); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -652,6 +708,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * @param dialog A JDialog instance to this components to */ private void initNameDataPanel (final JDialog dialog) { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Panel "name" input boxes JPanel namePanel = new JPanel(); namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.Y_AXIS)); @@ -718,6 +777,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Finally add panel to dialog dialog.add(namePanel); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -727,6 +789,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * @todo Fill this with life */ private void initOtherDataPanel (final JDialog dialog) { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Panel "other" input boxes JPanel otherPanel = new JPanel(); otherPanel.setLayout(new BoxLayout(otherPanel, BoxLayout.Y_AXIS)); @@ -736,21 +801,33 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Finally add panel to dialog dialog.add(otherPanel); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Initialize other dialogs (e.g. "Add contact") */ private void initOtherDialogs () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init other windows: // 1) Add contact initAddContactDialog(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Initializes status panel */ private void initStatusPanel () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init status label (which needs to be updated this.statusLabel = new JLabel(); this.updateStatus("initializing"); //NOI18N @@ -763,12 +840,18 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Add panel to frame this.frame.add(panel, BorderLayout.SOUTH); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Initializes the table which will show all contacts */ private void initTable () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Instance table model this.dataModel = new ContactTableModel(this.getClient()); @@ -798,6 +881,9 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame // Add pane to frame this.frame.add(scroller, BorderLayout.CENTER); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -806,7 +892,13 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame * @param type Status type */ private void updateStatus (final String type) { + // Trace message + this.getLogger().trace(MessageFormat.format("type={0} - CALLED!", type)); //NOI18N + // Set status message this.statusLabel.setText(this.getBundle().getString(String.format("AddressbookFrame.statusLabel.%s.text", type))); //NOI18N + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java index a8c1a72..8bad87a 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/SwingClient.java @@ -43,8 +43,6 @@ public class SwingClient extends BaseClient implements Client { * @param application Application instance */ public SwingClient (final Application application) { - super(); - // Debug message this.getLogger().trace("CALLED!"); //NOI18N @@ -53,6 +51,9 @@ public class SwingClient extends BaseClient implements Client { // Init frame instance this.frame = AddressbookFrame.getSelfInstance(this); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } @Override @@ -92,6 +93,9 @@ public class SwingClient extends BaseClient implements Client { */ @Override public Contact doEnterOwnData () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Deligate this call to the frame return this.frame.doEnterOwnData(); } @@ -197,7 +201,7 @@ public class SwingClient extends BaseClient implements Client { @Override public void showCurrentMenu () { - // Debug message + // Debug message //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); // Not implemented here diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index 42be4d3..40326c3 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.contact; +import java.text.MessageFormat; import java.util.Objects; import org.mxchange.addressbook.BaseFrameworkSystem; import org.mxchange.addressbook.client.Client; @@ -124,7 +125,7 @@ public class BaseContact extends BaseFrameworkSystem { * @todo Needs a lot improvements */ @Override - public boolean equals (Object object) { + public boolean equals (final Object object) { // Is it same type? if (!(object instanceof BaseContact)) { // Not equal types @@ -239,9 +240,12 @@ public class BaseContact extends BaseFrameworkSystem { * @return "CSV-serialized" version of the stored data */ public String getCsvStringFromStoreableObject () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Get all together String csvString = String.format( - "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n", + "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", this.isOwnContact(), this.getGender().getDatabaseValue(), this.getSurname(), @@ -457,6 +461,15 @@ public class BaseContact extends BaseFrameworkSystem { * @param client Client instance to use */ public void show (final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N + + // The client must be set + if (client == null) { + // Not set + throw new NullPointerException("client is null"); + } + // Display name "box" client.displayNameBox((Contact) this); @@ -476,6 +489,9 @@ public class BaseContact extends BaseFrameworkSystem { * @param countryCode Country code */ public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) { + // Trace message + this.getLogger().trace(MessageFormat.format("street={0},zipCode={1},city={2},countryCode={3} - CALLED!", street, zipCode, city, countryCode)); //NOI18N + // Set all if (street != null) { this.setStreet(street); @@ -489,6 +505,9 @@ public class BaseContact extends BaseFrameworkSystem { if (countryCode != null) { this.setCountryCode(countryCode); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -500,6 +519,9 @@ public class BaseContact extends BaseFrameworkSystem { * @param companyName Company name */ public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) { + // Trace message + this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N + // Set all this.setGender(gender); @@ -512,6 +534,9 @@ public class BaseContact extends BaseFrameworkSystem { if (companyName != null) { this.setCompanyName(companyName); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -525,6 +550,9 @@ public class BaseContact extends BaseFrameworkSystem { * @param comment Comments */ public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) { + // Trace message + this.getLogger().trace(MessageFormat.format("phoneNumber={0},cellphoneNumber={1}faxNumber={2},emailAddress={3},birthday={4},comment={5} - CALLED!", phoneNumber, cellphoneNumber, faxNumber, emailAddress, birthday, comment)); //NOI18N + // Set all if (phoneNumber != null) { this.setPhoneNumber(phoneNumber); @@ -544,6 +572,9 @@ public class BaseContact extends BaseFrameworkSystem { if (comment != null) { this.setComment(comment); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** diff --git a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java index fd6637e..9208a06 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.contact.user; +import java.text.MessageFormat; import org.mxchange.addressbook.contact.Contact; import org.mxchange.addressbook.contact.Gender; import org.mxchange.addressbook.contact.book.BookContact; @@ -42,8 +43,14 @@ public class UserContact extends BookContact implements Contact, StoreableCsv { // Make sure all constructors are called this(); + // Trace message + this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N + // Update all data this.updateNameData(gender, surname, familyName, companyName); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/Base64CsvDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/Base64CsvDatabaseBackend.java index b8ab55d..8f2bb19 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/Base64CsvDatabaseBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/Base64CsvDatabaseBackend.java @@ -54,28 +54,28 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv */ public Base64CsvDatabaseBackend (final String tableName) { // Debug message - this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName)); + this.getLogger().debug(MessageFormat.format("Trying to initialize table {0} ...", tableName)); //NOI18N // Set table name here, too this.setTableName(tableName); // Construct file name - String fileName = String.format("data/table_%s.b64", tableName); + String fileName = String.format("data/table_%s.b64", tableName); //NOI18N // Debug message - this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName)); + this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName)); //NOI18N try { // Try to initialize the storage (file instance) - this.storageFile = new RandomAccessFile(fileName, "rw"); + this.storageFile = new RandomAccessFile(fileName, "rw"); //NOI18N } catch (final FileNotFoundException ex) { // Did not work - this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString())); + this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString())); //NOI18N System.exit(1); } // Output message - this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName)); + this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName)); //NOI18N } /** @@ -87,12 +87,21 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv */ @Override public Iterator contactIterator () throws BadTokenException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + /* * Then read the file into RAM (yes, not perfect for >1000 entries ...) * and get a List back. */ List list = this.readContactList(); + // List must be set + assert (list instanceof List) : "list has not been set."; //NOI18N + + // Trace message + this.getLogger().trace(MessageFormat.format("list.iterator()={0} - EXIT!", list.iterator())); //NOI18N + // Get iterator from list and return it return list.iterator(); } @@ -102,6 +111,9 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv */ @Override public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + try { // Close file this.getStorageFile().close(); @@ -109,6 +121,9 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv this.getLogger().catching(ex); System.exit(1); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -122,7 +137,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv try { length = this.getStorageFile().length(); - this.getLogger().debug(MessageFormat.format("length={0}", length)); + this.getLogger().debug(MessageFormat.format("length={0}", length)); //NOI18N } catch (final IOException ex) { // Length cannot be determined this.getLogger().catching(ex); @@ -130,7 +145,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv } // Return result - this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); + this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); //NOI18N return length; } @@ -139,7 +154,8 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv */ @Override public void rewind () { - this.getLogger().trace("CALLED!"); + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N try { // Rewind underlaying database file @@ -149,7 +165,8 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv System.exit(1); } - this.getLogger().trace("EXIT!"); + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -160,6 +177,15 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv */ @Override public void store (final Storeable object) throws IOException { + // Trace message + this.getLogger().trace(MessageFormat.format("object={0} - CALLED!", object)); //NOI18N + + // Object must not be null + if (object == null) { + // Abort here + throw new NullPointerException("object is null"); + } + // Make sure the instance is there (DataOutput flawor) assert (this.storageFile instanceof DataOutput); @@ -170,13 +196,16 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv String str = csv.getCsvStringFromStoreableObject(); // Debug message - this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str)); + this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str)); //NOI18N // Encode line in BASE-64 - byte[] encoded = Base64.getEncoder().encode(str.trim().getBytes()); + byte[] encoded = Base64.getEncoder().encode(str.getBytes()); // The string is now a valid CSV string this.getStorageFile().write(encoded); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -186,17 +215,20 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv * @param list List instance */ private void addContactToList (final Contact contact, final List list) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + // No null here if (contact == null) { // Throw exception - throw new NullPointerException("contact is null"); + throw new NullPointerException("contact is null"); //NOI18N } else if (list == null) { // Throw exception - throw new NullPointerException("list is null"); + throw new NullPointerException("list is null"); //NOI18N } // Debug message - this.getLogger().debug(MessageFormat.format("contact={0}", contact)); + this.getLogger().debug(MessageFormat.format("contact={0}", contact)); //NOI18N // Is the contact read? if (contact instanceof Contact) { @@ -204,14 +236,17 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv boolean added = list.add(contact); // Debug message - this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); + this.getLogger().debug(MessageFormat.format("contact={0} added={1}", contact, added)); //NOI18N // Has it been added? if (!added) { // Not added - this.getLogger().warn("Contact object has not been added."); + this.getLogger().warn("Contact object has not been added."); //NOI18N } } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -240,7 +275,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv } // Return status - this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof)); + this.getLogger().trace(MessageFormat.format("isEof={0} : EXIT!", isEof)); //NOI18N return isEof; } @@ -251,7 +286,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv * @return A list with Contact instances */ private List readContactList () throws BadTokenException { - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // First rewind this.rewind(); @@ -260,7 +295,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv int lines = Math.round(this.length() / 140 + 0.5f); // Debug message - this.getLogger().debug(MessageFormat.format("lines={0}", lines)); + this.getLogger().debug(MessageFormat.format("lines={0}", lines)); //NOI18N // Instance list // @TODO The maximum length could be guessed from file size? @@ -283,11 +318,11 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv line = this.readLine(); // Debug message - this.getLogger().debug(MessageFormat.format("line={0}", line)); + this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N // Then tokenize it // @TODO Move this into separate method - tokenizer = new StringTokenizer(line, ";"); + tokenizer = new StringTokenizer(line, ";"); //NOI18N // Reset variables count = 0; @@ -309,28 +344,28 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv } // Debug message - this.getLogger().debug(MessageFormat.format("token={0}", token)); + this.getLogger().debug(MessageFormat.format("token={0}", token)); //NOI18N // Verify token, it must have double-quotes on each side - if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { + if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { //NOI18N // Something bad was read - throw new BadTokenException(MessageFormat.format("Token {0} at position {1} has not double-quotes on both ends.", token, count)); + throw new BadTokenException(MessageFormat.format("Token {0} at position {1} has not double-quotes on both ends.", 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")) { + if (strippedToken.equals("null")) { //NOI18N // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken)); + 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)); + this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken)); //NOI18N // Now, let's try a number check, if no null if (strippedToken != null) { @@ -339,7 +374,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv num = Long.valueOf(strippedToken); // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); + this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken)); //NOI18N } catch (final NumberFormatException ex) { // No number, then set default num = null; @@ -347,27 +382,27 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv } // Now, let's try a boolean check, if no null - if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { + if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) { //NOI18N // Debug message - this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken)); + 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)); + 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")))) { + 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)); + this.getLogger().debug(MessageFormat.format("strippedToken={0},gender={1}", strippedToken, gender)); //NOI18N // This instance must be there - assert (gender instanceof Gender) : "gender is not set by Gender.fromChar(" + strippedToken + ")"; + assert (gender instanceof Gender) : "gender is not set by Gender.fromChar(" + strippedToken + ")"; //NOI18N } // Now it depends on the counter which position we need to check @@ -376,18 +411,18 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv assert ((bool instanceof Boolean)); // Debug message - this.getLogger().debug(MessageFormat.format("bool={0}", bool)); + this.getLogger().debug(MessageFormat.format("bool={0}", bool)); //NOI18N // Is it own contact? if (true == bool) { // Debug message - this.getLogger().debug("Creating UserContact object ..."); + this.getLogger().debug("Creating UserContact object ..."); //NOI18N // Own entry contact = new UserContact(); } else { // Debug message - this.getLogger().debug("Creating BookContact object ..."); + this.getLogger().debug("Creating BookContact object ..."); //NOI18N // Other contact contact = new BookContact(); @@ -395,108 +430,108 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv break; case 1: // Gender - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateNameData(gender, null, null, null); break; case 2: // Surname - assert (contact instanceof Contact) : "First token was not boolean"; - assert (gender instanceof Gender) : "gender instance is not set"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N + assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N // Update data contact.updateNameData(gender, strippedToken, null, null); break; case 3: // Family name - assert (contact instanceof Contact) : "First token was not boolean"; - assert (gender instanceof Gender) : "gender instance is not set"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N + assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N // Update data contact.updateNameData(gender, null, strippedToken, null); break; case 4: // Company name - assert (contact instanceof Contact) : "First token was not boolean"; - assert (gender instanceof Gender) : "gender instance is not set"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N + assert (gender instanceof Gender) : "gender instance is not set"; //NOI18N // Update data contact.updateNameData(gender, null, null, strippedToken); break; case 5: // Street number - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateAddressData(strippedToken, 0, null, null); break; case 6: // ZIP code - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateAddressData(null, num, null, null); break; case 7: // City name - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateAddressData(null, 0, strippedToken, null); break; case 8: // Country code - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateAddressData(null, 0, null, strippedToken); break; case 9: // Phone number - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(strippedToken, null, null, null, null, null); break; case 10: // Fax number - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(null, strippedToken, null, null, null, null); break; case 11: // Cellphone number - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(null, null, strippedToken, null, null, null); break; case 12: // Email address - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(null, null, null, strippedToken, null, null); break; case 13: // Birthday - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(null, null, null, null, strippedToken, null); break; case 14: // Birthday - assert (contact instanceof Contact) : "First token was not boolean"; + assert (contact instanceof Contact) : "First token was not boolean"; //NOI18N // Update data contact.updateOtherData(null, null, null, null, null, strippedToken); break; default: // New data entry - this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); + this.getLogger().warn(MessageFormat.format("Will not handle unknown data {0} at index {1}", strippedToken, count)); //NOI18N break; } @@ -505,14 +540,14 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv } // The contact instance should be there now - assert (contact instanceof Contact) : "contact is not set: " + contact; + assert (contact instanceof Contact) : "contact is not set: " + contact; //NOI18N // Add contact this.addContactToList(contact, list); } // Return finished list - this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); + this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); //NOI18N return list; } @@ -522,6 +557,9 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv * @return Read line from file */ private String readLine () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init input String input = null; @@ -538,6 +576,9 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Csv this.getLogger().catching(ex); } + // Trace message + this.getLogger().trace(MessageFormat.format("input={0} - EXIT!", input)); //NOI18N + // Return read string or null return input; } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java index 43955ee..5b62847 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java @@ -60,7 +60,13 @@ public class BaseDatabaseFrontend extends BaseFrameworkSystem { * Initialize backend */ protected void initBackend () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Instance backend this.backend = new Base64CsvDatabaseBackend(this.getTableName()); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java index cfd7ec1..30535fd 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java @@ -17,13 +17,14 @@ package org.mxchange.addressbook.database.frontend.contact; import java.io.IOException; +import java.text.MessageFormat; import java.util.Iterator; import java.util.List; -import org.mxchange.addressbook.exceptions.BadTokenException; import org.mxchange.addressbook.contact.Contact; import org.mxchange.addressbook.database.backend.csv.CsvBackend; import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend; import org.mxchange.addressbook.database.storage.Storeable; +import org.mxchange.addressbook.exceptions.BadTokenException; import org.mxchange.addressbook.manager.contact.ContactManager; /** @@ -42,6 +43,15 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con // 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); } @@ -52,8 +62,11 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con protected ContactDatabaseFrontend () { super(); + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Set "table" name - this.setTableName("contacts"); + this.setTableName("contacts"); //NOI18N // Initalize backend this.initBackend(); @@ -64,8 +77,14 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con */ @Override public void doShutdown () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Shutdown backend this.getBackend().doShutdown(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -73,6 +92,9 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con */ @Override public void flushAllContacts () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Get full list List contacts = this.getContactManager().getList(); @@ -96,6 +118,9 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con System.exit(1); } } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -104,6 +129,9 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con */ @Override public void readAllContacts () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Get iterator and case it CsvBackend backend = (CsvBackend) this.getBackend(); @@ -127,5 +155,8 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con // Add contact instance to manager this.getContactManager().addContact(contact); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java b/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java index 16ec145..f27cfb3 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/application/ApplicationManager.java @@ -32,6 +32,12 @@ public class ApplicationManager extends BaseManager implements ManageableApplica * @return */ public static final ManageableApplication getManager (final Application application) { + // Application instance must be set + if (application == null) { + // Abort here + throw new NullPointerException("application is null"); //NOI18N + } + // Get manager ManageableApplication manager = new ApplicationManager(application); @@ -47,16 +53,31 @@ public class ApplicationManager extends BaseManager implements ManageableApplica private ApplicationManager (final Application application) { super(); + // Application instance must be set + if (application == null) { + // Abort here + throw new NullPointerException("application is null"); //NOI18N + } + + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Set application instance this.setApplication(application); } @Override public void start () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Bootstrap application this.getApplication().doBootstrap(); // Run the main loop this.getApplication().doMainLoop(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index f502e1e..128aeeb 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -64,6 +64,18 @@ public class ContactManager extends BaseManager implements ManageableContact { // Always call super constructor first super(); + // Trace message + this.getLogger().trace(MessageFormat.format("maxContacts={0},client={1} - CALLED!", maxContacts, client)); //NOI18N + + // Make sure all parameters are set correctly + if (maxContacts <= 0) { + // Must not be zero or smaller + throw new IllegalArgumentException(MessageFormat.format("maxContacts is below or zero: {0}", maxContacts)); //NOI18N + } else if (client == null) { + // Abort here + throw new NullPointerException("client is null"); //NOI18N + } + // Set client instance this.setClient(client); @@ -93,9 +105,22 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void addContact (final Contact contact) { - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N + + // 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.contacts.add(contact); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -103,19 +128,27 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void doAddOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("Not supported yet."); //NOI18N } /** * Let the user change address data * * @param contact Instance to change data - * @param client Client instance to call back */ @Override - public void doChangeAddressData (final Contact contact, final Client client) { + 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 + } + // First display it again - client.displayAddressBox(contact); + this.getClient().displayAddressBox(contact); // Is it own data? if (contact.isOwnContact()) { @@ -123,23 +156,34 @@ public class ContactManager extends BaseManager implements ManageableContact { this.getClient().doChangeOwnAddressData(contact); } else { // Other contact's address data to change - throw new UnsupportedOperationException("Changing contact entries not finished."); + throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N } // Flush whole list this.flush(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Let the user change "name data" * * @param contact Instance to change data - * @param client Client instance to call back */ @Override - public void doChangeNameData (final Contact contact, final Client client) { + 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 + } + // First display them again - client.displayNameBox(contact); + this.getClient().displayNameBox(contact); // Is this own data? if (contact.isOwnContact()) { @@ -147,11 +191,13 @@ public class ContactManager extends BaseManager implements ManageableContact { this.getClient().doChangeOwnNameData(contact); } else { // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); + throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N } // Flush whole list this.flush(); + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -159,18 +205,26 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void doChangeOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("Not supported yet."); //NOI18N } /** * Let the user change other data * * @param contact Instance to change data - * @param client Client instance to call back * @todo Didn't handle birthday */ @Override - public void doChangeOtherData (final Contact contact, final Client client) { + 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 + } + // First display them again this.getClient().displayOtherDataBox(contact); @@ -180,11 +234,14 @@ public class ContactManager extends BaseManager implements ManageableContact { this.getClient().doChangeOwnOtherData(contact); } else { // Then re-ask them ... - throw new UnsupportedOperationException("Changing contact entries not finished."); + throw new UnsupportedOperationException("Changing contact entries not finished."); //NOI18N } // Flush whole list this.flush(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -192,13 +249,16 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @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."); + this.getClient().outputMessage("Sie haben noch nicht Ihre Daten eingegeben."); //NOI18N // Skip any below code return; @@ -219,6 +279,9 @@ public class ContactManager extends BaseManager implements ManageableContact { } catch (final UnhandledUserChoiceException ex) { this.getLogger().catching(ex); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -226,7 +289,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void doDeleteOtherAddress () { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("Not supported yet."); //NOI18N } /** @@ -234,6 +297,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void doEnterOwnData () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Deligate this call to the client Contact contact = this.getClient().doEnterOwnData(); @@ -242,16 +308,19 @@ public class ContactManager extends BaseManager implements ManageableContact { // 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."); + throw new UnsupportedOperationException("Not supported yet."); //NOI18N } @Override public void doSearchContacts () { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("Not supported yet."); //NOI18N } /** @@ -259,8 +328,14 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @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 } /** @@ -270,6 +345,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnCellNumber () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Handynummer an: ", true); } @@ -280,6 +358,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnCity () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(3, 50, "Bitte geben Sie Ihre Wohnort ein: ", false); } @@ -290,6 +371,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnComment () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(0, 100, "Kommentar zu Ihrem Eintrag: ", true); } @@ -300,6 +384,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnCompanyName () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true); } @@ -310,6 +397,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnCountryCode () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(2, 2, "Bitte geben Sie den zweistelligen Ländercode von Ihrem Land ein: ", false).toUpperCase(); } @@ -320,6 +410,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnEmailAddress () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(10, 50, "Bitte geben Sie Ihre Email-Adresse ein: ", true); } @@ -330,6 +423,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnFamilyName () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false); } @@ -340,6 +436,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnFaxNumber () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Faxnummer an: ", true); } @@ -350,6 +449,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public Gender enterOwnGender () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): "); } @@ -360,6 +462,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnPhoneNumber () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(5, 30, "Bitte geben Sie Ihre Telefonnummer an: ", true); } @@ -370,6 +475,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnStreet () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Strasse und Hausnummer ein: ", false); } @@ -380,6 +488,9 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String enterOwnSurname () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false); } @@ -390,12 +501,15 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public int enterOwnZipCode () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + return this.getClient().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"; + assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N return this.columnNames.size(); } @@ -408,7 +522,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public String getColumnName (final int columnIndex) { - assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; + assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N // Get column name at index return this.columnNames.get(columnIndex); @@ -421,7 +535,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public List getList () { - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N return Collections.unmodifiableList(this.contacts); } @@ -434,9 +548,9 @@ public class ContactManager extends BaseManager implements ManageableContact { @Override public boolean isOwnContactAdded () { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N // Default is not added boolean isAdded = false; @@ -463,7 +577,7 @@ public class ContactManager extends BaseManager implements ManageableContact { } // Trace message - this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); + this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N // Return result return isAdded; @@ -477,10 +591,19 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public void registerContact (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 + } + // Sanity check if (contact == null) { // Abort here - throw new NullPointerException("contact is null"); + throw new NullPointerException("contact is null"); //NOI18N } // Check if contact is found @@ -493,7 +616,7 @@ public class ContactManager extends BaseManager implements ManageableContact { } // Debug message - /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); + /* NOISY-DEBUG: */ this.getLogger().debug(MessageFormat.format("Adding '{0}' '{1}' at pos '{2}' ...", contact.getSurname(), contact.getFamilyName(), this.size())); //NOI18N // Add contact to internal list this.addContact(contact); @@ -509,7 +632,7 @@ public class ContactManager extends BaseManager implements ManageableContact { */ @Override public final int size () { - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N return this.contacts.size(); } @@ -517,10 +640,10 @@ public class ContactManager extends BaseManager implements ManageableContact { * Fills the column names array with strings from bundle */ private void fillColumnNamesFromBundle () { - assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; + assert (this.columnNames instanceof List) : "this.columnNames is not initialized"; //NOI18N // Debug message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // First get an iterator from key set to iterate over Iterator iterator = this.getBundle().keySet().iterator(); @@ -531,9 +654,9 @@ public class ContactManager extends BaseManager implements ManageableContact { String key = iterator.next(); // Does the key start with ContactManager.columnName ? - if (key.startsWith("ContactManager.columnName")) { + if (key.startsWith("ContactManager.columnName")) { //NOI18N // This is the wanted entry. - this.getLogger().debug(MessageFormat.format("key={0}", key)); + this.getLogger().debug(MessageFormat.format("key={0}", key)); //NOI18N // So add it this.columnNames.add(this.getBundle().getString(key)); @@ -541,15 +664,21 @@ public class ContactManager extends BaseManager implements ManageableContact { } // Debug message - this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); + this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N } /** * Flushes all entries by calling database backend */ private void flush () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Flusgh all this.getContactDatabase().flushAllContacts(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -567,7 +696,10 @@ public class ContactManager extends BaseManager implements ManageableContact { * @return Contact instance or null */ private Contact getOwnContact () { - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N + + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N // Now get it back from address book, first get an iterator Iterator iterator = this.contacts.iterator(); @@ -589,6 +721,9 @@ public class ContactManager extends BaseManager implements ManageableContact { } } + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N + // Return instance or null return contact; } @@ -600,7 +735,16 @@ public class ContactManager extends BaseManager implements ManageableContact { * @return TRUE if found, FALSE if not found */ private boolean isContactAlreadyAdded (final Contact checkContact) throws NullPointerException { - assert (this.contacts instanceof List) : "this.contacts is not initialized"; + assert (this.contacts instanceof List) : "this.contacts is not initialized"; //NOI18N + + // Trace message + this.getLogger().trace(MessageFormat.format("checkContact={0} - CALLED!", checkContact)); //NOI18N + + // Contact instance must not be null + if (checkContact == null) { + // Abort here + throw new NullPointerException("checkContact is null"); + } // Default is not found boolean isFound = false; @@ -625,6 +769,9 @@ public class ContactManager extends BaseManager implements ManageableContact { } } + // Trace message + this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N + // Return result return isFound; } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java index 2ed123c..6c4ff93 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ManageableContact.java @@ -17,7 +17,6 @@ package org.mxchange.addressbook.manager.contact; import java.util.List; -import org.mxchange.addressbook.client.Client; import org.mxchange.addressbook.contact.Contact; import org.mxchange.addressbook.contact.Gender; import org.mxchange.addressbook.manager.Manageable; @@ -169,18 +168,16 @@ public interface ManageableContact extends Manageable { * of given Contact instance. * * @param contact Instance to change data - * @param client Client instance to call back */ - public void doChangeAddressData (final Contact contact, final Client client); + 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 - * @param client Client instance to call back */ - public void doChangeNameData (final Contact contact, final Client client); + public void doChangeNameData (final Contact contact); /** * Let the user change other address @@ -191,9 +188,8 @@ public interface ManageableContact extends Manageable { * The user can change other data, like phone numbers or comments. * * @param contact Instance to change data - * @param client Client instance to call back */ - public void doChangeOtherData (final Contact contact, final Client client); + public void doChangeOtherData (final Contact contact); /** * Let the user change own data diff --git a/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java index 418a7cb..af29b11 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.menu; +import java.text.MessageFormat; import java.util.List; import org.apache.logging.log4j.Logger; import org.mxchange.addressbook.BaseFrameworkSystem; @@ -40,15 +41,27 @@ public class AddressbookMenu extends BaseFrameworkSystem { // Get logger Logger log = new AddressbookMenu().getLogger(); + // Trace call + log.trace(MessageFormat.format("menuList={0},menuType={1},client={2} - CALLED!", menuList, menuType, client)); //NOI18N + + // Some instances must be set + if (menuList == null) { + // Abort here + throw new NullPointerException("menuList is null"); //NOI18N + } else if (client == null) { + // Abort here + throw new NullPointerException("contact is null"); //NOI18N + } + // Get list size int size = menuList.size(); // Debug message - log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ..."); + log.debug(MessageFormat.format("Adding menu for '{0}' (old size: '{1}') ...", menuType, size)); //NOI18N // Depends on type switch (menuType) { - case "main": // Main menu + case "main": // Main menu //NOI18N // Enter own data menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen")); @@ -75,7 +88,7 @@ public class AddressbookMenu extends BaseFrameworkSystem { break; default: // Not supported - log.error("Menu type '" + menuType + "' ont supported"); + log.error(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N System.exit(1); } diff --git a/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java index 73f3422..de12ad4 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/BaseMenu.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.menu; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -65,6 +66,15 @@ public class BaseMenu extends BaseFrameworkSystem { * @param client Client instance to call back */ public void show (final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("client={0} CALLED!", client)); //NOI18N + + // Client must not be null + if (client == null) { + // Abort here + throw new NullPointerException("client is null"); //NOI18N + } + // Get values Iterator iterator = this.menuList.iterator(); @@ -79,6 +89,9 @@ public class BaseMenu extends BaseFrameworkSystem { // Show this item item.show(client); } + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -97,7 +110,13 @@ public class BaseMenu extends BaseFrameworkSystem { * @param client CLient to call back */ protected void initMenu (final String menuType, final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N + // Init menu list this.menuList = new ArrayList<>(5); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java b/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java index a8d5bd3..f1c1f2c 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/MenuTools.java @@ -62,11 +62,11 @@ public class MenuTools extends BaseFrameworkSystem { while (iterator.hasNext()) { // Get item SelectableMenuItem item = iterator.next(); - //* NOISY-DEBUG: */ logger.debug("item=" + item); + //* NOISY-DEBUG: */ logger.debug("item=" + item); // Get access key from item and add it to the array accessKeys[i] = item.getAccessKey(); - //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]); + //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]); // Increment counter i++; diff --git a/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java index 7064473..6eff64f 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/console/ConsoleMenu.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.menu.console; +import java.text.MessageFormat; import org.mxchange.addressbook.client.Client; import org.mxchange.addressbook.menu.AddressbookMenu; import org.mxchange.addressbook.menu.BaseMenu; @@ -34,6 +35,16 @@ public class ConsoleMenu extends BaseMenu implements Menu { * @param client CLient to call back */ public ConsoleMenu (final String menuType, final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N + + // Client must not be null + if (client == null) { + // Abort here + throw new NullPointerException("client is null"); + } + + // Init menu this.initMenu(menuType, client); // Add all items diff --git a/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java index 7fe38bb..8b863cd 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/item/console/ConsoleMenuItem.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.menu.item.console; +import java.text.MessageFormat; import org.mxchange.addressbook.client.Client; import org.mxchange.addressbook.menu.item.BaseMenuItem; import org.mxchange.addressbook.menu.item.SelectableMenuItem; @@ -43,8 +44,8 @@ public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem * @param text Text to show to user */ public ConsoleMenuItem (final char accessKey, final String text) { - this.accessKey = accessKey; - this.text = text; + this.setAccessKey(accessKey); + this.setText(text); } /** @@ -69,8 +70,20 @@ public class ConsoleMenuItem extends BaseMenuItem implements SelectableMenuItem @Override public void show (final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N + + // Client must not be null + if (client == null) { + // Abort here + throw new NullPointerException("client is null"); + } + // Call-back client over menu client.showEntry(this); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** diff --git a/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java b/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java index e199165..c55261c 100644 --- a/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java +++ b/Addressbook/src/org/mxchange/addressbook/model/BaseModel.java @@ -37,6 +37,9 @@ public class BaseModel extends BaseFrameworkSystem { * Protected constructor */ protected BaseModel () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Init listener list this.eventListenerList = new EventListenerList(); } @@ -47,11 +50,23 @@ public class BaseModel extends BaseFrameworkSystem { * @param listener Listener instance */ public void addListDataListener (final ListDataListener listener) { + // Trace message + this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N + + // Listener must not be null + if (listener == null) { + // Abort here + throw new NullPointerException("listener is null"); + } + // Debug message this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass())); // Remove listener this.eventListenerList.add(ListDataListener.class, listener); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -60,11 +75,23 @@ public class BaseModel extends BaseFrameworkSystem { * @param listener Lister instance */ public void addTableModelListener (final TableModelListener listener) { + // Trace message + this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N + + // Listener must not be null + if (listener == null) { + // Abort here + throw new NullPointerException("listener is null"); + } + // Debug message this.getLogger().debug(MessageFormat.format("Adding listener {0} ...", listener.getClass())); // Add listener this.eventListenerList.add(TableModelListener.class, listener); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -73,11 +100,23 @@ public class BaseModel extends BaseFrameworkSystem { * @param listener Listener instance */ public void removeListDataListener (final ListDataListener listener) { + // Trace message + this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N + + // Listener must not be null + if (listener == null) { + // Abort here + throw new NullPointerException("listener is null"); + } + // Debug message this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass())); // Remove listener this.eventListenerList.remove(ListDataListener.class, listener); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -86,10 +125,22 @@ public class BaseModel extends BaseFrameworkSystem { * @param listener Listener instance */ public void removeTableModelListener (final TableModelListener listener) { + // Trace message + this.getLogger().trace("listener=" + listener + " - CALLED!"); //NOI18N + + // Listener must not be null + if (listener == null) { + // Abort here + throw new NullPointerException("listener is null"); + } + // Debug message this.getLogger().debug(MessageFormat.format("Removing listener {0} ...", listener.getClass())); // Remove listener this.eventListenerList.remove(TableModelListener.class, listener); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java b/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java index ef125a0..30307c6 100644 --- a/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java +++ b/Addressbook/src/org/mxchange/addressbook/model/contact/ContactTableModel.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.model.contact; +import java.text.MessageFormat; import javax.swing.table.TableModel; import org.mxchange.addressbook.client.Client; import org.mxchange.addressbook.model.BaseModel; @@ -36,6 +37,15 @@ public class ContactTableModel extends BaseModel implements TableModel { // Parent super constructor super(); + // Trace message + this.getLogger().trace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N + + // Client must not be null + if (client == null) { + // Abort here + throw new NullPointerException("client is null"); //NOI18N + } + // Set client this.setClient(client); } -- 2.39.5