From: Roland Haeder Date: Fri, 4 Sep 2015 19:50:46 +0000 (+0200) Subject: It is part of the model. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=51d313937a598a0e0c68832923b97f9a151dbafa;p=jcore.git It is part of the model. Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 0e32cb5..aed856b 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -24,7 +24,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.mxchange.jcore.application.Application; import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.contact.Contact; +import org.mxchange.jcore.model.contact.Contact; import org.mxchange.jcore.manager.Manageable; /** diff --git a/src/org/mxchange/jcore/client/Client.java b/src/org/mxchange/jcore/client/Client.java index 5131773..475c91c 100644 --- a/src/org/mxchange/jcore/client/Client.java +++ b/src/org/mxchange/jcore/client/Client.java @@ -19,7 +19,7 @@ package org.mxchange.jcore.client; import java.io.IOException; import java.sql.SQLException; import org.mxchange.jcore.FrameworkInterface; -import org.mxchange.jcore.contact.Contact; +import org.mxchange.jcore.model.contact.Contact; /** * An interface for application clients diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java deleted file mode 100644 index c07b89b..0000000 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.contact; - -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jcore.BaseFrameworkSystem; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.contact.gender.Gender; - -/** - * A general contact class which should only be extended. - * - * @author Roland Haeder - * @version 0.0 - */ -public class BaseContact extends BaseFrameworkSystem implements Contact, Comparable { - - /** - * Id number - */ - private Long contactId; - - /** - * Birth day - */ - private String birthday; - - /** - * Cellphone number - */ - private String cellphoneNumber; - - /** - * City - */ - private String city; - - /** - * Optional comments - */ - private String comment; - - /** - * Companyname - */ - private String companyName; - - /** - * Country code - */ - private String countryCode; - - /** - * Email address - */ - private String emailAddress; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number - */ - private String faxNumber; - - /** - * First name - */ - private String firstName; - - /** - * Gender instance - */ - private Gender gender; - - /** - * House number - */ - private Long houseNumber; - - /** - * Flag whether this contact is user's own data - */ - private boolean ownContact; - - /** - * Phone number - */ - private String phoneNumber; - - /** - * Street - */ - private String street; - - /** - * ZIP code - */ - private Long zipCode; - - /** - * No instances should be created of this class. Better extend this class - * and provide proper constructors. - */ - protected BaseContact () { - // Fake gender - this.setGender(Gender.UNKNOWN); - } - - /** - * Check if contacts are same or throw an exception - * - * @param object Other possible contact class - * @return Whether both contacts are same - * TODO Needs a lot improvements - */ - @Override - public boolean equals (final Object object) { - // Is it same type? - if (!(object instanceof BaseContact)) { - // Not equal types - return false; - } else if (!(object instanceof Contact)) { - // Not correct interface - return false; - } - - // Try to cast - Contact contact = (Contact) object; - - // Now test some data TODO Definedly needs improvement - return ((this.getGender().equals(contact.getGender())) - && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase())) - && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); - } - - /** - * Birth day - * - * @return the birthday - */ - @Override - public String getBirthday () { - 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 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 - * - * @return the city - */ - @Override - public String getCity () { - return this.city; - } - - /** - * City - * - * @param city the city to set - */ - @Override - public final void setCity (final String city) { - this.city = city; - } - - /** - * Comments - * - * @return the comment - */ - @Override - public String getComment () { - return this.comment; - } - - /** - * Comments - * - * @param comment the comment to set - */ - @Override - public final void setComment (final String comment) { - this.comment = comment; - } - - /** - * Companyname - * - * @return the companyName - */ - @Override - public String getCompanyName () { - return this.companyName; - } - - /** - * Companyname - * - * @param companyName the companyName to set - */ - @Override - public final void setCompanyName (final String companyName) { - this.companyName = companyName; - } - - /** - * Id number - * @return the contactId - */ - @Override - public final Long getContactId () { - return this.contactId; - } - - /** - * Id number - * @param contactId the contactId to set - */ - @Override - public final void setContactId (final Long contactId) { - this.contactId = contactId; - } - - /** - * Country code - * - * @return the countryCode - */ - @Override - public String getCountryCode () { - return this.countryCode; - } - - /** - * Country code - * - * @param countryCode the countryCode to set - */ - @Override - public final void setCountryCode (final String countryCode) { - this.countryCode = countryCode; - } - - /** - * Email address - * - * @return the emailAddress - */ - @Override - public String getEmailAddress () { - return this.emailAddress; - } - - /** - * Email address - * - * @param emailAddress the emailAddress to set - */ - @Override - public final void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - /** - * Family name - * - * @return the familyName - */ - @Override - public String getFamilyName () { - //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); - return this.familyName; - } - - /** - * Family name - * - * @param familyName the familyName to set - */ - @Override - public final void setFamilyName (final String familyName) { - /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N - this.familyName = familyName; - } - - /** - * Fax number - * - * @return the faxNumber - */ - @Override - public String getFaxNumber () { - return this.faxNumber; - } - - /** - * Fax number - * - * @param faxNumber the faxNumber to set - */ - @Override - public final void setFaxNumber (final String faxNumber) { - 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 - * - * @return the gender - */ - @Override - public Gender getGender () { - return this.gender; - } - - /** - * Gender of the contact - * - * @param gender the gender to set - */ - @Override - public final void setGender (final Gender gender) { - this.gender = gender; - } - - /** - * House number - * - * @return the houseNumber - */ - @Override - 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 - * - * @return the phoneNumber - */ - @Override - public String getPhoneNumber () { - return this.phoneNumber; - } - - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ - @Override - public final void setPhoneNumber (final String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - /** - * Street - * - * @return the street - */ - @Override - public String getStreet () { - return this.street; - } - - /** - * Street - * - * @param street the street to set - */ - @Override - public final void setStreet (final String street) { - this.street = street; - } - - /** - * Some "getter" for a translated/human-readable gender - * - * @return gender Human-readable gender - */ - @Override - public String getTranslatedGender () { - // "Translate" it - String translated = this.getMessageStringFromKey(this.getGender().getMessageKey()); - - // Return it - return translated; - } - - /** - * ZIP code - * - * @return the zipCode - */ - @Override - public final Long getZipCode () { - return this.zipCode; - } - - /** - * ZIP code - * - * @param zipCode the zipCode to set - */ - @Override - 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."; //NOI18N - - int hash = 7; - hash = 79 * hash + Objects.hashCode(this.getFamilyName()); - hash = 79 * hash + this.getGender().hashCode(); - 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; - } - - /** - * Shows this contact to the user - * - * @param client Client instance to use - */ - @Override - public void show (final Client client) { - // Trace message - this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N - - // The client must be set - if (null == client) { - // Not set - throw new NullPointerException("client is null"); //NOI18N - } - - // Display name "box" - client.displayNameBox(this); - - // Display address "box" - client.displayAddressBox(this); - - // Display other data "box" - client.displayOtherDataBox(this); - } - - /** - * Enables the flag "own data" which signals that this contact is the user's - * own data. - */ - protected final void enableFlagOwnContact () { - this.ownContact = true; - } - - /** - * Compares two contacts with each other - * - * @param contact Contact comparator - * @return Comparison value - */ - @Override - public int compareTo (final Contact contact) { - // Trace message - this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N - - // contact should not be null - if (null == contact) { - throw new NullPointerException("contact is null"); //NOI18N - } - - // Debug message - this.getLogger().debug(MessageFormat.format("this.id={0},contact.id={1}", this.getContactId(), contact.getContactId())); //NOI18N - - // Is the contactId the same? - if (Objects.equals(this.getContactId(), contact.getContactId())) { - // Same contactId, means same contact - return 0; - } else if (this.getContactId() > contact.getContactId()) { - // This contactId is larger than compared to - return -1; - } - - // The other contactId is larger - return 1; - } -} diff --git a/src/org/mxchange/jcore/contact/Contact.java b/src/org/mxchange/jcore/contact/Contact.java deleted file mode 100644 index 8e59943..0000000 --- a/src/org/mxchange/jcore/contact/Contact.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.contact; - -import org.mxchange.jcore.FrameworkInterface; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.contact.gender.Gender; - -/** - * A general contact interface - * - * @author Roland Haeder - */ -public interface Contact extends FrameworkInterface, Comparable { - /** - * Some "getter" for translated gender of the contact - * - * @return Translated / human-readable gender - */ - public String getTranslatedGender (); - - /** - * Id number - * @return the contactId - */ - public Long getContactId (); - - /** - * Id number - * @param contactId the contactId to set - */ - public void setContactId (final Long contactId); - - /** - * Gender of the contact - * - * @return the gender - */ - public Gender getGender (); - - /** - * Gender of the contact - * - * @param gender the gender to set - */ - public void setGender (final Gender gender); - - /** - * First name - * - * @return the first name - */ - public String getFirstName (); - - /** - * First name - * - * @param firstName the first name to set - */ - public void setFirstName (final String firstName); - - /** - * Family name - * - * @return the familyName - */ - public String getFamilyName (); - - /** - * Family name - * - * @param familyName the familyName to set - */ - public void setFamilyName (final String familyName); - - /** - * Companyname - * - * @return the companyName - */ - public String getCompanyName (); - - /** - * Companyname - * - * @param companyName the companyName to set - */ - public void setCompanyName (final String companyName); - - /** - * Street - * - * @return the street - */ - public String getStreet (); - - /** - * Street - * - * @param street the street to set - */ - public void setStreet (final String street); - - /** - * House number - * - * @return the houseNumber - */ - public Long getHouseNumber (); - - /** - * House number - * - * @param houseNumber the houseNumber to set - */ - public void setHouseNumber (final Long houseNumber); - - /** - * ZIP code - * - * @return the zipCode - */ - public Long getZipCode (); - - /** - * ZIP code - * - * @param zipCode the zipCode to set - */ - public void setZipCode (final Long zipCode); - - /** - * City - * - * @return the city - */ - public String getCity (); - - /** - * City - * - * @param city the city to set - */ - public void setCity (final String city); - - /** - * Country code - * - * @return the countryCode - */ - public String getCountryCode (); - - /** - * Country code - * - * @param countryCode the countryCode to set - */ - public void setCountryCode (final String countryCode); - - /** - * Email address - * - * @return the emailAddress - */ - public String getEmailAddress (); - - /** - * Email address - * - * @param emailAddress the emailAddress to set - */ - public void setEmailAddress (final String emailAddress); - - /** - * Phone number - * - * @return the phoneNumber - */ - public String getPhoneNumber (); - - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set - */ - public void setPhoneNumber (final String phoneNumber); - - /** - * Fax number - * - * @return the faxNumber - */ - public String getFaxNumber (); - - /** - * Fax number - * - * @param faxNumber the faxNumber to set - */ - public void setFaxNumber (final String faxNumber); - - /** - * Cellphone number - * - * @return the cellphoneNumber - */ - public String getCellphoneNumber (); - - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set - */ - public void setCellphoneNumber (final String cellphoneNumber); - - /** - * Birth day - * - * @return the birthday - */ - public String getBirthday (); - - /** - * Birth day - * - * @param birthday the birthday to set - */ - public void setBirthday (final String birthday); - - /** - * Comments - * - * @return the comment - */ - public String getComment (); - - /** - * Comments - * - * @param comment the comment to set - */ - public void setComment (final String comment); - - /** - * Checks whether the contact is user's own data - * - * @return Own data? - */ - public boolean isOwnContact (); - - /** - * Shows the contact to the user - * - * @param client Client instance to call back - */ - public void show (final Client client); - - /** - * Compare method - * @param contact Contact to compare to - * @return Comparison value - */ - @Override - public int compareTo (final Contact contact); -} diff --git a/src/org/mxchange/jcore/contact/gender/Gender.java b/src/org/mxchange/jcore/contact/gender/Gender.java deleted file mode 100644 index 576851d..0000000 --- a/src/org/mxchange/jcore/contact/gender/Gender.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.contact.gender; - -import java.text.MessageFormat; - -/** - * Gender enum - * - * @author Roland Haeder - */ -public enum Gender { - /** - * Unknown enum - */ - UNKNOWN('U', "BaseContact.gender.unknown.text"), //NOI18N - - /** - * Male enum - */ - MALE('M', "BaseContact.gender.male.text"), //NOI18N - - /** - * Female enum - */ - FEMALE('F', "BaseContact.gender.female.text"), //NOI18N - - /** - * Company enum - */ - COMPANY('C', "BaseContact.gender.company.text"); //NOI18N - - /** - * Cache for valid chars - */ - private static char[] validChars; - - /** - * Access key being entered by ConsoleClient - */ - private final char accessChar; - - /** - * Output value (for messages) - */ - private final String messageKey; - - /** - * Getter for Gender enum from given character - * - * @param c Gender character - * @return Gender enum - */ - public static Gender fromChar (final char c) { - // Init variable - Gender g = null; - - // Loop through all - for (final Gender gender : GenderUtils.selectableGenders()) { - // Does the char match? - if (c == gender.getAccessChar()) { - // Found it - g = gender; - break; - } - } - - // Still null? - if (null == g) { - // Didn't found a valid one - throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N - } - - // Return it - //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName()); - return g; - } - - /** - * Valid chars (mostly for console client) - * - * @return Valid chars - */ - public static char[] validChars () { - // Is cache set? - if (validChars != null) { - // Return it - return validChars; - } - - // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid. - char[] valid = new char[3]; - - // Get values - int i = 0; - for (final Gender gender : GenderUtils.selectableGenders()) { - // Debug message - //* NOISY-DEBUG: */ System.out.println("gender=" + gender); - - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i)); - - // Get access key as this is also the access - valid[i] = gender.getAccessChar(); - - // Increment index - i++; - } - - // Set it here - validChars = valid; - - // Return finialized array - return valid; - } - - /** - * Constructor - * - * @param accessChar Value being entered by ConsoleClient - * @param messageKey Message key for resource file - */ - private Gender (final char accessChar, final String messageKey) { - // Set both - this.accessChar = accessChar; - this.messageKey = messageKey; - } - - /** - * Acces key (console client mostly) - * - * @return the accessChar - */ - public char getAccessChar () { - return this.accessChar; - } - - /** - * Output value (for messages) - * - * @return the messageKey - */ - public String getMessageKey () { - return this.messageKey; - } -} diff --git a/src/org/mxchange/jcore/contact/gender/GenderUtils.java b/src/org/mxchange/jcore/contact/gender/GenderUtils.java deleted file mode 100644 index 1fb0992..0000000 --- a/src/org/mxchange/jcore/contact/gender/GenderUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.contact.gender; - -import java.text.MessageFormat; -import java.util.LinkedList; -import java.util.List; -import org.mxchange.jcore.BaseFrameworkSystem; - -/** - * Gender utils class - * - * @author Roland Haeder - */ -public final class GenderUtils extends BaseFrameworkSystem { - /** - * Private contructor as this is an utility class - */ - private GenderUtils () { - } - - /** - * All selectable genders (not UNKNOWN) - * - * @return Selectable genders (not UNKNOWN) - */ - public static List selectableGenders () { - // Trace message - new GenderUtils().getLogger().trace("CALLED!"); //NOI18N - - // Init list - List list = new LinkedList<>(); - - // Walk through all genders - for (final Gender gender : Gender.values()) { - // Debug log - new GenderUtils().getLogger().debug(MessageFormat.format("gender={0}", gender)); //NOI18N - - // Is it not UNKNOWN - if (!gender.equals(Gender.UNKNOWN)) { - // Add it - boolean added = list.add(gender); - - // Has it been added? - assert(added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N - } - } - - // Trace message - new GenderUtils().getLogger().trace(MessageFormat.format("list={0} - EXIT!", list)); //NOI18N - - // Return it - return list; - } -} diff --git a/src/org/mxchange/jcore/model/contact/BaseContact.java b/src/org/mxchange/jcore/model/contact/BaseContact.java new file mode 100644 index 0000000..2202b00 --- /dev/null +++ b/src/org/mxchange/jcore/model/contact/BaseContact.java @@ -0,0 +1,575 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.model.contact; + +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jcore.client.Client; +import org.mxchange.jcore.model.contact.gender.Gender; + +/** + * A general contact class which should only be extended. + * + * @author Roland Haeder + * @version 0.0 + */ +public class BaseContact extends BaseFrameworkSystem implements Contact, Comparable { + + /** + * Id number + */ + private Long contactId; + + /** + * Birth day + */ + private String birthday; + + /** + * Cellphone number + */ + private String cellphoneNumber; + + /** + * City + */ + private String city; + + /** + * Optional comments + */ + private String comment; + + /** + * Companyname + */ + private String companyName; + + /** + * Country code + */ + private String countryCode; + + /** + * Email address + */ + private String emailAddress; + + /** + * Family name + */ + private String familyName; + + /** + * Fax number + */ + private String faxNumber; + + /** + * First name + */ + private String firstName; + + /** + * Gender instance + */ + private Gender gender; + + /** + * House number + */ + private Long houseNumber; + + /** + * Flag whether this contact is user's own data + */ + private boolean ownContact; + + /** + * Phone number + */ + private String phoneNumber; + + /** + * Street + */ + private String street; + + /** + * ZIP code + */ + private Long zipCode; + + /** + * No instances should be created of this class. Better extend this class + * and provide proper constructors. + */ + protected BaseContact () { + // Fake gender + this.setGender(Gender.UNKNOWN); + } + + /** + * Check if contacts are same or throw an exception + * + * @param object Other possible contact class + * @return Whether both contacts are same + * TODO Needs a lot improvements + */ + @Override + public boolean equals (final Object object) { + // Is it same type? + if (!(object instanceof BaseContact)) { + // Not equal types + return false; + } else if (!(object instanceof Contact)) { + // Not correct interface + return false; + } + + // Try to cast + Contact contact = (Contact) object; + + // Now test some data TODO Definedly needs improvement + return ((this.getGender().equals(contact.getGender())) + && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase())) + && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); + } + + /** + * Birth day + * + * @return the birthday + */ + @Override + public String getBirthday () { + 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 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 + * + * @return the city + */ + @Override + public String getCity () { + return this.city; + } + + /** + * City + * + * @param city the city to set + */ + @Override + public final void setCity (final String city) { + this.city = city; + } + + /** + * Comments + * + * @return the comment + */ + @Override + public String getComment () { + return this.comment; + } + + /** + * Comments + * + * @param comment the comment to set + */ + @Override + public final void setComment (final String comment) { + this.comment = comment; + } + + /** + * Companyname + * + * @return the companyName + */ + @Override + public String getCompanyName () { + return this.companyName; + } + + /** + * Companyname + * + * @param companyName the companyName to set + */ + @Override + public final void setCompanyName (final String companyName) { + this.companyName = companyName; + } + + /** + * Id number + * @return the contactId + */ + @Override + public final Long getContactId () { + return this.contactId; + } + + /** + * Id number + * @param contactId the contactId to set + */ + @Override + public final void setContactId (final Long contactId) { + this.contactId = contactId; + } + + /** + * Country code + * + * @return the countryCode + */ + @Override + public String getCountryCode () { + return this.countryCode; + } + + /** + * Country code + * + * @param countryCode the countryCode to set + */ + @Override + public final void setCountryCode (final String countryCode) { + this.countryCode = countryCode; + } + + /** + * Email address + * + * @return the emailAddress + */ + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + /** + * Email address + * + * @param emailAddress the emailAddress to set + */ + @Override + public final void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Family name + * + * @return the familyName + */ + @Override + public String getFamilyName () { + //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!"); + return this.familyName; + } + + /** + * Family name + * + * @param familyName the familyName to set + */ + @Override + public final void setFamilyName (final String familyName) { + /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N + this.familyName = familyName; + } + + /** + * Fax number + * + * @return the faxNumber + */ + @Override + public String getFaxNumber () { + return this.faxNumber; + } + + /** + * Fax number + * + * @param faxNumber the faxNumber to set + */ + @Override + public final void setFaxNumber (final String faxNumber) { + 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 + * + * @return the gender + */ + @Override + public Gender getGender () { + return this.gender; + } + + /** + * Gender of the contact + * + * @param gender the gender to set + */ + @Override + public final void setGender (final Gender gender) { + this.gender = gender; + } + + /** + * House number + * + * @return the houseNumber + */ + @Override + 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 + * + * @return the phoneNumber + */ + @Override + public String getPhoneNumber () { + return this.phoneNumber; + } + + /** + * Phone number + * + * @param phoneNumber the phoneNumber to set + */ + @Override + public final void setPhoneNumber (final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /** + * Street + * + * @return the street + */ + @Override + public String getStreet () { + return this.street; + } + + /** + * Street + * + * @param street the street to set + */ + @Override + public final void setStreet (final String street) { + this.street = street; + } + + /** + * Some "getter" for a translated/human-readable gender + * + * @return gender Human-readable gender + */ + @Override + public String getTranslatedGender () { + // "Translate" it + String translated = this.getMessageStringFromKey(this.getGender().getMessageKey()); + + // Return it + return translated; + } + + /** + * ZIP code + * + * @return the zipCode + */ + @Override + public final Long getZipCode () { + return this.zipCode; + } + + /** + * ZIP code + * + * @param zipCode the zipCode to set + */ + @Override + 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."; //NOI18N + + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.getFamilyName()); + hash = 79 * hash + this.getGender().hashCode(); + 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; + } + + /** + * Shows this contact to the user + * + * @param client Client instance to use + */ + @Override + public void show (final Client client) { + // Trace message + this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N + + // The client must be set + if (null == client) { + // Not set + throw new NullPointerException("client is null"); //NOI18N + } + + // Display name "box" + client.displayNameBox(this); + + // Display address "box" + client.displayAddressBox(this); + + // Display other data "box" + client.displayOtherDataBox(this); + } + + /** + * Enables the flag "own data" which signals that this contact is the user's + * own data. + */ + protected final void enableFlagOwnContact () { + this.ownContact = true; + } + + /** + * Compares two contacts with each other + * + * @param contact Contact comparator + * @return Comparison value + */ + @Override + public int compareTo (final Contact contact) { + // Trace message + this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N + + // contact should not be null + if (null == contact) { + throw new NullPointerException("contact is null"); //NOI18N + } + + // Debug message + this.getLogger().debug(MessageFormat.format("this.id={0},contact.id={1}", this.getContactId(), contact.getContactId())); //NOI18N + + // Is the contactId the same? + if (Objects.equals(this.getContactId(), contact.getContactId())) { + // Same contactId, means same contact + return 0; + } else if (this.getContactId() > contact.getContactId()) { + // This contactId is larger than compared to + return -1; + } + + // The other contactId is larger + return 1; + } +} diff --git a/src/org/mxchange/jcore/model/contact/Contact.java b/src/org/mxchange/jcore/model/contact/Contact.java new file mode 100644 index 0000000..2fbc3a0 --- /dev/null +++ b/src/org/mxchange/jcore/model/contact/Contact.java @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.model.contact; + +import org.mxchange.jcore.FrameworkInterface; +import org.mxchange.jcore.client.Client; +import org.mxchange.jcore.model.contact.gender.Gender; + +/** + * A general contact interface + * + * @author Roland Haeder + */ +public interface Contact extends FrameworkInterface, Comparable { + /** + * Some "getter" for translated gender of the contact + * + * @return Translated / human-readable gender + */ + public String getTranslatedGender (); + + /** + * Id number + * @return the contactId + */ + public Long getContactId (); + + /** + * Id number + * @param contactId the contactId to set + */ + public void setContactId (final Long contactId); + + /** + * Gender of the contact + * + * @return the gender + */ + public Gender getGender (); + + /** + * Gender of the contact + * + * @param gender the gender to set + */ + public void setGender (final Gender gender); + + /** + * First name + * + * @return the first name + */ + public String getFirstName (); + + /** + * First name + * + * @param firstName the first name to set + */ + public void setFirstName (final String firstName); + + /** + * Family name + * + * @return the familyName + */ + public String getFamilyName (); + + /** + * Family name + * + * @param familyName the familyName to set + */ + public void setFamilyName (final String familyName); + + /** + * Companyname + * + * @return the companyName + */ + public String getCompanyName (); + + /** + * Companyname + * + * @param companyName the companyName to set + */ + public void setCompanyName (final String companyName); + + /** + * Street + * + * @return the street + */ + public String getStreet (); + + /** + * Street + * + * @param street the street to set + */ + public void setStreet (final String street); + + /** + * House number + * + * @return the houseNumber + */ + public Long getHouseNumber (); + + /** + * House number + * + * @param houseNumber the houseNumber to set + */ + public void setHouseNumber (final Long houseNumber); + + /** + * ZIP code + * + * @return the zipCode + */ + public Long getZipCode (); + + /** + * ZIP code + * + * @param zipCode the zipCode to set + */ + public void setZipCode (final Long zipCode); + + /** + * City + * + * @return the city + */ + public String getCity (); + + /** + * City + * + * @param city the city to set + */ + public void setCity (final String city); + + /** + * Country code + * + * @return the countryCode + */ + public String getCountryCode (); + + /** + * Country code + * + * @param countryCode the countryCode to set + */ + public void setCountryCode (final String countryCode); + + /** + * Email address + * + * @return the emailAddress + */ + public String getEmailAddress (); + + /** + * Email address + * + * @param emailAddress the emailAddress to set + */ + public void setEmailAddress (final String emailAddress); + + /** + * Phone number + * + * @return the phoneNumber + */ + public String getPhoneNumber (); + + /** + * Phone number + * + * @param phoneNumber the phoneNumber to set + */ + public void setPhoneNumber (final String phoneNumber); + + /** + * Fax number + * + * @return the faxNumber + */ + public String getFaxNumber (); + + /** + * Fax number + * + * @param faxNumber the faxNumber to set + */ + public void setFaxNumber (final String faxNumber); + + /** + * Cellphone number + * + * @return the cellphoneNumber + */ + public String getCellphoneNumber (); + + /** + * Cellphone number + * + * @param cellphoneNumber the cellphoneNumber to set + */ + public void setCellphoneNumber (final String cellphoneNumber); + + /** + * Birth day + * + * @return the birthday + */ + public String getBirthday (); + + /** + * Birth day + * + * @param birthday the birthday to set + */ + public void setBirthday (final String birthday); + + /** + * Comments + * + * @return the comment + */ + public String getComment (); + + /** + * Comments + * + * @param comment the comment to set + */ + public void setComment (final String comment); + + /** + * Checks whether the contact is user's own data + * + * @return Own data? + */ + public boolean isOwnContact (); + + /** + * Shows the contact to the user + * + * @param client Client instance to call back + */ + public void show (final Client client); + + /** + * Compare method + * @param contact Contact to compare to + * @return Comparison value + */ + @Override + public int compareTo (final Contact contact); +} diff --git a/src/org/mxchange/jcore/model/contact/gender/Gender.java b/src/org/mxchange/jcore/model/contact/gender/Gender.java new file mode 100644 index 0000000..6e8faaa --- /dev/null +++ b/src/org/mxchange/jcore/model/contact/gender/Gender.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.model.contact.gender; + +import java.text.MessageFormat; + +/** + * Gender enum + * + * @author Roland Haeder + */ +public enum Gender { + /** + * Unknown enum + */ + UNKNOWN('U', "BaseContact.gender.unknown.text"), //NOI18N + + /** + * Male enum + */ + MALE('M', "BaseContact.gender.male.text"), //NOI18N + + /** + * Female enum + */ + FEMALE('F', "BaseContact.gender.female.text"), //NOI18N + + /** + * Company enum + */ + COMPANY('C', "BaseContact.gender.company.text"); //NOI18N + + /** + * Cache for valid chars + */ + private static char[] validChars; + + /** + * Access key being entered by ConsoleClient + */ + private final char accessChar; + + /** + * Output value (for messages) + */ + private final String messageKey; + + /** + * Getter for Gender enum from given character + * + * @param c Gender character + * @return Gender enum + */ + public static Gender fromChar (final char c) { + // Init variable + Gender g = null; + + // Loop through all + for (final Gender gender : GenderUtils.selectableGenders()) { + // Does the char match? + if (c == gender.getAccessChar()) { + // Found it + g = gender; + break; + } + } + + // Still null? + if (null == g) { + // Didn't found a valid one + throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N + } + + // Return it + //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName()); + return g; + } + + /** + * Valid chars (mostly for console client) + * + * @return Valid chars + */ + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid. + char[] valid = new char[3]; + + // Get values + int i = 0; + for (final Gender gender : GenderUtils.selectableGenders()) { + // Debug message + //* NOISY-DEBUG: */ System.out.println("gender=" + gender); + + // Debug message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i)); + + // Get access key as this is also the access + valid[i] = gender.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Constructor + * + * @param accessChar Value being entered by ConsoleClient + * @param messageKey Message key for resource file + */ + private Gender (final char accessChar, final String messageKey) { + // Set both + this.accessChar = accessChar; + this.messageKey = messageKey; + } + + /** + * Acces key (console client mostly) + * + * @return the accessChar + */ + public char getAccessChar () { + return this.accessChar; + } + + /** + * Output value (for messages) + * + * @return the messageKey + */ + public String getMessageKey () { + return this.messageKey; + } +} diff --git a/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java b/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java new file mode 100644 index 0000000..c971cba --- /dev/null +++ b/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcore.model.contact.gender; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import org.mxchange.jcore.BaseFrameworkSystem; + +/** + * Gender utils class + * + * @author Roland Haeder + */ +public final class GenderUtils extends BaseFrameworkSystem { + /** + * Private contructor as this is an utility class + */ + private GenderUtils () { + } + + /** + * All selectable genders (not UNKNOWN) + * + * @return Selectable genders (not UNKNOWN) + */ + public static List selectableGenders () { + // Trace message + new GenderUtils().getLogger().trace("CALLED!"); //NOI18N + + // Init list + List list = new LinkedList<>(); + + // Walk through all genders + for (final Gender gender : Gender.values()) { + // Debug log + new GenderUtils().getLogger().debug(MessageFormat.format("gender={0}", gender)); //NOI18N + + // Is it not UNKNOWN + if (!gender.equals(Gender.UNKNOWN)) { + // Add it + boolean added = list.add(gender); + + // Has it been added? + assert(added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N + } + } + + // Trace message + new GenderUtils().getLogger().trace(MessageFormat.format("list={0} - EXIT!", list)); //NOI18N + + // Return it + return list; + } +}