*/\r
package org.mxchange.addressbook.contact;\r
\r
+import java.util.Objects;\r
import org.mxchange.addressbook.BaseFrameworkSystem;\r
import org.mxchange.addressbook.client.Client;\r
\r
/**\r
* ZIP code\r
*/\r
- private int zipCode;\r
+ private long zipCode;\r
\r
/**\r
* No instances can be created of this class\r
super();\r
}\r
\r
- /**\r
- * Enables the flag "own data" which signals that this contact is the user's\r
- * own data.\r
- */\r
- public void enableFlagOwnContact () {\r
- this.ownContact = true;\r
- }\r
-\r
/**\r
* Check if contacts are same or throw an exception\r
*\r
* @param object Other possible contact class\r
* @return Whether both contacts are same\r
+ * @todo Needs a lot improvements\r
*/\r
@Override\r
public boolean equals (Object object) {\r
+ // Is it same type?\r
+ if (!(object instanceof BaseContact)) {\r
+ // Not equal types\r
+ return false;\r
+ } else if (!(object instanceof Contact)) {\r
+ // Not correct interface\r
+ return false;\r
+ }\r
+\r
// Try to cast\r
- BaseContact c = (BaseContact) object;\r
+ Contact contact = (Contact) object;\r
\r
- /*\r
- * Now test some data @todo Definedly needs improvement\r
- */\r
- return ((this.getGender() == c.getGender())\r
- && (this.getSurname().toLowerCase().equals(c.getSurname().toLowerCase()))\r
- && (this.getFamilyName().toLowerCase().equals(c.getFamilyName().toLowerCase())));\r
+ // Now test some data @todo Definedly needs improvement\r
+ return ((this.getGender() == contact.getGender())\r
+ && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))\r
+ && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));\r
}\r
\r
/**\r
this.countryCode = countryCode;\r
}\r
\r
+ /**\r
+ * "Serializes" this object into a CSV string (this time with semicolons)\r
+ *\r
+ * @return "CSV-serialized" version of the stored data\r
+ */\r
+ public String getCsvStringFromStoreableObject () {\r
+ // Get all together\r
+ String csvString = String.format(\r
+ "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",\r
+ this.isOwnContact(),\r
+ this.getGender(),\r
+ this.getSurname(),\r
+ this.getFamilyName(),\r
+ this.getCompanyName(),\r
+ this.getStreet(),\r
+ this.getZipCode(),\r
+ this.getCity(),\r
+ this.getCountryCode(),\r
+ this.getPhoneNumber(),\r
+ this.getFaxNumber(),\r
+ this.getCellphoneNumber(),\r
+ this.getEmailAddress(),\r
+ this.getBirthday(),\r
+ this.getComment()\r
+ );\r
+ \r
+ // Then return it\r
+ return csvString;\r
+ }\r
+\r
/**\r
* Email address\r
*\r
*\r
* @return the zipCode\r
*/\r
- public int getZipCode () {\r
+ public long getZipCode () {\r
return this.zipCode;\r
}\r
\r
*\r
* @param zipCode the zipCode to set\r
*/\r
- public void setZipCode (final int zipCode) {\r
+ public void setZipCode (final long zipCode) {\r
this.zipCode = zipCode;\r
}\r
\r
+ @Override\r
+ public int hashCode () {\r
+ int hash = 7;\r
+ hash = 79 * hash + Objects.hashCode(this.getFamilyName());\r
+ hash = 79 * hash + this.getGender();\r
+ hash = 79 * hash + Objects.hashCode(this.getSurname());\r
+ return hash;\r
+ }\r
+\r
/**\r
* Checks whether the contact is user's own data\r
*\r
// Display other data "box"\r
client.displayOtherDataBox((Contact) this);\r
}\r
+\r
+ /**\r
+ * Updates address data in this Contact instance\r
+ *\r
+ * @param street Street\r
+ * @param zipCode ZIP code\r
+ * @param city City\r
+ * @param countryCode Country code\r
+ */\r
+ public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {\r
+ // Set all\r
+ if (street != null) {\r
+ this.setStreet(street);\r
+ }\r
+ if (zipCode > 0) {\r
+ this.setZipCode(zipCode);\r
+ }\r
+ if (city != null) {\r
+ this.setCity(city);\r
+ }\r
+ if (countryCode != null) {\r
+ this.setCountryCode(countryCode);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates name data in this Contact instance\r
+ * @param gender Gender (M, F, C)\r
+ * @param surname Surname\r
+ * @param familyName Family name\r
+ * @param companyName Company name\r
+ */\r
+ public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {\r
+ // Set all\r
+ this.setGender(gender);\r
+ if (surname != null) {\r
+ this.setSurname(surname);\r
+ }\r
+ if (familyName != null) {\r
+ this.setFamilyName(familyName);\r
+ }\r
+ if (companyName != null) {\r
+ this.setCompanyName(companyName);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Updates other data in this Contact instance\r
+ * \r
+ * @param phoneNumber Phone number\r
+ * @param cellphoneNumber Cellphone number\r
+ * @param faxNumber Fax number\r
+ * @param emailAddress Email address\r
+ * @param birthday Birth day\r
+ * @param comment Comments\r
+ */\r
+ public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {\r
+ // Set all\r
+ if (phoneNumber != null) {\r
+ this.setPhoneNumber(phoneNumber);\r
+ }\r
+ if (cellphoneNumber != null) {\r
+ this.setCellphoneNumber(cellphoneNumber);\r
+ }\r
+ if (faxNumber != null) {\r
+ this.setFaxNumber(faxNumber);\r
+ }\r
+ if (emailAddress != null) {\r
+ this.setEmailAddress(emailAddress);\r
+ }\r
+ if (birthday != null) {\r
+ this.setBirthday(birthday);\r
+ }\r
+ if (comment != null) {\r
+ this.setComment(comment);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Enables the flag "own data" which signals that this contact is the user's\r
+ * own data.\r
+ */\r
+ protected void enableFlagOwnContact () {\r
+ this.ownContact = true;\r
+ }\r
}\r