]> git.mxchange.org Git - jcore.git/blobdiff - src/org/mxchange/jcore/contact/BaseContact.java
Better return an iterator of Map.Entry<Field, Object>. This is really generic, it...
[jcore.git] / src / org / mxchange / jcore / contact / BaseContact.java
index f0bf18b7cada8536b82b66332f297cd1c2482f1d..b817a594721c68e4a062796b1b5a2edf63e13fa4 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;
@@ -479,28 +482,37 @@ 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 {
                // 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", columnName);
+                       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;
        }
@@ -558,29 +570,38 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        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
         *
@@ -590,19 +611,19 @@ public class BaseContact extends BaseFrameworkSystem implements Contact {
        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");
                }
-               
+
                // Display name "box"
                client.displayNameBox(this);
-               
+
                // Display address "box"
                client.displayAddressBox(this);
-               
+
                // Display other data "box"
                client.displayOtherDataBox(this);
        }