]> git.mxchange.org Git - jfinancials-lib.git/blobdiff - Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java
Moved a lot classes and interfaces (generalized) to new jcore project + added a few...
[jfinancials-lib.git] / Addressbook / src / org / mxchange / addressbook / contact / BaseContact.java
index f03a3c1bdf20c1ded94ccacfb5eb68ceeefbb4d0..4e590c2462f0420c24b658d0d48a2053e582f0a2 100644 (file)
  */
 package org.mxchange.addressbook.contact;
 
+import java.text.MessageFormat;
 import java.util.Objects;
-import org.mxchange.addressbook.BaseFrameworkSystem;
-import org.mxchange.addressbook.client.Client;
+import org.mxchange.addressbook.BaseAddressbookSystem;
+import org.mxchange.addressbook.client.AddressbookClient;
+import org.mxchange.jcore.client.Client;
 
 /**
  * A general contact
  *
  * @author Roland Haeder
  * @version 0.0
- * @since 0.0
  */
-public class BaseContact extends BaseFrameworkSystem {
+public class BaseContact extends BaseAddressbookSystem {
 
        /**
         * Birth day
@@ -75,10 +76,9 @@ public class BaseContact extends BaseFrameworkSystem {
        private String faxNumber;
 
        /**
-        * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
-        * Company
+        * Gender instance
         */
-       private char gender;
+       private Gender gender;
 
        /**
         * House number
@@ -114,7 +114,6 @@ public class BaseContact extends BaseFrameworkSystem {
         * No instances can be created of this class
         */
        protected BaseContact () {
-               super();
        }
 
        /**
@@ -125,7 +124,7 @@ public class BaseContact extends BaseFrameworkSystem {
         * @todo Needs a lot improvements
         */
        @Override
-       public boolean equals (Object object) {
+       public boolean equals (final Object object) {
                // Is it same type?
                if (!(object instanceof BaseContact)) {
                        // Not equal types
@@ -139,7 +138,7 @@ public class BaseContact extends BaseFrameworkSystem {
                Contact contact = (Contact) object;
 
                // Now test some data @todo Definedly needs improvement
-               return ((this.getGender() == contact.getGender())
+               return ((this.getGender().equals(contact.getGender()))
                                && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
                                && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
        }
@@ -238,13 +237,18 @@ public class BaseContact extends BaseFrameworkSystem {
         * "Serializes" this object into a CSV string (this time with semicolons)
         *
         * @return "CSV-serialized" version of the stored data
+        * @deprecated Don't use this anymore
         */
+       @Deprecated
        public String getCsvStringFromStoreableObject () {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
                // Get all together
                String csvString = String.format(
-                               "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
+                               "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
                                this.isOwnContact(),
-                               this.getGender(),
+                               this.getGender().getDatabaseValue(),
                                this.getSurname(),
                                this.getFamilyName(),
                                this.getCompanyName(),
@@ -323,7 +327,7 @@ public class BaseContact extends BaseFrameworkSystem {
         *
         * @return the gender
         */
-       public char getGender () {
+       public Gender getGender () {
                return this.gender;
        }
 
@@ -332,7 +336,7 @@ public class BaseContact extends BaseFrameworkSystem {
         *
         * @param gender the gender to set
         */
-       private void setGender (final char gender) {
+       private void setGender (final Gender gender) {
                this.gender = gender;
        }
 
@@ -387,27 +391,8 @@ public class BaseContact extends BaseFrameworkSystem {
         * @return gender Human-readable gender
         */
        public String getTranslatedGender () {
-               // Default init
-               String translated = null;
-
                // "Translate" it
-               switch (this.getGender()) {
-                       case 'M': // Mr.
-                               translated = "Herr";
-                               break;
-
-                       case 'F': // Mrs.
-                               translated = "Frau";
-                               break;
-
-                       case 'C': // "Company"
-                               translated = "Firma";
-                               break;
-
-                       default: // Unsupported
-                               this.getLogger().error("Gender " + this.getGender() + " not supported.");
-                               break;
-               }
+               String translated = this.getBundle().getString(this.getGender().getMessageKey());
 
                // Return it
                return translated;
@@ -430,12 +415,15 @@ public class BaseContact extends BaseFrameworkSystem {
        protected final void setZipCode (final long zipCode) {
                this.zipCode = zipCode;
        }
-
+       
        @Override
        public int hashCode () {
+               // Validate gender instance
+               assert (this.getGender() instanceof Gender) : "gender is not set.";
+
                int hash = 7;
                hash = 79 * hash + Objects.hashCode(this.getFamilyName());
-               hash = 79 * hash + this.getGender();
+               hash = 79 * hash + this.getGender().hashCode();
                hash = 79 * hash + Objects.hashCode(this.getSurname());
                return hash;
        }
@@ -455,14 +443,26 @@ public class BaseContact extends BaseFrameworkSystem {
         * @param client Client instance to use
         */
        public void show (final Client client) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
+
+               // The client must be set
+               if (client == null) {
+                       // Not set
+                       throw new NullPointerException("client is null");
+               }
+
+               // Cast client
+               AddressbookClient c = (AddressbookClient) client;
+
                // Display name "box"
-               client.displayNameBox((Contact) this);
+               c.displayNameBox((Contact) this);
 
                // Display address "box"
-               client.displayAddressBox((Contact) this);
+               c.displayAddressBox((Contact) this);
 
                // Display other data "box"
-               client.displayOtherDataBox((Contact) this);
+               c.displayOtherDataBox((Contact) this);
        }
 
        /**
@@ -474,6 +474,9 @@ public class BaseContact extends BaseFrameworkSystem {
         * @param countryCode Country code
         */
        public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("street={0},zipCode={1},city={2},countryCode={3} - CALLED!", street, zipCode, city, countryCode)); //NOI18N
+
                // Set all
                if (street != null) {
                        this.setStreet(street);
@@ -487,6 +490,9 @@ public class BaseContact extends BaseFrameworkSystem {
                if (countryCode != null) {
                        this.setCountryCode(countryCode);
                }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -497,9 +503,13 @@ public class BaseContact extends BaseFrameworkSystem {
         * @param familyName Family name
         * @param companyName Company name
         */
-       public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
+       public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N
+
                // Set all
                this.setGender(gender);
+
                if (surname != null) {
                        this.setSurname(surname);
                }
@@ -509,6 +519,9 @@ public class BaseContact extends BaseFrameworkSystem {
                if (companyName != null) {
                        this.setCompanyName(companyName);
                }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -522,6 +535,9 @@ public class BaseContact extends BaseFrameworkSystem {
         * @param comment Comments
         */
        public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("phoneNumber={0},cellphoneNumber={1}faxNumber={2},emailAddress={3},birthday={4},comment={5} - CALLED!", phoneNumber, cellphoneNumber, faxNumber, emailAddress, birthday, comment)); //NOI18N
+
                // Set all
                if (phoneNumber != null) {
                        this.setPhoneNumber(phoneNumber);
@@ -541,6 +557,9 @@ public class BaseContact extends BaseFrameworkSystem {
                if (comment != null) {
                        this.setComment(comment);
                }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -595,4 +614,72 @@ public class BaseContact extends BaseFrameworkSystem {
        protected final void setBirthday (final String birthday) {
                this.birthday = birthday;
        }
+
+       /**
+        * Some "getter for a value from given column name. This name will be
+        * translated into a method name and then this method is called.
+        *
+        * @param columnName Column name
+        * @return Value from field
+        */
+       @Override
+       public Object getValueFromColumn (final String columnName) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
+               
+               // Determine if the given column is boolean
+               if (this.isBooleanField(this, "BaseContact", columnName)) {
+                       // Yes, then call other method
+                       return this.getBooleanField(this, "BaseContact", columnName);
+               }
+               
+               // Convert column name to field name
+               String methodName = this.convertColumnNameToGetterMethod(columnName, false);
+               
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+               
+               // Get field
+               Object value = this.getField(this, "BaseContact", methodName);
+               
+               // Trace message
+               this.getLogger().trace("value=" + value + " - EXIT!");
+               
+               // Return it
+               return value;
+       }
+
+       /**
+        * Checks if given boolean field is available and set to same value
+        *
+        * @param columnName Column name to check
+        * @param bool Boolean value
+        * @return Whether all conditions are met
+        */
+       @Override
+       public boolean isValueEqual (final String columnName, final boolean bool) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
+               
+               // Convert column name to field name
+               String methodName = this.convertColumnNameToGetterMethod(columnName, true);
+               
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+               
+               // Init class instance
+               boolean value = this.getBooleanField(this, "BaseContact", methodName);
+               
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("value={0}", value));
+               
+               // Compare it
+               boolean isFound = (bool == value);
+               
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
+               
+               // Return result
+               return isFound;
+       }
 }