From a87df7319bfda48b0113a1f5e73ceb31907996d4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 24 Sep 2015 14:57:38 +0200 Subject: [PATCH] =?utf8?q?Continiued:=20-=20reformatted=20many=20files=20-?= =?utf8?q?=20got=20rid=20of=20BaseContact=20and=20made=20UserContact=20to?= =?utf8?q?=20an=20entity=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../mxchange/jcore/BaseFrameworkSystem.java | 182 +++++++-------- .../mxchange/jcore/FrameworkInterface.java | 13 +- .../jcore/application/Application.java | 1 + src/org/mxchange/jcore/client/Client.java | 49 ++-- .../FrameAlreadyInitializedException.java | 1 + .../UnhandledUserChoiceException.java | 1 + .../mxchange/jcore/manager/Manageable.java | 3 +- .../application/ApplicationManager.java | 3 +- .../mxchange/jcore/model/contact/Contact.java | 214 +++++++++--------- .../{BaseContact.java => UserContact.java} | 85 ++++--- 10 files changed, 289 insertions(+), 263 deletions(-) rename src/org/mxchange/jcore/model/contact/{BaseContact.java => UserContact.java} (86%) diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index ebfe18b..f1817c1 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -101,84 +101,39 @@ public abstract class BaseFrameworkSystem implements FrameworkInterface { return this.application; } - /** - * Getter for logger instance - * - * @return Logger instance - */ - protected Logger getLogger () { - return this.LOG; - } - - @Override - public Manageable getManager () { - return this.manager; - } - - @Override - public String getMessageStringFromKey (final String key) { - // Return message - return this.getBundle().getString(key); - } - - /** - * Aborts program with given exception - * - * @param throwable Any type of Throwable - */ - protected void abortProgramWithException (final Throwable throwable) { - // Log exception ... - this.logException(throwable); - - // .. and exit - System.exit(1); - } - - /** - * Application instance - * - * @param application the application to set - */ - protected void setApplication (final Application application) { - this.application = application; - } - @Override public Client getClient () { return this.client; } - /** - * Getter for bundle instance - * - * @return Resource bundle - */ - protected ResourceBundle getBundle () { - return BaseFrameworkSystem.bundle; + @Override + public void logException (final Throwable exception) { + // Log this exception + this.getLogger().catching(exception); } /** - * Setter for bundle instance + * Converts null to empty string or leaves original object untouched. * - * @param bundle the bundle to set + * @param object Any string + * @return Empty string if null or original string TODO: Move to own utility + * class */ - protected static void setBundle (final ResourceBundle bundle) { - BaseFrameworkSystem.bundle = bundle; - } + protected Object convertNullToEmpty (final Object object) { + // Trace message + this.getLogger().trace(MessageFormat.format("object={0}", object)); //NOI18N - /** - * Client instance - * - * @param client the client to set - */ - protected void setClient (final Client client) { - this.client = client; - } + // Is it null? + if (null == object) { + // Return empty string + return ""; //NOI18N + } - @Override - public void logException (final Throwable exception) { - // Log this exception - this.getLogger().catching(exception); + // Trace message + this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N + + // Return it + return object; } /** @@ -186,8 +141,8 @@ public abstract class BaseFrameworkSystem implements FrameworkInterface { * * @param str String to tokenize and get array from * @param delimiter Delimiter - * @return Array from tokenized string TODO Get rid of size parameter - * TODO: Move to own utility class + * @return Array from tokenized string TODO Get rid of size parameter TODO: + * Move to own utility class */ protected String[] getArrayFromString (final String str, final String delimiter) { // Trace message @@ -220,36 +175,26 @@ public abstract class BaseFrameworkSystem implements FrameworkInterface { } /** - * Converts null to empty string or leaves original object untouched. + * Client instance * - * @param object Any string - * @return Empty string if null or original string - * TODO: Move to own utility class + * @param client the client to set */ - protected Object convertNullToEmpty (final Object object) { - // Trace message - this.getLogger().trace(MessageFormat.format("object={0}", object)); //NOI18N - - // Is it null? - if (null == object) { - // Return empty string - return ""; //NOI18N - } - - // Trace message - this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N - - // Return it - return object; + protected void setClient (final Client client) { + this.client = client; } /** - * Manager instance + * Application instance * - * @param manager the manager instance to set + * @param application the application to set */ - protected void setManager (final Manageable manager) { - this.manager = manager; + protected void setApplication (final Application application) { + this.application = application; + } + + @Override + public Manageable getManager () { + return this.manager; } /** @@ -270,6 +215,61 @@ public abstract class BaseFrameworkSystem implements FrameworkInterface { this.contact = contact; } + /** + * Manager instance + * + * @param manager the manager instance to set + */ + protected void setManager (final Manageable manager) { + this.manager = manager; + } + + @Override + public String getMessageStringFromKey (final String key) { + // Return message + return this.getBundle().getString(key); + } + + /** + * Aborts program with given exception + * + * @param throwable Any type of Throwable + */ + protected void abortProgramWithException (final Throwable throwable) { + // Log exception ... + this.logException(throwable); + + // .. and exit + System.exit(1); + } + + /** + * Getter for bundle instance + * + * @return Resource bundle + */ + protected ResourceBundle getBundle () { + return BaseFrameworkSystem.bundle; + } + + /** + * Setter for bundle instance + * + * @param bundle the bundle to set + */ + protected static void setBundle (final ResourceBundle bundle) { + BaseFrameworkSystem.bundle = bundle; + } + + /** + * Getter for logger instance + * + * @return Logger instance + */ + protected Logger getLogger () { + return this.LOG; + } + /** * Initializes i18n bundles */ diff --git a/src/org/mxchange/jcore/FrameworkInterface.java b/src/org/mxchange/jcore/FrameworkInterface.java index 9df3adb..a0e42a7 100644 --- a/src/org/mxchange/jcore/FrameworkInterface.java +++ b/src/org/mxchange/jcore/FrameworkInterface.java @@ -26,17 +26,18 @@ import org.mxchange.jcore.manager.Manageable; * @author Roland Haeder */ public interface FrameworkInterface { + /** * File name (and path) for internalization bundle */ public static final String I18N_BUNDLE_FILE = "org/mxchange/localization/bundle"; //NOI18N /** - * Getter for manager + * Application instance * - * @return Manager instance + * @return the application */ - public Manageable getManager (); + public Application getApplication (); /** * Client instance @@ -46,11 +47,11 @@ public interface FrameworkInterface { public Client getClient (); /** - * Application instance + * Getter for manager * - * @return the application + * @return Manager instance */ - public Application getApplication (); + public Manageable getManager (); /** * Getter for human-readable string from given key diff --git a/src/org/mxchange/jcore/application/Application.java b/src/org/mxchange/jcore/application/Application.java index 9fc13fa..4ebafd0 100644 --- a/src/org/mxchange/jcore/application/Application.java +++ b/src/org/mxchange/jcore/application/Application.java @@ -38,6 +38,7 @@ public interface Application extends FrameworkInterface { /** * Shutdown the application + * * @throws java.io.IOException If an IO error occurs * @throws java.sql.SQLException If a SQL error occurs */ diff --git a/src/org/mxchange/jcore/client/Client.java b/src/org/mxchange/jcore/client/Client.java index 269bf3e..66c5b9c 100644 --- a/src/org/mxchange/jcore/client/Client.java +++ b/src/org/mxchange/jcore/client/Client.java @@ -29,35 +29,38 @@ import org.mxchange.jcore.model.contact.Contact; public interface Client extends FrameworkInterface { /** - * Shuts down the client and therefore whole application - * @throws java.io.IOException If an IO error occurs - * @throws java.sql.SQLException If a SQL error occurs + * Displays a "box" for the address + * + * @param contact Contact to show address from */ - public void doShutdown () throws IOException, SQLException; + public void displayAddressBox (final Contact contact); /** - * Displays a message to the user + * Displays a "box" for the name * - * @param message Message to show to the user + * @param contact Contact to show name from */ - public void outputMessage (final String message); + public void displayNameBox (final Contact contact); /** - * Enables isRunning attribute which singals that the client is running + * Displays a "box" for other data + * + * @param contact Contact to show other data from */ - public void enableIsRunning (); + public void displayOtherDataBox (final Contact contact); /** - * Determines whether the client is still active by checking some conditions + * Shuts down the client and therefore whole application * - * @return Whether the client is still active + * @throws java.io.IOException If an IO error occurs + * @throws java.sql.SQLException If a SQL error occurs */ - public boolean isRunning (); + public void doShutdown () throws IOException, SQLException; /** - * Shows introduction to user + * Enables isRunning attribute which singals that the client is running */ - public void showWelcome (); + public void enableIsRunning (); /** * Inizializes this client @@ -65,23 +68,21 @@ public interface Client extends FrameworkInterface { public void init (); /** - * Displays a "box" for the address + * Determines whether the client is still active by checking some conditions * - * @param contact Contact to show address from + * @return Whether the client is still active */ - public void displayAddressBox (final Contact contact); + public boolean isRunning (); /** - * Displays a "box" for the name + * Displays a message to the user * - * @param contact Contact to show name from + * @param message Message to show to the user */ - public void displayNameBox (final Contact contact); + public void outputMessage (final String message); /** - * Displays a "box" for other data - * - * @param contact Contact to show other data from + * Shows introduction to user */ - public void displayOtherDataBox (final Contact contact); + public void showWelcome (); } diff --git a/src/org/mxchange/jcore/exceptions/FrameAlreadyInitializedException.java b/src/org/mxchange/jcore/exceptions/FrameAlreadyInitializedException.java index 528c922..6f5ff78 100644 --- a/src/org/mxchange/jcore/exceptions/FrameAlreadyInitializedException.java +++ b/src/org/mxchange/jcore/exceptions/FrameAlreadyInitializedException.java @@ -22,6 +22,7 @@ package org.mxchange.jcore.exceptions; * @author Roland Haeder */ public class FrameAlreadyInitializedException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jcore/exceptions/UnhandledUserChoiceException.java b/src/org/mxchange/jcore/exceptions/UnhandledUserChoiceException.java index de55e6e..d8f6eaa 100644 --- a/src/org/mxchange/jcore/exceptions/UnhandledUserChoiceException.java +++ b/src/org/mxchange/jcore/exceptions/UnhandledUserChoiceException.java @@ -23,6 +23,7 @@ package org.mxchange.jcore.exceptions; * @author Roland Haeder */ public class UnhandledUserChoiceException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jcore/manager/Manageable.java b/src/org/mxchange/jcore/manager/Manageable.java index dd711d3..b19a38f 100644 --- a/src/org/mxchange/jcore/manager/Manageable.java +++ b/src/org/mxchange/jcore/manager/Manageable.java @@ -22,13 +22,14 @@ import org.mxchange.jcore.FrameworkInterface; /** * A general interface for any kind of manager classes - * + * * @author Roland Haeder */ public interface Manageable extends FrameworkInterface { /** * Shuts down this contact manager + * * @throws java.sql.SQLException If an SQL error occurs * @throws java.io.IOException If an IO error occurs */ diff --git a/src/org/mxchange/jcore/manager/application/ApplicationManager.java b/src/org/mxchange/jcore/manager/application/ApplicationManager.java index 097a0f4..34e1303 100644 --- a/src/org/mxchange/jcore/manager/application/ApplicationManager.java +++ b/src/org/mxchange/jcore/manager/application/ApplicationManager.java @@ -21,10 +21,11 @@ import org.mxchange.jcore.manager.BaseManager; /** * Application manager - * + * * @author Roland Haeder */ public class ApplicationManager extends BaseManager implements ManageableApplication { + /** * Self instance of this manager */ diff --git a/src/org/mxchange/jcore/model/contact/Contact.java b/src/org/mxchange/jcore/model/contact/Contact.java index 94f9b7f..18b807b 100644 --- a/src/org/mxchange/jcore/model/contact/Contact.java +++ b/src/org/mxchange/jcore/model/contact/Contact.java @@ -36,58 +36,60 @@ public interface Contact extends Serializable { public void copyAll (final Contact contact); /** - * Id number - * @return the contactId + * Birth day + * + * @return the birthday */ - public Long getId (); + public Date getBirthday (); /** - * Id number - * @param id the contactId to set + * Birth day + * + * @param birthday the birthday to set */ - public void setId (final Long id); + public void setBirthday (final Date birthday); /** - * Gender of the contact + * Cellphone number * - * @return the gender + * @return the cellphoneNumber */ - public Gender getGender (); + public String getCellphoneNumber (); /** - * Gender of the contact + * Cellphone number * - * @param gender the gender to set + * @param cellphoneNumber the cellphoneNumber to set */ - public void setGender (final Gender gender); + public void setCellphoneNumber (final String cellphoneNumber); /** - * First name + * City * - * @return the first name + * @return the city */ - public String getFirstName (); + public String getCity (); /** - * First name + * City * - * @param firstName the first name to set + * @param city the city to set */ - public void setFirstName (final String firstName); + public void setCity (final String city); /** - * Family name + * Comments * - * @return the familyName + * @return the comment */ - public String getFamilyName (); + public String getComment (); /** - * Family name + * Comments * - * @param familyName the familyName to set + * @param comment the comment to set */ - public void setFamilyName (final String familyName); + public void setComment (final String comment); /** * Company name @@ -104,74 +106,46 @@ public interface Contact extends Serializable { public void setCompanyName (final String companyName); /** - * Street - * - * @return the street - */ - public String getStreet (); - - /** - * Street - * - * @param street the street to set - */ - public void setStreet (final String street); - - /** - * House number - * - * @return the houseNumber - */ - public Long getHouseNumber (); - - /** - * House number - * - * @param houseNumber the houseNumber to set - */ - public void setHouseNumber (final Long houseNumber); - - /** - * ZIP code + * Id number * - * @return the zipCode + * @return the contactId */ - public Long getZipCode (); + public Long getContactId (); /** - * ZIP code + * Id number * - * @param zipCode the zipCode to set + * @param id the contactId to set */ - public void setZipCode (final Long zipCode); + public void setContactId (final Long id); /** - * City + * Country code * - * @return the city + * @return the countryCode */ - public String getCity (); + public String getCountryCode (); /** - * City + * Country code * - * @param city the city to set + * @param countryCode the countryCode to set */ - public void setCity (final String city); + public void setCountryCode (final String countryCode); /** - * Country code + * Getter for "created" timestamp * - * @return the countryCode + * @return "created" timestamp */ - public String getCountryCode (); + public Calendar getCreated (); /** - * Country code + * Setter for "created" timestamp * - * @param countryCode the countryCode to set + * @param created "created" timestamp */ - public void setCountryCode (final String countryCode); + public void setCreated (final Calendar created); /** * Email address @@ -188,18 +162,18 @@ public interface Contact extends Serializable { public void setEmailAddress (final String emailAddress); /** - * Phone number + * Family name * - * @return the phoneNumber + * @return the familyName */ - public String getPhoneNumber (); + public String getFamilyName (); /** - * Phone number + * Family name * - * @param phoneNumber the phoneNumber to set + * @param familyName the familyName to set */ - public void setPhoneNumber (final String phoneNumber); + public void setFamilyName (final String familyName); /** * Fax number @@ -216,74 +190,81 @@ public interface Contact extends Serializable { public void setFaxNumber (final String faxNumber); /** - * Cellphone number + * First name * - * @return the cellphoneNumber + * @return the first name */ - public String getCellphoneNumber (); + public String getFirstName (); /** - * Cellphone number + * First name * - * @param cellphoneNumber the cellphoneNumber to set + * @param firstName the first name to set */ - public void setCellphoneNumber (final String cellphoneNumber); + public void setFirstName (final String firstName); /** - * Birth day + * Gender of the contact * - * @return the birthday + * @return the gender */ - public Date getBirthday (); + public Gender getGender (); /** - * Birth day + * Gender of the contact * - * @param birthday the birthday to set + * @param gender the gender to set */ - public void setBirthday (final Date birthday); + public void setGender (final Gender gender); /** - * Comments + * House number * - * @return the comment + * @return the houseNumber */ - public String getComment (); + public Long getHouseNumber (); /** - * Comments + * House number * - * @param comment the comment to set + * @param houseNumber the houseNumber to set */ - public void setComment (final String comment); + public void setHouseNumber (final Long houseNumber); /** - * Checks whether the contact is user's own data + * Setter for own contact * - * @return Own data? + * @param ownContact Own contact */ - public Boolean isOwnContact (); + public void setOwnContact (final Boolean ownContact); /** - * Setter for own contact + * Phone number * - * @param ownContact Own contact + * @return the phoneNumber */ - public void setOwnContact (final Boolean ownContact); + public String getPhoneNumber (); /** - * Getter for "created" timestamp + * Phone number * - * @return "created" timestamp + * @param phoneNumber the phoneNumber to set */ - public Calendar getCreated (); + public void setPhoneNumber (final String phoneNumber); /** - * Setter for "created" timestamp + * Street * - * @param created "created" timestamp + * @return the street */ - public void setCreated (final Calendar created); + public String getStreet (); + + /** + * Street + * + * @param street the street to set + */ + public void setStreet (final String street); /** * Getter for "updated" timestamp @@ -298,4 +279,25 @@ public interface Contact extends Serializable { * @param updated "updated" timestamp */ public void setUpdated (final Calendar updated); + + /** + * ZIP code + * + * @return the zipCode + */ + public Long getZipCode (); + + /** + * ZIP code + * + * @param zipCode the zipCode to set + */ + public void setZipCode (final Long zipCode); + + /** + * Checks whether the contact is user's own data + * + * @return Own data? + */ + public Boolean isOwnContact (); } diff --git a/src/org/mxchange/jcore/model/contact/BaseContact.java b/src/org/mxchange/jcore/model/contact/UserContact.java similarity index 86% rename from src/org/mxchange/jcore/model/contact/BaseContact.java rename to src/org/mxchange/jcore/model/contact/UserContact.java index 0f163b7..1c88cce 100644 --- a/src/org/mxchange/jcore/model/contact/BaseContact.java +++ b/src/org/mxchange/jcore/model/contact/UserContact.java @@ -39,9 +39,9 @@ import org.mxchange.jcore.model.contact.gender.Gender; * @author Roland Haeder * @version 0.0 */ -@Entity (name = "contact") +@Entity (name = "contacts") @Table (name = "contacts") -public abstract class BaseContact implements Contact, Comparable { +public class UserContact implements Contact, Comparable { /** * Serial number @@ -51,7 +51,7 @@ public abstract class BaseContact implements Contact, Comparable { /** * Birth day */ - @Column + @Column (name = "birthday") @Temporal (TemporalType.DATE) private Date birthday; @@ -64,14 +64,14 @@ public abstract class BaseContact implements Contact, Comparable { /** * City */ - @Column (nullable = false, length = 100) + @Column (name = "city", nullable = false, length = 100) private String city; /** * Optional comments */ @Lob - @Column + @Column (name = "comment") private String comment; /** @@ -80,6 +80,14 @@ public abstract class BaseContact implements Contact, Comparable { @Column (name = "company_name", nullable = false) private String companyName; + /** + * Id number + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "contact_id", length = 20, updatable = false) + private Long contactId; + /** * Country code */ @@ -89,9 +97,9 @@ public abstract class BaseContact implements Contact, Comparable { /** * When the contact has been created */ - @Basic(optional = false) + @Basic (optional = false) @Temporal (TemporalType.TIMESTAMP) - @Column(nullable = false) + @Column (name = "created", nullable = false) private Calendar created; /** @@ -124,7 +132,7 @@ public abstract class BaseContact implements Contact, Comparable { * Gender instance */ @Basic (optional = false) - @Column (nullable = false) + @Column (name = "gender", nullable = false) private Gender gender; /** @@ -133,13 +141,6 @@ public abstract class BaseContact implements Contact, Comparable { @Column (name = "house_number", length = 5, nullable = false) private Long houseNumber; - /** - * Id number - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - /** * Flag whether this contact is user's own data */ @@ -155,13 +156,14 @@ public abstract class BaseContact implements Contact, Comparable { /** * Street */ - @Column (nullable = false) + @Column (name = "street", nullable = false) private String street; /** * When the contact has been updated */ @Temporal (TemporalType.TIMESTAMP) + @Column (name = "updated") private Calendar updated; /** @@ -170,11 +172,26 @@ public abstract class BaseContact implements Contact, Comparable { @Column (name = "zip_code", nullable = false, length = 6) private Long zipCode; + /** + * Constructor for gender and names + * + * @param gender Gender instance + * @param firstName First name + * @param familyName Family name + * @param companyName Company name + */ + public UserContact (final Gender gender, final String firstName, final String familyName, final String companyName) { + // Set all + this.gender = gender; + this.firstName = firstName; + this.familyName = familyName; + } + /** * No instances should be created of this class. Better extend this class * and provide proper constructors. */ - protected BaseContact () { + protected UserContact () { } /** @@ -190,16 +207,16 @@ public abstract class BaseContact implements Contact, Comparable { throw new NullPointerException("contact is null"); //NOI18N } - // Is the id the same? - if (Objects.equals(this.getId(), contact.getId())) { - // Same id, means same contact + // Is the contactId the same? + if (Objects.equals(this.getContactId(), contact.getContactId())) { + // Same contactId, means same contact return 0; - } else if (this.getId() > contact.getId()) { - // This id is larger than compared to + } else if (this.getContactId() > contact.getContactId()) { + // This contactId is larger than compared to return -1; } - // The other id is larger + // The other contactId is larger return 1; } @@ -236,7 +253,7 @@ public abstract class BaseContact implements Contact, Comparable { @Override public boolean equals (final Object object) { // Is it same type? - if (!(object instanceof BaseContact)) { + if (!(object instanceof UserContact)) { // Not equal types return false; } else if (!(object instanceof Contact)) { @@ -303,6 +320,16 @@ public abstract class BaseContact implements Contact, Comparable { this.companyName = companyName; } + @Override + public Long getContactId () { + return this.contactId; + } + + @Override + public void setContactId (final Long contactId) { + this.contactId = contactId; + } + @Override public String getCountryCode () { return this.countryCode; @@ -384,16 +411,6 @@ public abstract class BaseContact implements Contact, Comparable { this.houseNumber = houseNumber; } - @Override - public Long getId () { - return this.id; - } - - @Override - public void setId (final Long id) { - this.id = id; - } - @Override public void setOwnContact (final Boolean ownContact) { this.ownContact = ownContact; -- 2.39.5