]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 01:09:35 +0000 (02:09 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 01:24:35 +0000 (02:24 +0100)
- 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 <roland@mxchange.org>
lib/nblibraries.properties
nbproject/project.properties
src/org/mxchange/jfinancials/model/bonus_card/BonusCard.java
src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java

index f508429b10ef4dcd1fe691a451f9b0defe383649..dd890066fe99b5943c8d20df6fdbc9cdb99c849f 100644 (file)
@@ -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
index e6da131bd8188fed4a06302daf0b1ee6c1e63f45..a6af72773db96af65846f718a1809d93e7e9529c 100644 (file)
@@ -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/
index 05952116c5a4d4e397bbec539bdae6d646907a74..9d20a6f21f7ef8ce7f73a0a4c7b43960e73bd8dd 100644 (file)
@@ -26,7 +26,7 @@ import org.mxchange.jcustomercore.model.customer.Customer;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface BonusCard extends Serializable {
+public interface BonusCard extends Comparable<BonusCard>, Serializable {
 
        /**
         * Getter for bonus card's bar code
index b74ac63f3228a3a427aabbb554f7e39e2e200909..f9c9f2ae78e83dcd9ebccd15036439e3dd784222 100644 (file)
@@ -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
         * <p>
         * @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