]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 23:37:05 +0000 (00:37 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 23:37:05 +0000 (00:37 +0100)
- implemented Comparable interface

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java
src/org/mxchange/jfinancials/model/income/BillableIncome.java
src/org/mxchange/jfinancials/model/income/FinancialIncome.java
src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java
src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java
src/org/mxchange/jfinancials/model/receipt_item/BillableReceiptItem.java
src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java

index f9c9f2ae78e83dcd9ebccd15036439e3dd784222..1007da0b306e9cee87bec8fa5b7afeaa837eafd7 100644 (file)
@@ -162,11 +162,11 @@ public class FinancialBonusCard implements BonusCard {
 
        @Override
        public int compareTo (final BonusCard bonusCard) {
-               // For performance reasons
+               // Check parameter on null-reference and equality to this
                if (null == bonusCard) {
                        // Should not happen
                        throw new NullPointerException("bonusCard is null"); //NOI18N
-               } else if (Objects.equals(this, bonusCard)) {
+               } else if (bonusCard.equals(this)) {
                        // Same object
                        return 0;
                }
index 2285c976377c0a850632dbf726ec6b68c6be77db..080d0a198ddf01319fcc3bdf8985041cbe8999d2 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jfinancials.model.income;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 import org.mxchange.jfinancials.model.income.interval.FinancialInterval;
 import org.mxchange.jusercore.model.user.User;
@@ -26,7 +27,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface BillableIncome extends Serializable {
+public interface BillableIncome extends Comparable<BillableIncome>, Serializable {
 
        /**
         * Getter for income id (primary key)
@@ -89,14 +90,14 @@ public interface BillableIncome extends Serializable {
         * <p>
         * @return Income single amount
         */
-       Float getIncomeSingleAmount ();
+       BigDecimal getIncomeSingleAmount ();
 
        /**
         * Setter for income single amount
         * <p>
         * @param incomeSingleAmount Income single amount
         */
-       void setIncomeSingleAmount (final Float incomeSingleAmount);
+       void setIncomeSingleAmount (final BigDecimal incomeSingleAmount);
 
        /**
         * Getter for income title
index 92ba782b6030fbd64cce306c1acdbb55db108589..734abb8b7699938de46c6133dd8dce55fb1bcf00 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jfinancials.model.income;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -33,6 +34,7 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.mxchange.jcoreutils.Comparables;
 import org.mxchange.jfinancials.model.income.interval.FinancialInterval;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
@@ -90,7 +92,7 @@ public class FinancialIncome implements BillableIncome {
         */
        @Basic (optional = false)
        @Column (name = "income_single_amount", nullable = false)
-       private Float incomeSingleAmount;
+       private BigDecimal incomeSingleAmount;
 
        /**
         * Income title
@@ -128,7 +130,7 @@ public class FinancialIncome implements BillableIncome {
         * @param incomeInterval     Interval
         * @param incomeUser         Connected user
         */
-       public FinancialIncome (final String incomeTitle, final Float incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
+       public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
                // Call default constructor
                this();
 
@@ -142,6 +144,36 @@ public class FinancialIncome implements BillableIncome {
                this.incomeEnabled = Boolean.TRUE;
        }
 
+       @Override
+       public int compareTo (final BillableIncome billableIncome) {
+               // Check parameter on null-reference and equality to this
+               if (null == billableIncome) {
+                       // Should not happen
+                       throw new NullPointerException("billableIncome is null"); //NOI18N
+               } else if (billableIncome.equals(this)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First compare title
+                       this.getIncomeTitle().compareToIgnoreCase(billableIncome.getIncomeTitle()),
+                       // ... then compare interval
+                       this.getIncomeInterval().compareTo(billableIncome.getIncomeInterval()),
+                       // ... value
+                       this.getIncomeSingleAmount().compareTo(billableIncome.getIncomeSingleAmount()),
+                       // ... user instance
+                       this.getIncomeUser().compareTo(billableIncome.getIncomeUser())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
@@ -202,17 +234,17 @@ public class FinancialIncome implements BillableIncome {
        }
 
        @Override
-       public void setIncomeInterval (FinancialInterval incomeInterval) {
+       public void setIncomeInterval (final FinancialInterval incomeInterval) {
                this.incomeInterval = incomeInterval;
        }
 
        @Override
-       public Float getIncomeSingleAmount () {
+       public BigDecimal getIncomeSingleAmount () {
                return this.incomeSingleAmount;
        }
 
        @Override
-       public void setIncomeSingleAmount (Float incomeSingleAmount) {
+       public void setIncomeSingleAmount (final BigDecimal incomeSingleAmount) {
                this.incomeSingleAmount = incomeSingleAmount;
        }
 
index 5e5ca0d540d45cd714812c2bccf3cccfdc394313..7938dcbd24f9fb19c8aa358a9f2348655ef7a150 100644 (file)
@@ -29,7 +29,7 @@ import org.mxchange.jusercore.model.user.User;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface BillableReceipt extends Serializable {
+public interface BillableReceipt extends Comparable<BillableReceipt>, Serializable {
 
        /**
         * Getter for receipt bar-code number
index de5397651ca12f41237e80493cb62d859e642b22..818496fa59dc59f60175f4452cb62408f240ffe0 100644 (file)
@@ -36,15 +36,21 @@ 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.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.employee.Employees;
+import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.SafeNumberUtils;
 import org.mxchange.jfinancials.model.bonus_card.BonusCard;
 import org.mxchange.jfinancials.model.bonus_card.FinancialBonusCard;
 import org.mxchange.jproduct.model.payment.PaymentType;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.Users;
 
 /**
  *
@@ -228,6 +234,46 @@ public class FinancialReceipt implements BillableReceipt {
                this.receiptIssued = receiptIssued;
        }
 
+       @Override
+       public int compareTo (final BillableReceipt billableReceipt) {
+               // Check parameter on null-reference and equality to this
+               if (null == billableReceipt) {
+                       // Should not happen
+                       throw new NullPointerException("billableReceipt is null"); //NOI18N
+               } else if (billableReceipt.equals(this)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First compare receipt number
+                       StringUtils.compare(this.getReceiptNumber(), billableReceipt.getReceiptNumber()),
+                       // ... next bar-code
+                       StringUtils.compare(this.getReceiptBarCodeNumber(), billableReceipt.getReceiptBarCodeNumber()),
+                       // ... sequence number
+                       SafeNumberUtils.compare(this.getReceiptSequenceNumber(), billableReceipt.getReceiptSequenceNumber()),
+                       // ... payment type
+                       this.getReceiptPaymentType().compareTo(billableReceipt.getReceiptPaymentType()),
+                       // ... register number
+                       SafeNumberUtils.compare(this.getReceiptRegisterNumber(), billableReceipt.getReceiptRegisterNumber()),
+                       // ... issue date
+                       this.getReceiptIssued().compareTo(billableReceipt.getReceiptIssued()),
+                       // ... next is seller instance
+                       Employees.compare(this.getReceiptSellerEmployee(), billableReceipt.getReceiptSellerEmployee()),
+                       // .. branch office
+                       BranchOffices.compare(this.getReceiptBranchOffice(), billableReceipt.getReceiptBranchOffice()),
+                       // ... and user instance
+                       Users.compare(this.getReceiptUser(), billableReceipt.getReceiptUser())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {
index b573f09428a650c61486ea9ca25822ef66b838b3..3ced262ebb28b79d22a9c380e3870d1bc58ceb1f 100644 (file)
@@ -29,7 +29,7 @@ import org.mxchange.jproduct.model.product.Product;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface BillableReceiptItem extends Serializable {
+public interface BillableReceiptItem extends Comparable<BillableReceiptItem>, Serializable {
 
        /**
         * Getter for item's product category
index 93c673574a7a905e48d1cd836973467d4c12e55d..7ddc8306de4b71651a895d0a35e65ed2c68a5098 100644 (file)
@@ -34,14 +34,18 @@ 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.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.SafeNumberUtils;
 import org.mxchange.jfinancials.model.receipt.BillableReceipt;
 import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
 import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.category.ProductCategory;
 import org.mxchange.jproduct.model.product.GenericProduct;
 import org.mxchange.jproduct.model.product.Product;
+import org.mxchange.jproduct.model.product.Products;
 
 /**
  * A POJO for receipt items
@@ -194,6 +198,44 @@ public class FinancialReceiptItem implements BillableReceiptItem {
                this.itemReceipt = itemReceipt;
        }
 
+       @Override
+       public int compareTo (final BillableReceiptItem billableReceiptItem) {
+               // Check parameter on null-reference and equality to this
+               if (null == billableReceiptItem) {
+                       // Should not happen
+                       throw new NullPointerException("billableReceiptItem is null"); //NOI18N
+               } else if (billableReceiptItem.equals(this)) {
+                       // Same object
+                       return 0;
+               }
+
+               // Init comparators
+               final int comparators[] = {
+                       // First check brand name ...
+                       StringUtils.compare(this.getItemBrandName(), billableReceiptItem.getItemBrandName()),
+                       // ... item number
+                       SafeNumberUtils.compare(this.getItemNumber(), billableReceiptItem.getItemNumber()),
+                       // ... coupon number
+                       StringUtils.compare(this.getItemCouponNumber(), billableReceiptItem.getItemCouponNumber()),
+                       // ... gross price
+                       SafeNumberUtils.compare(this.getItemGrossPrice(), billableReceiptItem.getItemGrossPrice()),
+                       // ... net price
+                       SafeNumberUtils.compare(this.getItemNetPrice(), billableReceiptItem.getItemNetPrice()),
+                       // ... tax rate
+                       SafeNumberUtils.compare(this.getItemTaxRate(), billableReceiptItem.getItemTaxRate()),
+                       // ... product quanity
+                       this.getItemProductQuantity().compareTo(billableReceiptItem.getItemProductQuantity()),
+                       // ... product instance
+                       Products.compare(this.getItemProduct(), billableReceiptItem.getItemProduct()),
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparators);
+
+               // Return value
+               return comparison;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (this == object) {