X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcore%2Fcontact%2FBaseContact.java;h=71a7d30021e3531f0526a87fd5661fc1643d6fc6;hb=10598f2ffeebd25b659f61e4e528f2ec9d25f41e;hp=a30dcc59381618535ed0935f1704f6f8b69bd275;hpb=eb98bf71c1ef80b7dc42baf1d441579f0f3f6ed8;p=jcore.git diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index a30dcc5..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 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,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 () { } @@ -152,16 +157,36 @@ 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 * * @return the cellphoneNumber */ @Override - public String getCellphoneNumber () { + public final String getCellphoneNumber () { return this.cellphoneNumber; } + /** + * Cellphone number + * + * @param cellphoneNumber the cellphoneNumber to set + */ + @Override + public final void setCellphoneNumber (final String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + /** * City * @@ -177,7 +202,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param city the city to set */ - private void setCity (final String city) { + @Override + public final void setCity (final String city) { this.city = city; } @@ -196,7 +222,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param comment the comment to set */ - private void setComment (final String comment) { + @Override + public final void setComment (final String comment) { this.comment = comment; } @@ -215,7 +242,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param companyName the companyName to set */ - private void setCompanyName (final String companyName) { + @Override + public final void setCompanyName (final String companyName) { this.companyName = companyName; } @@ -234,45 +262,11 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param countryCode the countryCode to set */ - private void setCountryCode (final String countryCode) { + @Override + public final void setCountryCode (final String countryCode) { 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 * @@ -288,7 +282,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param emailAddress the emailAddress to set */ - private void setEmailAddress (final String emailAddress) { + @Override + public final void setEmailAddress (final String emailAddress) { this.emailAddress = emailAddress; } @@ -299,6 +294,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { */ @Override public String getFamilyName () { + //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); return this.familyName; } @@ -307,7 +303,9 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param familyName the familyName to set */ - private void setFamilyName (final String familyName) { + @Override + public final void setFamilyName (final String familyName) { + /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); this.familyName = familyName; } @@ -326,7 +324,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param faxNumber the faxNumber to set */ - private void setFaxNumber (final String faxNumber) { + @Override + public final void setFaxNumber (final String faxNumber) { this.faxNumber = faxNumber; } @@ -345,7 +344,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param gender the gender to set */ - private void setGender (final Gender gender) { + @Override + public final void setGender (final Gender gender) { this.gender = gender; } @@ -355,10 +355,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 * @@ -369,6 +379,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 * @@ -384,7 +404,8 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param street the street to set */ - protected final void setStreet (final String street) { + @Override + public final void setStreet (final String street) { this.street = street; } @@ -398,6 +419,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 * @@ -412,13 +443,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, 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", 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; } @@ -427,10 +501,11 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * * @param zipCode the zipCode to set */ - protected final void setZipCode (final long zipCode) { + @Override + public final void setZipCode (final Long zipCode) { this.zipCode = zipCode; } - + @Override public int hashCode () { // Validate gender instance @@ -454,129 +529,72 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { } /** - * Shows this contact to the user + * Checks if given boolean field is available and set to same value * - * @param client Client instance to use + * @param columnName Column name to check + * @param bool Boolean value + * @return Whether all conditions are met */ @Override - public void show (final Client client) { + public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // 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"); - } + this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool)); - // Display name "box" - client.displayNameBox(this); + // Convert column name to field name + String methodName = this.convertColumnNameToGetterMethod(columnName, true); - // Display address "box" - client.displayAddressBox(this); + // Debug message + this.getLogger().debug(MessageFormat.format("field={0}", methodName)); - // Display other data "box" - client.displayOtherDataBox(this); - } + // Init class instance + boolean value = this.getBooleanField(this, "BaseContact", methodName); - /** - * Updates address data in this Contact instance - * - * @param street Street - * @param zipCode ZIP code - * @param city City - * @param countryCode Country code - */ - @Override - 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 + // Debug message + this.getLogger().debug(MessageFormat.format("value={0}", value)); - // Set all - if (street != null) { - this.setStreet(street); - } - if (zipCode > 0) { - this.setZipCode(zipCode); - } - if (city != null) { - this.setCity(city); - } - if (countryCode != null) { - this.setCountryCode(countryCode); - } + // Compare it + boolean isFound = (bool == value); // Trace message - this.getLogger().trace("EXIT!"); //NOI18N + this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); + + // Return result + return isFound; } /** - * Updates name data in this Contact instance - * - * @param gender Gender (M, F, C) - * @param surname Surname - * @param familyName Family name - * @param companyName Company name + * Returns an iterator of all values from this object + * @return An iterator */ @Override - 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); - } - if (familyName != null) { - this.setFamilyName(familyName); - } - if (companyName != null) { - this.setCompanyName(companyName); - } - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N + public Iterator> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + return this.fieldIterator(this, "BaseContact"); } /** - * Updates other data in this Contact instance + * Shows this contact to the user * - * @param phoneNumber Phone number - * @param cellphoneNumber Cellphone number - * @param faxNumber Fax number - * @param emailAddress Email address - * @param birthday Birth day - * @param comment Comments + * @param client Client instance to use */ @Override - public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) { + public void show (final Client client) { // 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 + this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N - // Set all - if (phoneNumber != null) { - this.setPhoneNumber(phoneNumber); - } - if (cellphoneNumber != null) { - this.setCellphoneNumber(cellphoneNumber); - } - if (faxNumber != null) { - this.setFaxNumber(faxNumber); - } - if (emailAddress != null) { - this.setEmailAddress(emailAddress); - } - if (birthday != null) { - this.setBirthday(birthday); - } - if (comment != null) { - this.setComment(comment); + // The client must be set + if (client == null) { + // Not set + throw new NullPointerException("client is null"); } - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N + // Display name "box" + client.displayNameBox(this); + + // Display address "box" + client.displayAddressBox(this); + + // Display other data "box" + client.displayOtherDataBox(this); } /** @@ -587,116 +605,15 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { this.ownContact = true; } - /** - * Surname - * - * @param surname the surname to set - */ - protected final void setSurname (final String surname) { - this.surname = surname; - } - - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ - protected final void setPhoneNumber (final String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - /** - * House number - * - * @param houseNumber the houseNumber to set - */ - protected final void setHouseNumber (final int houseNumber) { - this.houseNumber = houseNumber; - } - - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set - */ - protected final void setCellphoneNumber (final String cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - /** - * Birth day - * - * @param birthday the birthday to set - */ - 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) { + public void setValueFromColumn (final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // 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; - } + this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value)); + + // Call super method + this.setValueInStoreableFromColumn(this, "BaseContact", columnName, 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; + this.getLogger().trace("EXIT!"); } }