]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 23:50:51 +0000 (00:50 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 19 Mar 2018 23:50:51 +0000 (00:50 +0100)
- Added Receipts.compare() which does a comparison with result as
  Comparable.compareTo() would do.
- The difference here is that this method (like all its sisters and brothers)
  are truely null-safe.
- added private constructor to IncomeUtils, no instances shall be created from
  utilities classes
- also need to compare receipt item's category and receipt instance
- updated reference to Customers utility class

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java
src/org/mxchange/jfinancials/model/income/IncomeUtils.java
src/org/mxchange/jfinancials/model/receipt/Receipts.java
src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java

index 1007da0b306e9cee87bec8fa5b7afeaa837eafd7..8781f627371d1315168f83b04a7b2d963f54f902 100644 (file)
@@ -42,7 +42,7 @@ 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;
+import org.mxchange.jcustomercore.model.customer.Customers;
 
 /**
  * A POJO (entity) for bonus cards
index e4c6591b7c70dcc46d3345800cc8983665ffcb93..047975a931848e3cfe963806edc1f528452763d6 100644 (file)
@@ -30,4 +30,11 @@ public class IncomeUtils implements Serializable {
         */
        private static final long serialVersionUID = 145_986_981_751L;
 
+       /**
+        * Utility classes should not have instances
+        */
+       private IncomeUtils () {
+               // Private constructor
+       }
+
 }
index 24fb923a928acbfcdc6b36197dfacf2153eb528b..a2f6d8a317f78d5951f292616b8215ca269d3184 100644 (file)
@@ -32,6 +32,42 @@ public class Receipts implements Serializable {
         */
        private static final long serialVersionUID = 2_867_938_676_165_401L;
 
+       /**
+        * Compares both receipt instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param receipt1 BillableReceipt instance 1
+        * @param receipt2 BillableReceipt instance 2
+        * <p>
+        * @return Comparison value
+        */
+       public static int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) {
+               // Check euqality, then at least first must be given
+               if (Objects.equals(receipt1, receipt2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == receipt1) {
+                       // First is null
+                       return -1;
+               } else if (null == receipt2) {
+                       // Second is null
+                       return 1;
+               }
+
+               // Invoke compareTo() method
+               return receipt1.compareTo(receipt2);
+       }
+
+       /**
+        * Checks whether both receipts are the same, means not true entity equality
+        * but if the receipt in general terms does already exist. A pre-check on
+        * entity equality is however performed to avoid below much longer code.
+        * <p>
+        * @param receipt1 BillableReceipt instance 1
+        * @param receipt2 BillableReceipt instance 2
+        * <p>
+        * @return Whether both receipts are the same (not instances)
+        */
        public static boolean isSameReceipt (final BillableReceipt receipt1, final BillableReceipt receipt2) {
                // Pre-compare both as entities (same id)
                if (Objects.equals(receipt1, receipt2)) {
@@ -58,7 +94,7 @@ public class Receipts implements Serializable {
                } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) {
                        // Throw IAE
                        throw new IllegalArgumentException("receipt1.receiptNumber is empty.");
-               } else if (receipt1.getReceiptPaymentType()== null) {
+               } else if (receipt1.getReceiptPaymentType() == null) {
                        // Throw NPE
                        throw new NullPointerException("receipt1.receiptPaymentType is null");
                } else if (null == receipt2) {
@@ -79,7 +115,7 @@ public class Receipts implements Serializable {
                } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) {
                        // Throw IAE
                        throw new IllegalArgumentException("receipt2.receiptNumber is empty.");
-               } else if (receipt2.getReceiptPaymentType()== null) {
+               } else if (receipt2.getReceiptPaymentType() == null) {
                        // Throw NPE
                        throw new NullPointerException("receipt2.receiptPaymentType is null");
                }
index 7ddc8306de4b71651a895d0a35e65ed2c68a5098..0b5071ac16cbfb9669e073cd097f6c862e1709e5 100644 (file)
@@ -41,6 +41,8 @@ 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.jfinancials.model.receipt.Receipts;
+import org.mxchange.jproduct.model.category.Categories;
 import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.category.ProductCategory;
 import org.mxchange.jproduct.model.product.GenericProduct;
@@ -227,6 +229,10 @@ public class FinancialReceiptItem implements BillableReceiptItem {
                        this.getItemProductQuantity().compareTo(billableReceiptItem.getItemProductQuantity()),
                        // ... product instance
                        Products.compare(this.getItemProduct(), billableReceiptItem.getItemProduct()),
+                       // ... category instance
+                       Categories.compare(this.getItemCategory(), billableReceiptItem.getItemCategory()),
+                       // and finally receipt instance
+                       Receipts.compare(this.getItemReceipt(), billableReceiptItem.getItemReceipt())
                };
 
                // Check all values