]> git.mxchange.org Git - jcore.git/commitdiff
Continiued:
authorRoland Haeder <roland@mxchange.org>
Thu, 24 Sep 2015 12:57:38 +0000 (14:57 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 24 Sep 2015 12:57:38 +0000 (14:57 +0200)
- reformatted many files
- got rid of BaseContact and made UserContact to an entity
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcore/BaseFrameworkSystem.java
src/org/mxchange/jcore/FrameworkInterface.java
src/org/mxchange/jcore/application/Application.java
src/org/mxchange/jcore/client/Client.java
src/org/mxchange/jcore/exceptions/FrameAlreadyInitializedException.java
src/org/mxchange/jcore/exceptions/UnhandledUserChoiceException.java
src/org/mxchange/jcore/manager/Manageable.java
src/org/mxchange/jcore/manager/application/ApplicationManager.java
src/org/mxchange/jcore/model/contact/BaseContact.java [deleted file]
src/org/mxchange/jcore/model/contact/Contact.java
src/org/mxchange/jcore/model/contact/UserContact.java [new file with mode: 0644]

index ebfe18b0ce45fb3a7083afc73fdc888774be047e..f1817c1463cf3642bd4854e30f31c9056cf8d464 100644 (file)
@@ -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
         */
index 9df3adbe3ddf1935c2df57cf3996f69c0ae53211..a0e42a777b10076c9a1e232888ca55dac1c178d9 100644 (file)
@@ -26,17 +26,18 @@ import org.mxchange.jcore.manager.Manageable;
  * @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
@@ -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
index 9fc13fa2a7cdc363f8ece75fcc8f51cb58bfd513..4ebafd082bd955c7a1f1dfc2db80e38e365f7cad 100644 (file)
@@ -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
         */
index 269bf3ef5e61e66d0b8876c683aec177524ef5ae..66c5b9c68410281d3ce260ae590cca995ac0e4ee 100644 (file)
@@ -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 ();
 }
index 528c922c1eb05d4eb234ab0bdefc0c45df8d679a..6f5ff7843d9fcafbc70f9e9d7d23c91679e62423 100644 (file)
@@ -22,6 +22,7 @@ package org.mxchange.jcore.exceptions;
  * @author Roland Haeder<roland@mxchange.org>
  */
 public class FrameAlreadyInitializedException extends Exception {
+
        /**
         * Serial number
         */
index de55e6e307cd0c157ffe4a8b98befb20702438e3..d8f6eaa71e21eee6deef645a04178be6440f4c69 100644 (file)
@@ -23,6 +23,7 @@ package org.mxchange.jcore.exceptions;
  * @author Roland Haeder<roland@mxchange.org>
  */
 public class UnhandledUserChoiceException extends Exception {
+
        /**
         * Serial number
         */
index dd711d35e04f07338477f8dafa95dbeb19a2e455..b19a38ff6d3082472ec30da41bc0d4b9c4c110d1 100644 (file)
@@ -22,13 +22,14 @@ import org.mxchange.jcore.FrameworkInterface;
 
 /**
  * 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
         */
index 097a0f44967109234297ac8d4a2c0b600fbf43c7..34e13036c34d246fcdad929390d5d6f44c2cd835 100644 (file)
@@ -21,10 +21,11 @@ import org.mxchange.jcore.manager.BaseManager;
 
 /**
  * Application manager
- * 
+ *
  * @author Roland Haeder<roland@mxchange.org>
  */
 public class ApplicationManager extends BaseManager implements ManageableApplication {
+
        /**
         * Self instance of this manager
         */
diff --git a/src/org/mxchange/jcore/model/contact/BaseContact.java b/src/org/mxchange/jcore/model/contact/BaseContact.java
deleted file mode 100644 (file)
index 0f163b7..0000000
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * 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);
-       }
-}
index 94f9b7fe05a126a609e36b6de0e60b660746086f..18b807bcbc558c8c359ae4bab37875dd393a399d 100644 (file)
@@ -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/UserContact.java b/src/org/mxchange/jcore/model/contact/UserContact.java
new file mode 100644 (file)
index 0000000..1c88cce
--- /dev/null
@@ -0,0 +1,505 @@
+/*
+ * 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);
+       }
+}