From 7c0d0029902672c241249c99cf319c6f43791291 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Jul 2015 13:39:32 +0200 Subject: [PATCH] Added 'final' keyword to getters/setters as it makes no sense overwriting them. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../addressbook/BaseFrameworkSystem.java | 2 +- .../FrameAlreadyInitializedException.java | 3 +- .../addressbook/FrameworkInterface.java | 1 + .../addressbook/client/BaseClient.java | 10 +- .../client/console/ConsoleClient.java | 10 +- .../client/gui/AddressbookFrame.java | 31 +++-- .../addressbook/client/gui/ClientFrame.java | 16 +-- .../addressbook/contact/BaseContact.java | 128 +++++++++--------- .../addressbook/contact/user/UserContact.java | 6 +- .../database/backend/csv/CsvBackend.java | 1 + .../backend/csv/CsvDatabaseBackend.java | 21 ++- .../frontend/BaseDatabaseFrontend.java | 4 +- .../addressbook/manager/BaseManager.java | 2 +- .../manager/contact/ContactManager.java | 12 +- 14 files changed, 139 insertions(+), 108 deletions(-) diff --git a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java index 680474d..49ac02e 100644 --- a/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java +++ b/Addressbook/src/org/mxchange/addressbook/BaseFrameworkSystem.java @@ -160,7 +160,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * * @return Resource bundle */ - protected ResourceBundle getBundle () { + protected final ResourceBundle getBundle () { return this.bundle; } } diff --git a/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java b/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java index 1709f0b..0a4be3c 100644 --- a/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java +++ b/Addressbook/src/org/mxchange/addressbook/FrameAlreadyInitializedException.java @@ -17,7 +17,8 @@ package org.mxchange.addressbook; /** - * + * This exception is thrown when initFrame() is called twice. + * * @author Roland Haeder */ public class FrameAlreadyInitializedException extends Exception { diff --git a/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java index 2158bdb..5236877 100644 --- a/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java +++ b/Addressbook/src/org/mxchange/addressbook/FrameworkInterface.java @@ -21,6 +21,7 @@ import org.mxchange.addressbook.client.Client; import org.mxchange.addressbook.manager.contact.ManageableContact; /** + * A general interface which should be always expanded * * @author Roland Haeder */ diff --git a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java index 0282c91..399a6c1 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/BaseClient.java @@ -69,7 +69,7 @@ public abstract class BaseClient extends BaseFrameworkSystem { /** * Enables the client */ - public void enableIsRunning () { + public final void enableIsRunning () { this.isRunning = true; } @@ -78,7 +78,7 @@ public abstract class BaseClient extends BaseFrameworkSystem { * * @return the currentMenu */ - public String getCurrentMenu () { + public final String getCurrentMenu () { return this.currentMenu; } @@ -86,7 +86,7 @@ public abstract class BaseClient extends BaseFrameworkSystem { * Current menu choice * @param currentMenu the currentMenu to set */ - public void setCurrentMenu (final String currentMenu) { + public final void setCurrentMenu (final String currentMenu) { this.currentMenu = currentMenu; } @@ -116,7 +116,7 @@ public abstract class BaseClient extends BaseFrameworkSystem { * * @return Whether the application is still active */ - public boolean isRunning () { + public final boolean isRunning () { // In console client, 0 may have been used return this.isRunning; } @@ -124,7 +124,7 @@ public abstract class BaseClient extends BaseFrameworkSystem { /** * Disables running state, so the main loop can abort. */ - protected void disableIsRunning () { + protected final void disableIsRunning () { this.isRunning = false; } diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index b97600e..8d55309 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -414,25 +414,25 @@ public class ConsoleClient extends BaseClient implements Client { public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { // 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); break; - + case 'a': // Address data this.getContactManager().doChangeAddressData(contact, this); break; - + case 'o': // Other data this.getContactManager().doChangeOtherData(contact, this); break; - + case 'x': // Exit this menu // Ignored as it should go back break; - + default: // @TODO throw own exception throw new UnhandledUserChoiceException(MessageFormat.format("Choice '{0}' not handled yet.", choice)); diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java index 29151b1..fe9d47b 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/AddressbookFrame.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.client.gui; +import java.text.MessageFormat; import javax.swing.JFrame; import org.mxchange.addressbook.BaseFrameworkSystem; import org.mxchange.addressbook.FrameAlreadyInitializedException; @@ -62,11 +63,12 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame /** * Creates an instance of this frame with a client instance + * * @param client */ private AddressbookFrame (final Client client) { // Debug line - this.getLogger().debug("Initializing Swing frame ..."); + this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); // Set frame instance this.frame = new JFrame(AddressbookApplication.printableTitle()); @@ -75,18 +77,16 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame this.setClient(client); } - @Override - public void setVisible (final boolean visible) { - throw new UnsupportedOperationException("Not supported yet."); - } - /** - * Setups the frame + * Setups the frame, do not set isInitialized here * * @param client Client instance */ @Override public void setupFrame (final Client client) { + // Debug line + this.getLogger().trace(MessageFormat.format("client={0}: CALLED!", client)); + // Has the user entered own data? if (this.getClient().getContactManager().isOwnContactAdded()) { // Debug message @@ -109,8 +109,11 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame */ @Override public void initFrame () throws FrameAlreadyInitializedException { + // Debug line + this.getLogger().trace("CALLED!"); + // Has this frame been initialized? - if (this.isInitialized) { + if (this.isInitialized()) { // Throw exception throw new FrameAlreadyInitializedException(); } @@ -122,10 +125,22 @@ public class AddressbookFrame extends BaseFrameworkSystem implements ClientFrame this.isInitialized = true; } + /** + * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. + * + * @return Field isInitialized + */ + @Override + public final boolean isInitialized () { + return this.isInitialized; + } + /** * Initialize components */ private void initComponents () { + // Debug line + this.getLogger().trace("CALLED!"); } } diff --git a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java index 06af9bb..0c5ab4d 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java +++ b/Addressbook/src/org/mxchange/addressbook/client/gui/ClientFrame.java @@ -21,18 +21,11 @@ import org.mxchange.addressbook.FrameworkInterface; import org.mxchange.addressbook.client.Client; /** + * An interface for applications with a frame * * @author Roland Haeder */ public interface ClientFrame extends FrameworkInterface { - - /** - * From JFrame - * - * @param visible Set visibility - */ - public void setVisible (boolean visible); - /** * Setups the frame (and starts it). You have to call initFrame() before you * can call this method. @@ -47,4 +40,11 @@ public interface ClientFrame extends FrameworkInterface { * @throws org.mxchange.addressbook.FrameAlreadyInitializedException If this method has been called twice */ public void initFrame () throws FrameAlreadyInitializedException; + + /** + * Returns field isInitialized. This flag indicates whether this frame has been initialized or not. + * + * @return Field isInitialized + */ + public boolean isInitialized (); } diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index 2a1ecb7..975ce3f 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -152,15 +152,6 @@ public class BaseContact extends BaseFrameworkSystem { return this.birthday; } - /** - * Birth day - * - * @param birthday the birthday to set - */ - public void setBirthday (final String birthday) { - this.birthday = birthday; - } - /** * Cellphone number * @@ -170,15 +161,6 @@ public class BaseContact extends BaseFrameworkSystem { return this.cellphoneNumber; } - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set - */ - public void setCellphoneNumber (final String cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - /** * City * @@ -193,7 +175,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param city the city to set */ - public void setCity (final String city) { + private void setCity (final String city) { this.city = city; } @@ -211,7 +193,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param comment the comment to set */ - public void setComment (final String comment) { + private void setComment (final String comment) { this.comment = comment; } @@ -229,7 +211,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param companyName the companyName to set */ - public void setCompanyName (final String companyName) { + private void setCompanyName (final String companyName) { this.companyName = companyName; } @@ -247,7 +229,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param countryCode the countryCode to set */ - public void setCountryCode (final String countryCode) { + private void setCountryCode (final String countryCode) { this.countryCode = countryCode; } @@ -295,7 +277,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param emailAddress the emailAddress to set */ - public void setEmailAddress (final String emailAddress) { + private void setEmailAddress (final String emailAddress) { this.emailAddress = emailAddress; } @@ -313,7 +295,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param familyName the familyName to set */ - public void setFamilyName (final String familyName) { + private void setFamilyName (final String familyName) { this.familyName = familyName; } @@ -331,7 +313,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param faxNumber the faxNumber to set */ - public void setFaxNumber (final String faxNumber) { + private void setFaxNumber (final String faxNumber) { this.faxNumber = faxNumber; } @@ -349,7 +331,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param gender the gender to set */ - public void setGender (final char gender) { + private void setGender (final char gender) { this.gender = gender; } @@ -362,15 +344,6 @@ public class BaseContact extends BaseFrameworkSystem { return this.houseNumber; } - /** - * House number - * - * @param houseNumber the houseNumber to set - */ - public void setHouseNumber (final int houseNumber) { - this.houseNumber = houseNumber; - } - /** * Phone number * @@ -380,15 +353,6 @@ public class BaseContact extends BaseFrameworkSystem { return this.phoneNumber; } - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ - public void setPhoneNumber (final String phoneNumber) { - this.phoneNumber = phoneNumber; - } - /** * Street * @@ -403,7 +367,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @param street the street to set */ - public void setStreet (final String street) { + protected final void setStreet (final String street) { this.street = street; } @@ -412,19 +376,10 @@ public class BaseContact extends BaseFrameworkSystem { * * @return the surname */ - public String getSurname () { + public final String getSurname () { return this.surname; } - /** - * Surname - * - * @param surname the surname to set - */ - public void setSurname (final String surname) { - this.surname = surname; - } - /** * Some "getter" for a translated/human-readable gender * @return gender Human-readable gender @@ -461,7 +416,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @return the zipCode */ - public long getZipCode () { + public final long getZipCode () { return this.zipCode; } @@ -470,10 +425,10 @@ public class BaseContact extends BaseFrameworkSystem { * * @param zipCode the zipCode to set */ - public void setZipCode (final long zipCode) { + protected final void setZipCode (final long zipCode) { this.zipCode = zipCode; } - + @Override public int hashCode () { int hash = 7; @@ -488,7 +443,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @return Own data? */ - public boolean isOwnContact () { + public final boolean isOwnContact () { return this.ownContact; } @@ -500,11 +455,11 @@ public class BaseContact extends BaseFrameworkSystem { public void show (final Client client) { // Display name "box" client.displayNameBox((Contact) this); - - // Display address "box" + + // Display address "box" client.displayAddressBox((Contact) this); - - // Display other data "box" + + // Display other data "box" client.displayOtherDataBox((Contact) this); } @@ -589,7 +544,52 @@ public class BaseContact extends BaseFrameworkSystem { * Enables the flag "own data" which signals that this contact is the user's * own data. */ - protected void enableFlagOwnContact () { + protected final void enableFlagOwnContact () { this.ownContact = true; } + + /** + * Surname + * + * @param surname the surname to set + */ + protected final void setSurname (final String surname) { + this.surname = surname; + } + + /** + * Phone number + * + * @param phoneNumber the phoneNumber to set + */ + protected final void setPhoneNumber (final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /** + * House number + * + * @param houseNumber the houseNumber to set + */ + protected final void setHouseNumber (final int houseNumber) { + this.houseNumber = houseNumber; + } + + /** + * Cellphone number + * + * @param cellphoneNumber the cellphoneNumber to set + */ + protected final void setCellphoneNumber (final String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + /** + * Birth day + * + * @param birthday the birthday to set + */ + protected final void setBirthday (final String birthday) { + this.birthday = birthday; + } } diff --git a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java index 1f9b141..bf0e522 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/user/UserContact.java @@ -40,10 +40,8 @@ public class UserContact extends BookContact implements Contact, StoreableCsv { // Make sure all constructors are called this(); - this.setGender(gender); - this.setSurname(surname); - this.setFamilyName(familyName); - this.setCompanyName(companyName); + // Update all data + this.updateNameData(gender, surname, familyName, companyName); } /** diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java index 704cbb6..f310588 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvBackend.java @@ -31,6 +31,7 @@ public interface CsvBackend extends DatabaseBackend { * Gets an iterator for contacts * * @return Iterator for contacts + * @throws org.mxchange.addressbook.BadTokenException If the CSV token is badly formulated */ public Iterator contactIterator () throws BadTokenException; } diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java index 0bc97f3..9f3e832 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/csv/CsvDatabaseBackend.java @@ -100,7 +100,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken public void doShutdown () { try { // Close file - this.storageFile.close(); + this.getStorageFile().close(); } catch (final IOException ex) { this.getLogger().catching(ex); System.exit(1); @@ -117,7 +117,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken long length = 0; try { - length = this.storageFile.length(); + length = this.getStorageFile().length(); this.getLogger().debug(MessageFormat.format("length={0}", length)); } catch (final IOException ex) { // Length cannot be determined @@ -139,7 +139,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken try { // Rewind underlaying database file - this.storageFile.seek(0); + this.getStorageFile().seek(0); } catch (final IOException ex) { this.getLogger().catching(ex); System.exit(1); @@ -169,7 +169,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str)); // The string is now a valid CSV string - this.storageFile.writeBytes(str); + this.getStorageFile().writeBytes(str); } /** @@ -198,6 +198,15 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken } } + /** + * Returns storage file + * + * @return Storage file instance + */ + private RandomAccessFile getStorageFile () { + return this.storageFile; + } + /** * Checks whether end of file has been reached * @@ -208,7 +217,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken boolean isEof = true; try { - isEof = (this.storageFile.getFilePointer() >= this.length()); + isEof = (this.getStorageFile().getFilePointer() >= this.length()); } catch (final IOException ex) { // Length cannot be determined this.getLogger().catching(ex); @@ -481,7 +490,7 @@ public class CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBacken String input = null; try { - input = this.storageFile.readLine(); + input = this.getStorageFile().readLine(); } catch (final IOException ex) { this.getLogger().catching(ex); } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java index de208ba..509dd66 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/BaseDatabaseFrontend.java @@ -43,7 +43,7 @@ public class BaseDatabaseFrontend extends BaseFrameworkSystem { * * @return the backend */ - protected DatabaseBackend getBackend () { + protected final DatabaseBackend getBackend () { return this.backend; } @@ -52,7 +52,7 @@ public class BaseDatabaseFrontend extends BaseFrameworkSystem { * * @param backend the backend to set */ - protected void setBackend (final DatabaseBackend backend) { + protected final void setBackend (final DatabaseBackend backend) { this.backend = backend; } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java b/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java index 2790075..d845d92 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/BaseManager.java @@ -25,7 +25,7 @@ import org.mxchange.addressbook.BaseFrameworkSystem; * @version 0.0 * @since 0.0 */ -public class BaseManager extends BaseFrameworkSystem { +public class BaseManager extends BaseFrameworkSystem implements Manageable { /** * No instances can be created of this class */ diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index fefd2c1..709f6f9 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -241,7 +241,7 @@ public class ContactManager extends BaseManager implements ManageableContact { @Override public void doShutdown () { // Shut down the database layer - this.contactDatabase.doShutdown(); + this.getContactDatabase().doShutdown(); } /** @@ -373,7 +373,7 @@ public class ContactManager extends BaseManager implements ManageableContact { } @Override - public int getColumnCount () { + public final int getColumnCount () { return this.columnNames.size(); } @@ -465,7 +465,7 @@ public class ContactManager extends BaseManager implements ManageableContact { * @return size of contact "book" */ @Override - public int size () { + public final int size () { return this.contacts.size(); } @@ -473,6 +473,9 @@ public class ContactManager extends BaseManager implements ManageableContact { * Fills the column names array with strings from bundle */ private void fillColumnNamesFromBundle () { + // Debug message + this.getLogger().trace("CALLED!"); + // First get an iterator from key set to iterate over Iterator iterator = this.getBundle().keySet().iterator(); @@ -490,6 +493,9 @@ public class ContactManager extends BaseManager implements ManageableContact { this.columnNames.add(this.getBundle().getString(key)); } } + + // Debug message + this.getLogger().trace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); } /** -- 2.39.5