From: Roland Häder Date: Mon, 19 Mar 2018 23:50:51 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4269f830856a18f6c65f1ba5ced59db10bfd4de3;p=jfinancials-core.git Continued: - 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 --- diff --git a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java index 1007da0..8781f62 100644 --- a/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java +++ b/src/org/mxchange/jfinancials/model/bonus_card/FinancialBonusCard.java @@ -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 diff --git a/src/org/mxchange/jfinancials/model/income/IncomeUtils.java b/src/org/mxchange/jfinancials/model/income/IncomeUtils.java index e4c6591..047975a 100644 --- a/src/org/mxchange/jfinancials/model/income/IncomeUtils.java +++ b/src/org/mxchange/jfinancials/model/income/IncomeUtils.java @@ -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 + } + } diff --git a/src/org/mxchange/jfinancials/model/receipt/Receipts.java b/src/org/mxchange/jfinancials/model/receipt/Receipts.java index 24fb923..a2f6d8a 100644 --- a/src/org/mxchange/jfinancials/model/receipt/Receipts.java +++ b/src/org/mxchange/jfinancials/model/receipt/Receipts.java @@ -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. + *

+ * @param receipt1 BillableReceipt instance 1 + * @param receipt2 BillableReceipt instance 2 + *

+ * @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. + *

+ * @param receipt1 BillableReceipt instance 1 + * @param receipt2 BillableReceipt instance 2 + *

+ * @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"); } diff --git a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java index 7ddc830..0b5071a 100644 --- a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java +++ b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java @@ -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