]> git.mxchange.org Git - jcore.git/blobdiff - src/org/mxchange/jcore/contact/BaseContact.java
It has to be Long, with long you get zeros in forms
[jcore.git] / src / org / mxchange / jcore / contact / BaseContact.java
index 7b5b1c691470ada0e050c097b8a3f80a4e65b056..75f51fdf1d5ac358d1e88cd845a06ca1bf379d19 100644 (file)
  */
 package org.mxchange.jcore.contact;
 
+import java.lang.reflect.Field;
 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;
@@ -82,10 +85,10 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        /**
         * House number
         */
-       private int houseNumber;
+       private Long houseNumber;
 
        /**
-        * Marker whether this contact is user's own data
+        * Flag whether this contact is user's own data
         */
        private boolean ownContact;
 
@@ -107,7 +110,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        /**
         * ZIP code
         */
-       private long zipCode;
+       private Long zipCode;
 
        /**
         * No instances can be created of this class
@@ -152,6 +155,16 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                return this.birthday;
        }
 
+       /**
+        * Birth day
+        *
+        * @param birthday the birthday to set
+        */
+       @Override
+       public final void setBirthday (final String birthday) {
+               this.birthday = birthday;
+       }
+
        /**
         * Cellphone number
         *
@@ -162,6 +175,16 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                return this.cellphoneNumber;
        }
 
+       /**
+        * Cellphone number
+        *
+        * @param cellphoneNumber the cellphoneNumber to set
+        */
+       @Override
+       public final void setCellphoneNumber (final String cellphoneNumber) {
+               this.cellphoneNumber = cellphoneNumber;
+       }
+
        /**
         * City
         *
@@ -363,10 +386,20 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
         * @return the houseNumber
         */
        @Override
-       public int getHouseNumber () {
+       public Long getHouseNumber () {
                return this.houseNumber;
        }
 
+       /**
+        * House number
+        *
+        * @param houseNumber the houseNumber to set
+        */
+       @Override
+       public final void setHouseNumber (final Long houseNumber) {
+               this.houseNumber = houseNumber;
+       }
+
        /**
         * Phone number
         *
@@ -377,6 +410,16 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                return this.phoneNumber;
        }
 
+       /**
+        * Phone number
+        *
+        * @param phoneNumber the phoneNumber to set
+        */
+       @Override
+       public final void setPhoneNumber (final String phoneNumber) {
+               this.phoneNumber = phoneNumber;
+       }
+
        /**
         * Street
         *
@@ -407,6 +450,16 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                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
         *
@@ -421,13 +474,56 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                return translated;
        }
 
+       /**
+        * 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) throws IllegalArgumentException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
+
+               // A '$' means not our field
+               if (columnName.startsWith("$")) {
+                       // Don't handle these
+                       throw new IllegalArgumentException("columnsName contains $");
+               }
+
+               // Determine if the given column is boolean
+               if (this.isBooleanField(this, "BaseContact", columnName)) {
+                       // Debug message
+                       this.getLogger().debug("Column " + columnName + " represents a boolean field.");
+
+                       // Yes, then call other method
+                       return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true));
+               }
+
+               // 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;
+       }
+
        /**
         * ZIP code
         *
         * @return the zipCode
         */
        @Override
-       public final long getZipCode () {
+       public final Long getZipCode () {
                return this.zipCode;
        }
 
@@ -437,7 +533,7 @@ 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;
        }
 
@@ -463,6 +559,49 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
                return this.ownContact;
        }
 
+       /**
+        * 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;
+       }
+
+       /**
+        * Returns an iterator of all values from this object
+        * @return An iterator
+        */
+       @Override
+       public Iterator<Map.Entry<Field, Object>> iterator () {
+               return this.fieldIterator(this, "BaseContact");
+       }
+
        /**
         * Shows this contact to the user
         *
@@ -496,121 +635,4 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        protected final void enableFlagOwnContact () {
                this.ownContact = true;
        }
-
-       /**
-        * Surname
-        *
-        * @param surname the surname to set
-        */
-       @Override
-       public final void setSurname (final String surname) {
-               this.surname = surname;
-       }
-
-       /**
-        * Phone number
-        *
-        * @param phoneNumber the phoneNumber to set
-        */
-       @Override
-       public final void setPhoneNumber (final String phoneNumber) {
-               this.phoneNumber = phoneNumber;
-       }
-
-       /**
-        * House number
-        *
-        * @param houseNumber the houseNumber to set
-        */
-       public final void setHouseNumber (final int houseNumber) {
-               this.houseNumber = houseNumber;
-       }
-
-       /**
-        * Cellphone number
-        *
-        * @param cellphoneNumber the cellphoneNumber to set
-        */
-       @Override
-       public final void setCellphoneNumber (final String cellphoneNumber) {
-               this.cellphoneNumber = cellphoneNumber;
-       }
-
-       /**
-        * Birth day
-        *
-        * @param birthday the birthday to set
-        */
-       @Override
-       public 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;
-       }
 }