From: Roland Haeder Date: Thu, 1 Oct 2015 13:24:33 +0000 (+0200) Subject: initial import (was in wrong project, sorry folks) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=be929d32d4109bb1f532fd3b7f84bebfa7064635;p=jcontacts-core.git initial import (was in wrong project, sorry folks) Signed-off-by:Roland Häder --- be929d32d4109bb1f532fd3b7f84bebfa7064635 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a014dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/dist/ +/build/ \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..3a8dcfa --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project jcontacts. + + + diff --git a/dist.sh b/dist.sh new file mode 100644 index 0000000..91a23db --- /dev/null +++ b/dist.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +NAME="jcontacts" +LIST=`find ../*/lib/${NAME}.jar` +LIST="${LIST} `find ../*/*-ejb/lib/${NAME}.jar`" + +for entry in ${LIST}; +do + cp -v dist/${NAME}.jar ${entry} +done diff --git a/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..eaf6790 Binary files /dev/null and b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/lib/jcore.jar b/lib/jcore.jar new file mode 100644 index 0000000..197b973 Binary files /dev/null and b/lib/jcore.jar differ diff --git a/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip new file mode 100644 index 0000000..fd55e6e Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence-2.1.0-doc.zip differ diff --git a/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar new file mode 100644 index 0000000..841d2e1 Binary files /dev/null and b/lib/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar differ diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties new file mode 100644 index 0000000..7ee5412 --- /dev/null +++ b/lib/nblibraries.properties @@ -0,0 +1,10 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.CopyLibs.displayName=CopyLibs Task +libs.CopyLibs.prop-version=2.0 +libs.jpa20-persistence.classpath=\ + ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar +libs.jpa20-persistence.displayName=Persistence (JPA 2.1) +libs.jpa20-persistence.javadoc=\ + ${base}/jpa20-persistence/javax.persistence-2.1.0-doc.zip +libs.jpa20-persistence.prop-maven-dependencies=org.eclipse.persistence:javax.persistence:2.1.0:jar diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..0e8386d --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1438 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..09edd72 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=454ad12e +build.xml.script.CRC32=d16b6fdf +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=454ad12e +nbproject/build-impl.xml.script.CRC32=d8b8bfba +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..53e6058 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,79 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=jcontacts +application.vendor=Roland Haeder +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/jcontacts.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.jcore.jar=lib/jcore.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.jcore.jar}:\ + ${libs.jpa20-persistence.classpath} +# Space-separated list of extra javac options +javac.compilerargs=-Xlint:unchecked -Xlint:deprecation +javac.deprecation=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=true +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=true +javadoc.splitindex=true +javadoc.use=true +javadoc.version=true +javadoc.windowtitle=Contacts Library +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +project.license=gpl30 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +source.reference.jcore.jar=../jcore/src/ +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..027e268 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + jcontacts + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/src/org/mxchange/jcontacts/contact/Contact.java b/src/org/mxchange/jcontacts/contact/Contact.java new file mode 100644 index 0000000..6c1f583 --- /dev/null +++ b/src/org/mxchange/jcontacts/contact/Contact.java @@ -0,0 +1,303 @@ +/* + * 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.jcontacts.contact; + +import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; +import org.mxchange.jcontacts.contact.gender.Gender; + +/** + * A general contact interface + *

+ * @author Roland Haeder + */ +public interface Contact extends Serializable { + + /** + * Copies all attributes from other contact object to this + *

+ * @param contact Source instance + */ + public void copyAll (final Contact contact); + + /** + * Birth day + *

+ * @return the birthday + */ + public Date getBirthday (); + + /** + * Birth day + *

+ * @param birthday the birthday to set + */ + public void setBirthday (final Date birthday); + + /** + * Cellphone number + *

+ * @return the cellphoneNumber + */ + public String getCellphoneNumber (); + + /** + * Cellphone number + *

+ * @param cellphoneNumber the cellphoneNumber to set + */ + public void setCellphoneNumber (final String cellphoneNumber); + + /** + * City + *

+ * @return the city + */ + public String getCity (); + + /** + * City + *

+ * @param city the city to set + */ + public void setCity (final String city); + + /** + * Comments + *

+ * @return the comment + */ + public String getComment (); + + /** + * Comments + *

+ * @param comment the comment to set + */ + public void setComment (final String comment); + + /** + * Company name + *

+ * @return the companyName + */ + public String getCompanyName (); + + /** + * Company name + *

+ * @param companyName the companyName to set + */ + public void setCompanyName (final String companyName); + + /** + * Id number + *

+ * @return the contactId + */ + public Long getContactId (); + + /** + * Id number + *

+ * @param id the contactId to set + */ + public void setContactId (final Long id); + + /** + * Country code + *

+ * @return the countryCode + */ + public String getCountryCode (); + + /** + * Country code + *

+ * @param countryCode the countryCode to set + */ + public void setCountryCode (final String countryCode); + + /** + * Getter for "created" timestamp + *

+ * @return "created" timestamp + */ + public Calendar getCreated (); + + /** + * Setter for "created" timestamp + *

+ * @param created "created" timestamp + */ + public void setCreated (final Calendar created); + + /** + * Email address + *

+ * @return the emailAddress + */ + public String getEmailAddress (); + + /** + * Email address + *

+ * @param emailAddress the emailAddress to set + */ + public void setEmailAddress (final String emailAddress); + + /** + * Family name + *

+ * @return the familyName + */ + public String getFamilyName (); + + /** + * Family name + *

+ * @param familyName the familyName to set + */ + public void setFamilyName (final String familyName); + + /** + * Fax number + *

+ * @return the faxNumber + */ + public String getFaxNumber (); + + /** + * Fax number + *

+ * @param faxNumber the faxNumber to set + */ + public void setFaxNumber (final String faxNumber); + + /** + * First name + *

+ * @return the first name + */ + public String getFirstName (); + + /** + * First name + *

+ * @param firstName the first name to set + */ + public void setFirstName (final String firstName); + + /** + * 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); + + /** + * House number + *

+ * @return the houseNumber + */ + public Short getHouseNumber (); + + /** + * House number + *

+ * @param houseNumber the houseNumber to set + */ + public void setHouseNumber (final Short houseNumber); + + /** + * Setter for own contact + *

+ * @param ownContact Own contact + */ + public void setOwnContact (final Boolean ownContact); + + /** + * Phone number + *

+ * @return the phoneNumber + */ + public String getPhoneNumber (); + + /** + * Phone number + *

+ * @param phoneNumber the phoneNumber to set + */ + public void setPhoneNumber (final String phoneNumber); + + /** + * Street + *

+ * @return the street + */ + public String getStreet (); + + /** + * Street + *

+ * @param street the street to set + */ + public void setStreet (final String street); + + /** + * Getter for "updated" timestamp + *

+ * @return "updated" timestamp + */ + public Calendar getUpdated (); + + /** + * Getter for "updated" timestamp + *

+ * @param updated "updated" timestamp + */ + public void setUpdated (final Calendar updated); + + /** + * ZIP code + *

+ * @return the zipCode + */ + public Long getZipCode (); + + /** + * ZIP code + *

+ * @param zipCode the zipCode to set + */ + public void setZipCode (final Long zipCode); + + /** + * Checks whether the contact is user's own data + *

+ * @return Own data? + */ + public Boolean isOwnContact (); +} diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java new file mode 100644 index 0000000..4755456 --- /dev/null +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -0,0 +1,485 @@ +/* + * 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.jcontacts.contact; + +import java.util.Calendar; +import java.util.Date; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import org.mxchange.jcontacts.contact.gender.Gender; + +/** + * A general contact class which should only be extended. + *

+ * @author Roland Haeder + * @version 0.0 + */ +@Entity (name = "contacts") +@Table (name = "contacts") +public class UserContact implements Contact, Comparable { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_744_284_981_863L; + + /** + * Birth day + */ + @Column (name = "birthday") + @Temporal (TemporalType.DATE) + private Date birthday; + + /** + * Cellphone number + */ + @Column (name = "cellphone_number", length = 100) + private String cellphoneNumber; + + /** + * City + */ + @Column (name = "city", nullable = false, length = 100) + private String city; + + /** + * Optional comments + */ + @Lob + @Column (name = "comment") + private String comment; + + /** + * Company name + */ + @Column (name = "company_name", nullable = false) + private String companyName; + + /** + * Id number + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "contact_id", length = 20, updatable = false) + private Long contactId; + + /** + * Country code + */ + @Column (name = "country_code", length = 2, nullable = false) + private String countryCode; + + /** + * When the contact has been created + */ + @Basic (optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "created", nullable = false) + private Calendar created; + + /** + * Email address + */ + @Column (name = "email_address", length = 100, nullable = false) + private String emailAddress; + + /** + * Family name + */ + @Basic (optional = false) + @Column (name = "family_name", length = 100, nullable = false) + private String familyName; + + /** + * Fax number + */ + @Column (name = "fax_number", length = 100) + private String faxNumber; + + /** + * First name + */ + @Basic (optional = false) + @Column (name = "first_name", length = 100, nullable = false) + private String firstName; + + /** + * Gender instance + */ + @Basic (optional = false) + @Column (name = "gender", nullable = false) + @Enumerated (EnumType.STRING) + private Gender gender; + + /** + * House number + */ + @Column (name = "house_number", length = 5, nullable = false) + private Short houseNumber; + + /** + * Flag whether this contact is user's own data + */ + @Column (name = "own_contact", nullable = false) + private Boolean ownContact; + + /** + * Phone number + */ + @Column (name = "phone_number", length = 100) + private String phoneNumber; + + /** + * Street + */ + @Column (name = "street", nullable = false) + private String street; + + /** + * When the contact has been updated + */ + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "updated") + private Calendar updated; + + /** + * ZIP code + */ + @Column (name = "zip_code", nullable = false, length = 6) + private Long zipCode; + + /** + * Constructor for gender and names + *

+ * @param gender Gender instance + * @param firstName First name + * @param familyName Family name + * @param companyName Company name + */ + public UserContact (final Gender gender, final String firstName, final String familyName, final String companyName) { + // Set all + this.gender = gender; + this.firstName = firstName; + this.familyName = familyName; + } + + /** + * Default constructor + */ + public UserContact () { + } + + /** + * Compares two contacts with each other + *

+ * @param contact Contact comparator + * @return Comparison value + */ + @Override + public int compareTo (final Contact contact) { + // contact should not be null + if (null == contact) { + throw new NullPointerException("contact is null"); //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; + } + + @Override + public void copyAll (final Contact contact) { + // Copy all: + // - base data + this.setFirstName(contact.getFirstName()); + this.setFamilyName(contact.getFamilyName()); + this.setCompanyName(contact.getCompanyName()); + this.setStreet(contact.getStreet()); + this.setZipCode(contact.getZipCode()); + this.setCity(contact.getCity()); + this.setCountryCode(contact.getCountryCode()); + + // - phone, fax, email + this.setPhoneNumber(contact.getPhoneNumber()); + this.setFaxNumber(contact.getFaxNumber()); + this.setCellphoneNumber(contact.getCellphoneNumber()); + + // - other data + this.setBirthday(contact.getBirthday()); + this.setComment(contact.getComment()); + this.setCreated(contact.getCreated()); + this.setUpdated(contact.getUpdated()); + } + + /** + * 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 UserContact)) { + // 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()))); + } + + @Override + public Date getBirthday () { + return this.birthday; + } + + @Override + public void setBirthday (final Date birthday) { + this.birthday = birthday; + } + + @Override + public String getCellphoneNumber () { + return this.cellphoneNumber; + } + + @Override + public void setCellphoneNumber (final String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + @Override + public String getCity () { + return this.city; + } + + @Override + public void setCity (final String city) { + this.city = city; + } + + @Override + public String getComment () { + return this.comment; + } + + @Override + public void setComment (final String comment) { + this.comment = comment; + } + + @Override + public String getCompanyName () { + return this.companyName; + } + + @Override + public void setCompanyName (final String companyName) { + this.companyName = companyName; + } + + @Override + public Long getContactId () { + return this.contactId; + } + + @Override + public void setContactId (final Long contactId) { + this.contactId = contactId; + } + + @Override + public String getCountryCode () { + return this.countryCode; + } + + @Override + public void setCountryCode (final String countryCode) { + this.countryCode = countryCode; + } + + @Override + public Calendar getCreated () { + return this.created; + } + + @Override + public void setCreated (final Calendar created) { + this.created = created; + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + @Override + public String getFamilyName () { + //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!"); + return this.familyName; + } + + @Override + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + @Override + public String getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final String faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public String getFirstName () { + return this.firstName; + } + + @Override + public void setFirstName (final String firstName) { + this.firstName = firstName; + } + + @Override + public Gender getGender () { + return this.gender; + } + + @Override + public void setGender (final Gender gender) { + this.gender = gender; + } + + @Override + public Short getHouseNumber () { + return this.houseNumber; + } + + @Override + public void setHouseNumber (final Short houseNumber) { + this.houseNumber = houseNumber; + } + + @Override + public void setOwnContact (final Boolean ownContact) { + this.ownContact = ownContact; + } + + @Override + public String getPhoneNumber () { + return this.phoneNumber; + } + + @Override + public void setPhoneNumber (final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @Override + public String getStreet () { + return this.street; + } + + @Override + public void setStreet (final String street) { + this.street = street; + } + + @Override + public Calendar getUpdated () { + return this.updated; + } + + @Override + public void setUpdated (final Calendar updated) { + this.updated = updated; + } + + @Override + public Long getZipCode () { + return this.zipCode; + } + + @Override + public 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; + } + + /** + * Initialization with fake gender UNKNOWN + */ + @PostConstruct + public void init () { + // Fake gender + this.gender = Gender.UNKNOWN; + } + + @Override + public Boolean isOwnContact () { + return this.ownContact; + } +} diff --git a/src/org/mxchange/jcontacts/contact/gender/Gender.java b/src/org/mxchange/jcontacts/contact/gender/Gender.java new file mode 100644 index 0000000..fa5ae2d --- /dev/null +++ b/src/org/mxchange/jcontacts/contact/gender/Gender.java @@ -0,0 +1,161 @@ +/* + * 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.jcontacts.contact.gender; + +import java.io.Serializable; +import java.text.MessageFormat; + +/** + * Gender enum + *

+ * @author Roland Haeder + */ +public enum Gender implements Serializable { + + /** + * Unknown enum + */ + UNKNOWN('U', "GENDER_UNKNOWN"), //NOI18N + + /** + * Male enum + */ + MALE('M', "GENDER_MALE"), //NOI18N + + /** + * Female enum + */ + FEMALE('F', "GENDER_FEMALE"), //NOI18N + + /** + * Company enum + */ + COMPANY('C', "GENDER_COMPANY"); //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/jcontacts/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java new file mode 100644 index 0000000..2af62dc --- /dev/null +++ b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java @@ -0,0 +1,88 @@ +/* + * 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.jcontacts.contact.gender; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jcontacts.contact.Contact; + +/** + * Gender utils class + *

+ * @author Roland Haeder + */ +public class GenderUtils extends BaseFrameworkSystem { + + /** + * Translates contact's gender to human-readable + *

+ * @param contact Contact instance + * @return Translates value (from bundle) + */ + public static String getTranslatedGender (final Contact contact) { + // Init instance + GenderUtils utils = new GenderUtils(); + + // contact must be set + if (null == contact) { + // Abort here + throw new NullPointerException("contact is null"); + } else if (contact.getGender() == null) { + // Gender is not set + throw new NullPointerException(MessageFormat.format("contact {0} has no gender set.", contact)); + } + + // Get key from it + String key = contact.getGender().getMessageKey(); + + // Translate and return it + return utils.getMessageStringFromKey(key); + } + + /** + * Private contructor as this is an utility class + */ + private GenderUtils () { + } + + /** + * All selectable genders (not UNKNOWN) + *

+ * @return Selectable genders (not UNKNOWN) + */ + public static List selectableGenders () { + // Init list + List list = new LinkedList<>(); + + // Walk through all genders + for (final Gender gender : Gender.values()) { + // 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 + } + } + + // Return it + return list; + } +}