X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcore%2Fcontact%2FBaseContact.java;h=71a7d30021e3531f0526a87fd5661fc1643d6fc6;hb=10598f2ffeebd25b659f61e4e528f2ec9d25f41e;hp=9463538ffd59004856b997f74e381aef7e6907d5;hpb=e200822df53ed15d17fdb8f90743d9b9d148c30c;p=jcore.git diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 9463538..71a7d30 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -16,13 +16,17 @@ */ 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 @@ -82,10 +86,10 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { /** * House number */ - private long 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,10 +111,11 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { /** * 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 () { } @@ -168,7 +173,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * @return the cellphoneNumber */ @Override - public String getCellphoneNumber () { + public final String getCellphoneNumber () { return this.cellphoneNumber; } @@ -262,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 * @@ -324,6 +294,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { */ @Override public String getFamilyName () { + //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); return this.familyName; } @@ -334,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)); this.familyName = familyName; } @@ -383,7 +355,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * @return the houseNumber */ @Override - public long getHouseNumber () { + public Long getHouseNumber () { return this.houseNumber; } @@ -393,7 +365,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; } @@ -479,28 +451,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, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // 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; } @@ -511,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; } @@ -521,7 +502,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; } @@ -555,32 +536,41 @@ 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)); - + // 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> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + return this.fieldIterator(this, "BaseContact"); + } + /** * Shows this contact to the user * @@ -590,19 +580,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); } @@ -614,4 +604,16 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { protected final void enableFlagOwnContact () { this.ownContact = true; } + + @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)); + + // Call super method + this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value); + + // Trace message + this.getLogger().trace("EXIT!"); + } }