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;
}
/**
*
* @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
}
/**
- * 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;
}
/**
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
*/
* @author Roland Haeder<roland@mxchange.org>
*/
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
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
/**
* Shutdown the application
+ *
* @throws java.io.IOException If an IO error occurs
* @throws java.sql.SQLException If a SQL error occurs
*/
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
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 ();
}
* @author Roland Haeder<roland@mxchange.org>
*/
public class FrameAlreadyInitializedException extends Exception {
+
/**
* Serial number
*/
* @author Roland Haeder<roland@mxchange.org>
*/
public class UnhandledUserChoiceException extends Exception {
+
/**
* Serial number
*/
/**
* A general interface for any kind of manager classes
- *
+ *
* @author Roland Haeder<roland@mxchange.org>
*/
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
*/
/**
* Application manager
- *
+ *
* @author Roland Haeder<roland@mxchange.org>
*/
public class ApplicationManager extends BaseManager implements ManageableApplication {
+
/**
* Self instance of this manager
*/
+++ /dev/null
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcore.model.contact;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Lob;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import org.mxchange.jcore.client.Client;
-import org.mxchange.jcore.model.contact.gender.Gender;
-
-/**
- * A general contact class which should only be extended.
- *
- * @author Roland Haeder<roland@mxchange.org>
- * @version 0.0
- */
-@Entity (name = "contact")
-@Table (name = "contacts")
-public abstract class BaseContact implements Contact, Comparable<Contact> {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 58_744_284_981_863L;
-
- /**
- * Birth day
- */
- @Column
- @Temporal (TemporalType.DATE)
- private Date birthday;
-
- /**
- * Cellphone number
- */
- @Column (name = "cellphone_number", length = 100)
- private String cellphoneNumber;
-
- /**
- * City
- */
- @Column (nullable = false, length = 100)
- private String city;
-
- /**
- * Optional comments
- */
- @Lob
- @Column
- private String comment;
-
- /**
- * Company name
- */
- @Column (name = "company_name", nullable = false)
- private String companyName;
-
- /**
- * Country code
- */
- @Column (name = "country_code", length = 2, nullable = false)
- private String countryCode;
-
- /**
- * When the contact has been created
- */
- @Basic(optional = false)
- @Temporal (TemporalType.TIMESTAMP)
- @Column(nullable = false)
- private Calendar created;
-
- /**
- * Email address
- */
- @Column (name = "email_address", length = 100, nullable = false)
- private String emailAddress;
-
- /**
- * Family name
- */
- @Basic (optional = false)
- @Column (name = "family_name", length = 100, nullable = false)
- private String familyName;
-
- /**
- * Fax number
- */
- @Column (name = "fax_number", length = 100)
- private String faxNumber;
-
- /**
- * First name
- */
- @Basic (optional = false)
- @Column (name = "first_name", length = 100, nullable = false)
- private String firstName;
-
- /**
- * Gender instance
- */
- @Basic (optional = false)
- @Column (nullable = false)
- private Gender gender;
-
- /**
- * House number
- */
- @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
- */
- @Column (name = "own_contact", nullable = false)
- private Boolean ownContact;
-
- /**
- * Phone number
- */
- @Column (name = "phone_number", length = 100)
- private String phoneNumber;
-
- /**
- * Street
- */
- @Column (nullable = false)
- private String street;
-
- /**
- * When the contact has been updated
- */
- @Temporal (TemporalType.TIMESTAMP)
- private Calendar updated;
-
- /**
- * ZIP code
- */
- @Column (name = "zip_code", nullable = false, length = 6)
- private Long zipCode;
-
- /**
- * No instances should be created of this class. Better extend this class
- * and provide proper constructors.
- */
- protected BaseContact () {
- }
-
- /**
- * Compares two contacts with each other
- *
- * @param contact Contact comparator
- * @return Comparison value
- */
- @Override
- public int compareTo (final Contact contact) {
- // contact should not be null
- if (null == contact) {
- throw new NullPointerException("contact is null"); //NOI18N
- }
-
- // Is the id the same?
- if (Objects.equals(this.getId(), contact.getId())) {
- // Same id, means same contact
- return 0;
- } else if (this.getId() > contact.getId()) {
- // This id is larger than compared to
- return -1;
- }
-
- // The other id is larger
- return 1;
- }
-
- @Override
- public void copyAll (final Contact contact) {
- // Copy all:
- // - base data
- this.setFirstName(contact.getFirstName());
- this.setFamilyName(contact.getFamilyName());
- this.setCompanyName(contact.getCompanyName());
- this.setStreet(contact.getStreet());
- this.setZipCode(contact.getZipCode());
- this.setCity(contact.getCity());
- this.setCountryCode(contact.getCountryCode());
-
- // - phone, fax, email
- this.setPhoneNumber(contact.getPhoneNumber());
- this.setFaxNumber(contact.getFaxNumber());
- this.setCellphoneNumber(contact.getCellphoneNumber());
-
- // - other data
- this.setBirthday(contact.getBirthday());
- this.setComment(contact.getComment());
- this.setCreated(contact.getCreated());
- this.setUpdated(contact.getUpdated());
- }
-
- /**
- * Check if contacts are same or throw an exception
- *
- * @param object Other possible contact class
- * @return Whether both contacts are same TODO Needs a lot improvements
- */
- @Override
- public boolean equals (final Object object) {
- // Is it same type?
- if (!(object instanceof BaseContact)) {
- // Not equal types
- return false;
- } else if (!(object instanceof Contact)) {
- // Not correct interface
- return false;
- }
-
- // Try to cast
- Contact contact = (Contact) object;
-
- // Now test some data TODO Definedly needs improvement
- return ((this.getGender().equals(contact.getGender()))
- && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
- && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
- }
-
- @Override
- public Date getBirthday () {
- return this.birthday;
- }
-
- @Override
- public void setBirthday (final Date birthday) {
- this.birthday = birthday;
- }
-
- @Override
- public String getCellphoneNumber () {
- return this.cellphoneNumber;
- }
-
- @Override
- public void setCellphoneNumber (final String cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
- }
-
- @Override
- public String getCity () {
- return this.city;
- }
-
- @Override
- public void setCity (final String city) {
- this.city = city;
- }
-
- @Override
- public String getComment () {
- return this.comment;
- }
-
- @Override
- public void setComment (final String comment) {
- this.comment = comment;
- }
-
- @Override
- public String getCompanyName () {
- return this.companyName;
- }
-
- @Override
- public void setCompanyName (final String companyName) {
- this.companyName = companyName;
- }
-
- @Override
- public String getCountryCode () {
- return this.countryCode;
- }
-
- @Override
- public void setCountryCode (final String countryCode) {
- this.countryCode = countryCode;
- }
-
- @Override
- public Calendar getCreated () {
- return this.created;
- }
-
- @Override
- public void setCreated (final Calendar created) {
- this.created = created;
- }
-
- @Override
- public String getEmailAddress () {
- return this.emailAddress;
- }
-
- @Override
- public void setEmailAddress (final String emailAddress) {
- this.emailAddress = emailAddress;
- }
-
- @Override
- public String getFamilyName () {
- //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
- return this.familyName;
- }
-
- @Override
- public void setFamilyName (final String familyName) {
- this.familyName = familyName;
- }
-
- @Override
- public String getFaxNumber () {
- return this.faxNumber;
- }
-
- @Override
- public void setFaxNumber (final String faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- @Override
- public String getFirstName () {
- return this.firstName;
- }
-
- @Override
- public void setFirstName (final String firstName) {
- this.firstName = firstName;
- }
-
- @Override
- public Gender getGender () {
- return this.gender;
- }
-
- @Override
- public void setGender (final Gender gender) {
- this.gender = gender;
- }
-
- @Override
- public Long getHouseNumber () {
- return this.houseNumber;
- }
-
- @Override
- public void setHouseNumber (final Long houseNumber) {
- 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;
- }
-
- @Override
- public String getPhoneNumber () {
- return this.phoneNumber;
- }
-
- @Override
- public void setPhoneNumber (final String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
-
- @Override
- public String getStreet () {
- return this.street;
- }
-
- @Override
- public void setStreet (final String street) {
- this.street = street;
- }
-
- @Override
- public Calendar getUpdated () {
- return this.updated;
- }
-
- @Override
- public void setUpdated (final Calendar updated) {
- this.updated = updated;
- }
-
- @Override
- public Long getZipCode () {
- return this.zipCode;
- }
-
- @Override
- public void setZipCode (final Long zipCode) {
- this.zipCode = zipCode;
- }
-
- @Override
- public int hashCode () {
- // Validate gender instance
- assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
-
- int hash = 7;
- hash = 79 * hash + Objects.hashCode(this.getFamilyName());
- hash = 79 * hash + this.getGender().hashCode();
- hash = 79 * hash + Objects.hashCode(this.getFirstName());
- return hash;
- }
-
- @PostConstruct
- public void init () {
- // Fake gender
- this.gender = Gender.UNKNOWN;
- }
-
- @Override
- public Boolean isOwnContact () {
- return this.ownContact;
- }
-
- /**
- * Shows this contact to the user.
- *
- * @param client Client instance to use
- * @deprecated Should not be called here
- */
- @Deprecated
- public void show (final Client client) {
- // The client must be set
- if (null == client) {
- // Not set
- throw new NullPointerException("client is null"); //NOI18N
- }
-
- // Display name "box"
- client.displayNameBox(this);
-
- // Display address "box"
- client.displayAddressBox(this);
-
- // Display other data "box"
- client.displayOtherDataBox(this);
- }
-}
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
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
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
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
* @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 ();
}
--- /dev/null
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcore.model.contact;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import org.mxchange.jcore.client.Client;
+import org.mxchange.jcore.model.contact.gender.Gender;
+
+/**
+ * A general contact class which should only be extended.
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ * @version 0.0
+ */
+@Entity (name = "contacts")
+@Table (name = "contacts")
+public class UserContact implements Contact, Comparable<Contact> {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 58_744_284_981_863L;
+
+ /**
+ * Birth day
+ */
+ @Column (name = "birthday")
+ @Temporal (TemporalType.DATE)
+ private Date birthday;
+
+ /**
+ * Cellphone number
+ */
+ @Column (name = "cellphone_number", length = 100)
+ private String cellphoneNumber;
+
+ /**
+ * City
+ */
+ @Column (name = "city", nullable = false, length = 100)
+ private String city;
+
+ /**
+ * Optional comments
+ */
+ @Lob
+ @Column (name = "comment")
+ private String comment;
+
+ /**
+ * Company name
+ */
+ @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
+ */
+ @Column (name = "country_code", length = 2, nullable = false)
+ private String countryCode;
+
+ /**
+ * When the contact has been created
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "created", nullable = false)
+ private Calendar created;
+
+ /**
+ * Email address
+ */
+ @Column (name = "email_address", length = 100, nullable = false)
+ private String emailAddress;
+
+ /**
+ * Family name
+ */
+ @Basic (optional = false)
+ @Column (name = "family_name", length = 100, nullable = false)
+ private String familyName;
+
+ /**
+ * Fax number
+ */
+ @Column (name = "fax_number", length = 100)
+ private String faxNumber;
+
+ /**
+ * First name
+ */
+ @Basic (optional = false)
+ @Column (name = "first_name", length = 100, nullable = false)
+ private String firstName;
+
+ /**
+ * Gender instance
+ */
+ @Basic (optional = false)
+ @Column (name = "gender", nullable = false)
+ private Gender gender;
+
+ /**
+ * House number
+ */
+ @Column (name = "house_number", length = 5, nullable = false)
+ private Long houseNumber;
+
+ /**
+ * Flag whether this contact is user's own data
+ */
+ @Column (name = "own_contact", nullable = false)
+ private Boolean ownContact;
+
+ /**
+ * Phone number
+ */
+ @Column (name = "phone_number", length = 100)
+ private String phoneNumber;
+
+ /**
+ * Street
+ */
+ @Column (name = "street", nullable = false)
+ private String street;
+
+ /**
+ * When the contact has been updated
+ */
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "updated")
+ private Calendar updated;
+
+ /**
+ * ZIP code
+ */
+ @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 UserContact () {
+ }
+
+ /**
+ * Compares two contacts with each other
+ *
+ * @param contact Contact comparator
+ * @return Comparison value
+ */
+ @Override
+ public int compareTo (final Contact contact) {
+ // contact should not be null
+ if (null == contact) {
+ throw new NullPointerException("contact is null"); //NOI18N
+ }
+
+ // Is the contactId the same?
+ if (Objects.equals(this.getContactId(), contact.getContactId())) {
+ // Same contactId, means same contact
+ return 0;
+ } else if (this.getContactId() > contact.getContactId()) {
+ // This contactId is larger than compared to
+ return -1;
+ }
+
+ // The other contactId is larger
+ return 1;
+ }
+
+ @Override
+ public void copyAll (final Contact contact) {
+ // Copy all:
+ // - base data
+ this.setFirstName(contact.getFirstName());
+ this.setFamilyName(contact.getFamilyName());
+ this.setCompanyName(contact.getCompanyName());
+ this.setStreet(contact.getStreet());
+ this.setZipCode(contact.getZipCode());
+ this.setCity(contact.getCity());
+ this.setCountryCode(contact.getCountryCode());
+
+ // - phone, fax, email
+ this.setPhoneNumber(contact.getPhoneNumber());
+ this.setFaxNumber(contact.getFaxNumber());
+ this.setCellphoneNumber(contact.getCellphoneNumber());
+
+ // - other data
+ this.setBirthday(contact.getBirthday());
+ this.setComment(contact.getComment());
+ this.setCreated(contact.getCreated());
+ this.setUpdated(contact.getUpdated());
+ }
+
+ /**
+ * Check if contacts are same or throw an exception
+ *
+ * @param object Other possible contact class
+ * @return Whether both contacts are same TODO Needs a lot improvements
+ */
+ @Override
+ public boolean equals (final Object object) {
+ // Is it same type?
+ if (!(object instanceof UserContact)) {
+ // Not equal types
+ return false;
+ } else if (!(object instanceof Contact)) {
+ // Not correct interface
+ return false;
+ }
+
+ // Try to cast
+ Contact contact = (Contact) object;
+
+ // Now test some data TODO Definedly needs improvement
+ return ((this.getGender().equals(contact.getGender()))
+ && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
+ && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
+ }
+
+ @Override
+ public Date getBirthday () {
+ return this.birthday;
+ }
+
+ @Override
+ public void setBirthday (final Date birthday) {
+ this.birthday = birthday;
+ }
+
+ @Override
+ public String getCellphoneNumber () {
+ return this.cellphoneNumber;
+ }
+
+ @Override
+ public void setCellphoneNumber (final String cellphoneNumber) {
+ this.cellphoneNumber = cellphoneNumber;
+ }
+
+ @Override
+ public String getCity () {
+ return this.city;
+ }
+
+ @Override
+ public void setCity (final String city) {
+ this.city = city;
+ }
+
+ @Override
+ public String getComment () {
+ return this.comment;
+ }
+
+ @Override
+ public void setComment (final String comment) {
+ this.comment = comment;
+ }
+
+ @Override
+ public String getCompanyName () {
+ return this.companyName;
+ }
+
+ @Override
+ public void setCompanyName (final String companyName) {
+ 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;
+ }
+
+ @Override
+ public void setCountryCode (final String countryCode) {
+ this.countryCode = countryCode;
+ }
+
+ @Override
+ public Calendar getCreated () {
+ return this.created;
+ }
+
+ @Override
+ public void setCreated (final Calendar created) {
+ this.created = created;
+ }
+
+ @Override
+ public String getEmailAddress () {
+ return this.emailAddress;
+ }
+
+ @Override
+ public void setEmailAddress (final String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+ @Override
+ public String getFamilyName () {
+ //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
+ return this.familyName;
+ }
+
+ @Override
+ public void setFamilyName (final String familyName) {
+ this.familyName = familyName;
+ }
+
+ @Override
+ public String getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ @Override
+ public void setFaxNumber (final String faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ @Override
+ public String getFirstName () {
+ return this.firstName;
+ }
+
+ @Override
+ public void setFirstName (final String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Override
+ public Gender getGender () {
+ return this.gender;
+ }
+
+ @Override
+ public void setGender (final Gender gender) {
+ this.gender = gender;
+ }
+
+ @Override
+ public Long getHouseNumber () {
+ return this.houseNumber;
+ }
+
+ @Override
+ public void setHouseNumber (final Long houseNumber) {
+ this.houseNumber = houseNumber;
+ }
+
+ @Override
+ public void setOwnContact (final Boolean ownContact) {
+ this.ownContact = ownContact;
+ }
+
+ @Override
+ public String getPhoneNumber () {
+ return this.phoneNumber;
+ }
+
+ @Override
+ public void setPhoneNumber (final String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ @Override
+ public String getStreet () {
+ return this.street;
+ }
+
+ @Override
+ public void setStreet (final String street) {
+ this.street = street;
+ }
+
+ @Override
+ public Calendar getUpdated () {
+ return this.updated;
+ }
+
+ @Override
+ public void setUpdated (final Calendar updated) {
+ this.updated = updated;
+ }
+
+ @Override
+ public Long getZipCode () {
+ return this.zipCode;
+ }
+
+ @Override
+ public void setZipCode (final Long zipCode) {
+ this.zipCode = zipCode;
+ }
+
+ @Override
+ public int hashCode () {
+ // Validate gender instance
+ assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
+
+ int hash = 7;
+ hash = 79 * hash + Objects.hashCode(this.getFamilyName());
+ hash = 79 * hash + this.getGender().hashCode();
+ hash = 79 * hash + Objects.hashCode(this.getFirstName());
+ return hash;
+ }
+
+ @PostConstruct
+ public void init () {
+ // Fake gender
+ this.gender = Gender.UNKNOWN;
+ }
+
+ @Override
+ public Boolean isOwnContact () {
+ return this.ownContact;
+ }
+
+ /**
+ * Shows this contact to the user.
+ *
+ * @param client Client instance to use
+ * @deprecated Should not be called here
+ */
+ @Deprecated
+ public void show (final Client client) {
+ // The client must be set
+ if (null == client) {
+ // Not set
+ throw new NullPointerException("client is null"); //NOI18N
+ }
+
+ // Display name "box"
+ client.displayNameBox(this);
+
+ // Display address "box"
+ client.displayAddressBox(this);
+
+ // Display other data "box"
+ client.displayOtherDataBox(this);
+ }
+}