X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Addressbook%2Fsrc%2Forg%2Fmxchange%2Faddressbook%2Fcontact%2FBaseContact.java;h=2a1ecb73ffd0bbf9d1f3605b063a71355379bf39;hb=26e5c3c4c49253578272a4fd6b121e76004dd414;hp=95335ff7978a0d2fb1efdb6d02bdf8c3b9cfd3e1;hpb=0490615f8cc85a9462dcd1514dfe58c637edea5b;p=jfinancials-swing.git diff --git a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java index 95335ff..2a1ecb7 100644 --- a/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java +++ b/Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.contact; +import java.util.Objects; import org.mxchange.addressbook.BaseFrameworkSystem; import org.mxchange.addressbook.client.Client; @@ -106,7 +107,7 @@ public class BaseContact extends BaseFrameworkSystem { /** * ZIP code */ - private int zipCode; + private long zipCode; /** * No instances can be created of this class @@ -115,31 +116,31 @@ public class BaseContact extends BaseFrameworkSystem { super(); } - /** - * Enables the flag "own data" which signals that this contact is the user's - * own data. - */ - public void enableFlagOwnContact () { - this.ownContact = true; - } - /** * 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 (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 - BaseContact c = (BaseContact) object; + Contact contact = (Contact) object; - /* - * Now test some data @todo Definedly needs improvement - */ - return ((this.getGender() == c.getGender()) - && (this.getSurname().toLowerCase().equals(c.getSurname().toLowerCase())) - && (this.getFamilyName().toLowerCase().equals(c.getFamilyName().toLowerCase()))); + // Now test some data @todo Definedly needs improvement + return ((this.getGender() == contact.getGender()) + && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase())) + && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase()))); } /** @@ -250,6 +251,36 @@ public class BaseContact extends BaseFrameworkSystem { this.countryCode = countryCode; } + /** + * "Serializes" this object into a CSV string (this time with semicolons) + * + * @return "CSV-serialized" version of the stored data + */ + public String getCsvStringFromStoreableObject () { + // Get all together + String csvString = String.format( + "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n", + this.isOwnContact(), + this.getGender(), + 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 * @@ -430,7 +461,7 @@ public class BaseContact extends BaseFrameworkSystem { * * @return the zipCode */ - public int getZipCode () { + public long getZipCode () { return this.zipCode; } @@ -439,10 +470,19 @@ public class BaseContact extends BaseFrameworkSystem { * * @param zipCode the zipCode to set */ - public void setZipCode (final int zipCode) { + public void setZipCode (final long zipCode) { this.zipCode = zipCode; } + @Override + public int hashCode () { + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.getFamilyName()); + hash = 79 * hash + this.getGender(); + hash = 79 * hash + Objects.hashCode(this.getSurname()); + return hash; + } + /** * Checks whether the contact is user's own data * @@ -467,4 +507,89 @@ public class BaseContact extends BaseFrameworkSystem { // Display other data "box" client.displayOtherDataBox((Contact) this); } + + /** + * Updates address data in this Contact instance + * + * @param street Street + * @param zipCode ZIP code + * @param city City + * @param countryCode Country code + */ + public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) { + // 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); + } + } + + /** + * Updates name data in this Contact instance + * @param gender Gender (M, F, C) + * @param surname Surname + * @param familyName Family name + * @param companyName Company name + */ + public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) { + // Set all + this.setGender(gender); + if (surname != null) { + this.setSurname(surname); + } + if (familyName != null) { + this.setFamilyName(familyName); + } + if (companyName != null) { + this.setCompanyName(companyName); + } + } + + /** + * Updates other data in this Contact instance + * + * @param phoneNumber Phone number + * @param cellphoneNumber Cellphone number + * @param faxNumber Fax number + * @param emailAddress Email address + * @param birthday Birth day + * @param comment Comments + */ + public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) { + // 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); + } + } + + /** + * Enables the flag "own data" which signals that this contact is the user's + * own data. + */ + protected void enableFlagOwnContact () { + this.ownContact = true; + } }