From: Roland Häder Date: Mon, 19 Mar 2018 01:09:35 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6199077245e4811e6fc8eb36a5557092c013372e;p=jbonuscard-core.git Continued: - added new dependency jcore-utils.jar and commons-lang3 - removed jcoreee.jar depdendency for above newly added - implemented Comparable - updated commons-lang3 to 3.7 Signed-off-by: Roland Häder --- diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties index f508429..dd89006 100644 --- a/lib/nblibraries.properties +++ b/lib/nblibraries.properties @@ -1,3 +1,8 @@ +libs.commons-lang3.classpath=\ + ${base}/commons-lang3/commons-lang3-3.7.jar +libs.commons-lang3.displayName=Commons Lang3 3.7 +libs.commons-lang3.javadoc=\ + https://commons.apache.org/proper/commons-lang/apidocs/ libs.CopyLibs.classpath=\ ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar libs.CopyLibs.displayName=CopyLibs Task diff --git a/nbproject/project.properties b/nbproject/project.properties index e6da131..a6af727 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -32,7 +32,7 @@ endorsed.classpath= excludes= file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-core.jar=lib/jcontacts-core.jar -file.reference.jcoreee.jar=lib/jcoreee.jar +file.reference.jcore-utils.jar=lib/jcore-utils.jar file.reference.jcountry-core.jar=lib/jcountry-core.jar file.reference.jcustomer-core.jar=lib/jcustomer-core.jar file.reference.jphone-core.jar=lib/jphone-core.jar @@ -43,7 +43,6 @@ jar.archive.disabled=${jnlp.enabled} jar.compress=false jar.index=${jnlp.enabled} javac.classpath=\ - ${file.reference.jcoreee.jar}:\ ${file.reference.jcountry-core.jar}:\ ${file.reference.jphone-core.jar}:\ ${file.reference.juser-core.jar}:\ @@ -51,6 +50,8 @@ javac.classpath=\ ${file.reference.jcontacts-business-core.jar}:\ ${file.reference.jcustomer-core.jar}:\ ${file.reference.jproduct-core.jar}:\ + ${file.reference.jcore-utils.jar}:\ + ${libs.commons-lang3.classpath}:\ ${libs.jpa20-persistence.classpath}:\ ${libs.javaee-api-7.0.classpath} # Space-separated list of extra javac options @@ -111,7 +112,7 @@ run.test.classpath=\ source.encoding=UTF-8 source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ source.reference.jcontacts-core.jar=../jcontacts-core/src/ -source.reference.jcoreee.jar=../jcoreee/src/ +source.reference.jcore-utils.jar=../jcore-utils/src/ source.reference.jcountry-core.jar=../jcountry-core/src/ source.reference.jcustomer-core.jar=../jcustomer-core/src/ source.reference.jphone-core.jar=../jphone-core/src/ diff --git a/src/org/mxchange/jfinancials/model/bonus_card/BonusCard.java b/src/org/mxchange/jfinancials/model/bonus_card/BonusCard.java index 0595211..9d20a6f 100644 --- a/src/org/mxchange/jfinancials/model/bonus_card/BonusCard.java +++ b/src/org/mxchange/jfinancials/model/bonus_card/BonusCard.java @@ -26,7 +26,7 @@ import org.mxchange.jcustomercore.model.customer.Customer; *

* @author Roland Häder */ -public interface BonusCard extends Serializable { +public interface BonusCard extends Comparable, Serializable { /** * Getter for bonus card's bar code diff --git a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java index b74ac63..f9c9f2a 100644 --- a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java +++ b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java @@ -32,12 +32,17 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contacts; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicDataUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; +import org.mxchange.jcoreutils.Comparables; import org.mxchange.jcustomercore.model.customer.ContactCustomer; import org.mxchange.jcustomercore.model.customer.Customer; +import org.mxchange.jcustomercore.utils.Customers; /** * A POJO (entity) for bonus cards @@ -123,8 +128,9 @@ public class FinancialBonusCard implements BonusCard { * Constructor with all required fields *

* @param bonusCardContact Contact instance + * @param bonusCardIssuer Issuing company instance */ - public FinancialBonusCard (final Contact bonusCardContact) { + public FinancialBonusCard (final Contact bonusCardContact, final BasicData bonusCardIssuer) { // Call other constructor first this(); @@ -136,12 +142,56 @@ public class FinancialBonusCard implements BonusCard { // Throw it again throw new NullPointerException("bonusCardContact.contactId is null"); //NOI18N } else if (bonusCardContact.getContactId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("bonusCardContact.contactId={0} is invalid", bonusCardContact.getContactId())); //NOI18N + } else if (null == bonusCardIssuer) { + // Throw NPE + throw new NullPointerException("bonusCardOwner is null"); //NOI18N + } else if (bonusCardIssuer.getBasicDataId() == null) { // Throw it again - throw new NullPointerException(MessageFormat.format("bonusCardContact.contactId={0} is invalid", bonusCardContact.getContactId())); //NOI18N + throw new NullPointerException("bonusCardOwner.baseDataId is null"); //NOI18N + } else if (bonusCardIssuer.getBasicDataId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("bonusCardOwner.baseDataId={0} is invalid", bonusCardIssuer.getBasicDataId())); //NOI18N } // Set all this.bonusCardContact = bonusCardContact; + this.bonusCardIssuer = bonusCardIssuer; + } + + @Override + public int compareTo (final BonusCard bonusCard) { + // For performance reasons + if (null == bonusCard) { + // Should not happen + throw new NullPointerException("bonusCard is null"); //NOI18N + } else if (Objects.equals(this, bonusCard)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First compare by number + StringUtils.compare(this.getBonusCardNumber(), bonusCard.getBonusCardNumber()), + // ... next by bar code + StringUtils.compare(this.getBonusCardBarCode(), bonusCard.getBonusCardBarCode()), + // ... customer data + Customers.compare(this.getBonusCardCustomer(), bonusCard.getBonusCardCustomer()), + // ... contact data (card holder) + Contacts.compare(this.getBonusCardContact(), bonusCard.getBonusCardContact()), + // ... issuing company data + this.getBonusCardIssuer().compareTo(bonusCard.getBonusCardIssuer()), + // ... partner company data + BasicDataUtils.compare(this.getBonusCardPartner(), bonusCard.getBonusCardPartner()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; } @Override