]> git.mxchange.org Git - jcore.git/blobdiff - src/org/mxchange/jcore/contact/BaseContact.java
Added setter for bundle
[jcore.git] / src / org / mxchange / jcore / contact / BaseContact.java
index 9085faa92c51f39ed415da4788e99fd7669ea024..a26027a24b672bbcb224c666ba8b7c109c23ac9b 100644 (file)
  */
 package org.mxchange.jcore.contact;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Objects;
 import org.mxchange.jcore.BaseFrameworkSystem;
 import org.mxchange.jcore.client.Client;
 
 /**
- * A general contact
+ * A general contact class which should only be extended.
  *
  * @author Roland Haeder
  * @version 0.0
@@ -75,6 +78,11 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         */
        private String faxNumber;
 
+       /**
+        * First name
+        */
+       private String firstName;
+
        /**
         * Gender instance
         */
@@ -83,7 +91,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        /**
         * House number
         */
-       private long houseNumber;
+       private Long houseNumber;
 
        /**
         * Flag whether this contact is user's own data
@@ -100,18 +108,14 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         */
        private String street;
 
-       /**
-        * Surname
-        */
-       private String surname;
-
        /**
         * ZIP code
         */
-       private long zipCode;
+       private Long zipCode;
 
        /**
-        * No instances can be created of this class
+        * No instances should be created of this class. Better extend this class
+        * and provide proper constructors.
         */
        protected BaseContact () {
        }
@@ -139,7 +143,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
 
                // Now test some data @todo Definedly needs improvement
                return ((this.getGender().equals(contact.getGender()))
-                               && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
+                               && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
                                && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
        }
 
@@ -169,7 +173,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return the cellphoneNumber
         */
        @Override
-       public String getCellphoneNumber () {
+       public final String getCellphoneNumber () {
                return this.cellphoneNumber;
        }
 
@@ -263,41 +267,6 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                this.countryCode = countryCode;
        }
 
-       /**
-        * "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\"", //NOI18N
-                               this.isOwnContact(),
-                               this.getGender().getDatabaseValue(),
-                               this.getSurname(),
-                               this.getFamilyName(),
-                               this.getCompanyName(),
-                               this.getStreet(),
-                               this.getZipCode(),
-                               this.getCity(),
-                               this.getCountryCode(),
-                               this.getPhoneNumber(),
-                               this.getFaxNumber(),
-                               this.getCellphoneNumber(),
-                               this.getEmailAddress(),
-                               this.getBirthday(),
-                               this.getComment()
-               );
-
-               // Then return it
-               return csvString;
-       }
-
        /**
         * Email address
         *
@@ -325,6 +294,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         */
        @Override
        public String getFamilyName () {
+               //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
                return this.familyName;
        }
 
@@ -335,6 +305,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         */
        @Override
        public final void setFamilyName (final String familyName) {
+               /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N
                this.familyName = familyName;
        }
 
@@ -358,6 +329,26 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                this.faxNumber = faxNumber;
        }
 
+       /**
+        * First name
+        *
+        * @return the firstName
+        */
+       @Override
+       public final String getFirstName () {
+               return this.firstName;
+       }
+
+       /**
+        * First name
+        *
+        * @param firstName the firstName to set
+        */
+       @Override
+       public final void setFirstName (final String firstName) {
+               this.firstName = firstName;
+       }
+
        /**
         * Gender of the contact
         *
@@ -384,7 +375,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return the houseNumber
         */
        @Override
-       public long getHouseNumber () {
+       public Long getHouseNumber () {
                return this.houseNumber;
        }
 
@@ -394,7 +385,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @param houseNumber the houseNumber to set
         */
        @Override
-       public final void setHouseNumber (final long houseNumber) {
+       public final void setHouseNumber (final Long houseNumber) {
                this.houseNumber = houseNumber;
        }
 
@@ -438,26 +429,6 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                this.street = street;
        }
 
-       /**
-        * Surname
-        *
-        * @return the surname
-        */
-       @Override
-       public final String getSurname () {
-               return this.surname;
-       }
-
-       /**
-        * Surname
-        *
-        * @param surname the surname to set
-        */
-       @Override
-       public final void setSurname (final String surname) {
-               this.surname = surname;
-       }
-
        /**
         * Some "getter" for a translated/human-readable gender
         *
@@ -480,27 +451,36 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return Value from field
         */
        @Override
-       public Object getValueFromColumn (final String columnName) {
+       public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
+               this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N
+
+               // A '$' means not our field
+               if (columnName.startsWith("$")) { //NOI18N
+                       // Don't handle these
+                       throw new IllegalArgumentException("columnsName contains $"); //NOI18N
+               }
 
                // Determine if the given column is boolean
-               if (this.isBooleanField(this, "BaseContact", columnName)) {
+               if (this.isBooleanField(this, "BaseContact", columnName)) { //NOI18N
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N
+
                        // Yes, then call other method
-                       return this.getBooleanField(this, "BaseContact", columnName);
+                       return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true)); //NOI18N
                }
 
                // Convert column name to field name
                String methodName = this.convertColumnNameToGetterMethod(columnName, false);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+               this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N
 
                // Get field
-               Object value = this.getField(this, "BaseContact", methodName);
+               Object value = this.getField(this, "BaseContact", methodName); //NOI18N
 
                // Trace message
-               this.getLogger().trace("value=" + value + " - EXIT!");
+               this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
 
                // Return it
                return value;
@@ -512,7 +492,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return the zipCode
         */
        @Override
-       public final long getZipCode () {
+       public final Long getZipCode () {
                return this.zipCode;
        }
 
@@ -522,32 +502,22 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @param zipCode the zipCode to set
         */
        @Override
-       public final void setZipCode (final long zipCode) {
+       public 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.";
+               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.getSurname());
+               hash = 79 * hash + Objects.hashCode(this.getFirstName());
                return hash;
        }
 
-       /**
-        * Checks whether the contact is user's own data
-        *
-        * @return Own data?
-        */
-       @Override
-       public final boolean isOwnContact () {
-               return this.ownContact;
-       }
-
        /**
         * Checks if given boolean field is available and set to same value
         *
@@ -556,39 +526,61 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return Whether all conditions are met
         */
        @Override
-       public boolean isValueEqual (final String columnName, final boolean bool) {
+       public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
+               this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool)); //NOI18N
 
                // Convert column name to field name
                String methodName = this.convertColumnNameToGetterMethod(columnName, true);
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("field={0}", methodName));
+               this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N
 
                // Init class instance
-               boolean value = this.getBooleanField(this, "BaseContact", methodName);
+               boolean value = this.getBooleanField(this, "BaseContact", methodName); //NOI18N
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("value={0}", value));
+               this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
 
                // Compare it
                boolean isFound = (bool == value);
 
                // Trace message
-               this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
+               this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
 
                // Return result
                return isFound;
        }
 
+       /**
+        * Checks whether the contact is user's own data
+        *
+        * @return Own data?
+        */
+       @Override
+       public final boolean isOwnContact () {
+               return this.ownContact;
+       }
+
        /**
         * Returns an iterator of all values from this object
         * @return An iterator
         */
        @Override
-       public Iterator<Object> iterator () {
-               return this.fieldIterator(this, "BaseContact");
+       public Iterator<Map.Entry<Field, Object>> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               return this.fieldIterator(this, "BaseContact"); //NOI18N
+       }
+
+       @Override
+       public void setValueFromColumn (final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value)); //NOI18N
+               
+               // Call super method
+               this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value); //NOI18N
+               
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
@@ -604,7 +596,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                // The client must be set
                if (client == null) {
                        // Not set
-                       throw new NullPointerException("client is null");
+                       throw new NullPointerException("client is null"); //NOI18N
                }
 
                // Display name "box"