From: Roland Häder Date: Thu, 6 Oct 2022 15:13:38 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a22286fd303de1ad8a10a44c618b5fc0b6c8f926;p=jfinancials-core.git Continued: - renamed utility classes *s to *Utils - moved them into own package --- diff --git a/src/org/mxchange/jfinancials/model/income/IncomeUtils.java b/src/org/mxchange/jfinancials/model/income/IncomeUtils.java deleted file mode 100644 index 6db7f90..0000000 --- a/src/org/mxchange/jfinancials/model/income/IncomeUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2016 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.model.income; - -import java.io.Serializable; - -/** - * An utilities class for incomes - *

- * @author Roland Häder - */ -public class IncomeUtils implements Serializable { - - /** - * Serial number - */ - 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/FinancialReceipt.java b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java index 3cc6bfb..bad9580 100644 --- a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java @@ -41,17 +41,17 @@ import org.apache.commons.lang3.StringUtils; import org.mxchange.jbonuscard.model.bonus_card.BonusCard; import org.mxchange.jbonuscard.model.bonus_card.RoyalityCard; 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.jcontactsbusiness.model.utils.BranchOfficeUtils; +import org.mxchange.jcontactsbusiness.model.utils.EmployeeUtils; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jcoreutils.SafeNumberUtils; 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; +import org.mxchange.jusercore.model.utils.UserUtils; /** * Receipt POJO @@ -292,11 +292,11 @@ public class FinancialReceipt implements BillableReceipt { // ... issue date this.getReceiptIssued().compareTo(billableReceipt.getReceiptIssued()), // ... next is seller instance - Employees.compare(this.getReceiptSellerEmployee(), billableReceipt.getReceiptSellerEmployee()), + EmployeeUtils.compare(this.getReceiptSellerEmployee(), billableReceipt.getReceiptSellerEmployee()), // .. branch office - BranchOffices.compare(this.getReceiptBranchOffice(), billableReceipt.getReceiptBranchOffice()), + BranchOfficeUtils.compare(this.getReceiptBranchOffice(), billableReceipt.getReceiptBranchOffice()), // ... and user instance - Users.compare(this.getReceiptUser(), billableReceipt.getReceiptUser()) + UserUtils.compare(this.getReceiptUser(), billableReceipt.getReceiptUser()) }; // Check all values diff --git a/src/org/mxchange/jfinancials/model/receipt/Receipts.java b/src/org/mxchange/jfinancials/model/receipt/Receipts.java deleted file mode 100644 index ba8f72f..0000000 --- a/src/org/mxchange/jfinancials/model/receipt/Receipts.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.model.receipt; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Objects; - -/** - * A utilities class for receipts - * - * @author Roland Häder - */ -public class Receipts implements Serializable { - - /** - * Serial number - */ - 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 equality, 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); - } - - /** - * Copies all fields from source receipt to target receipt. - *

- * @param sourceReceipt Source receipt instance - * @param targetReceipt Target Receipt instance - */ - public static void copyReceiptData (final BillableReceipt sourceReceipt, final BillableReceipt targetReceipt) { - // Both should not be null - if (null == sourceReceipt) { - // Throw NPE - throw new NullPointerException("sourceReceipt is null"); //NOI18N - } else if (null == targetReceipt) { - // Throw NPE - throw new NullPointerException("targetReceipt is null"); //NOI18N - } else if (Objects.equals(sourceReceipt, targetReceipt)) { - // Is exactly the same! - throw new IllegalArgumentException("sourcerReceipt and targetReceipt are the same."); //NOI18N - } - - // Copy all fields - targetReceipt.setReceiptBarCodeNumber(sourceReceipt.getReceiptBarCodeNumber()); - targetReceipt.setReceiptBonusCard(sourceReceipt.getReceiptBonusCard()); - targetReceipt.setReceiptBranchOffice(sourceReceipt.getReceiptBranchOffice()); - targetReceipt.setReceiptId(sourceReceipt.getReceiptId()); - targetReceipt.setReceiptIssued(sourceReceipt.getReceiptIssued()); - targetReceipt.setReceiptNumber(sourceReceipt.getReceiptNumber()); - targetReceipt.setReceiptPaymentType(sourceReceipt.getReceiptPaymentType()); - targetReceipt.setReceiptQrCode(sourceReceipt.getReceiptQrCode()); - targetReceipt.setReceiptRegisterNumber(sourceReceipt.getReceiptRegisterNumber()); - targetReceipt.setReceiptSellerEmployee(sourceReceipt.getReceiptSellerEmployee()); - targetReceipt.setReceiptSequenceNumber(sourceReceipt.getReceiptSequenceNumber()); - targetReceipt.setReceiptTransactionNumber(sourceReceipt.getReceiptTransactionNumber()); - targetReceipt.setReceiptUser(sourceReceipt.getReceiptUser()); - } - - /** - * 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)) { - // Same entity (with id number) - return true; - } - - // Validate parameter - if (null == receipt1) { - // Throw NPE - throw new NullPointerException("receipt1 is null"); //NOI18N - } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId())); //NOI18N - } else if (receipt1.getReceiptBranchOffice() == null) { - // Throw NPE - throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N - } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) { - // Throw NPE - throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null"); //NOI18N - } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId())); //NOI18N - } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) { - // Throw IAE - throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N - } else if (receipt1.getReceiptPaymentType() == null) { - // Throw NPE - throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N - } else if (null == receipt2) { - // Throw NPE - throw new NullPointerException("receipt2 is null"); //NOI18N - } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId())); //NOI18N - } else if (receipt2.getReceiptBranchOffice() == null) { - // Throw NPE - throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N - } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) { - // Throw NPE - throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null"); //NOI18N - } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId())); //NOI18N - } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) { - // Throw IAE - throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N - } else if (receipt2.getReceiptPaymentType() == null) { - // Throw NPE - throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N - } - - // Now check all individually - if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) { - // Other branch offices - return false; - } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) { - // Other receipt number - return false; - } else if (!Objects.equals(receipt1.getReceiptIssued(), receipt2.getReceiptIssued())) { - // Other issue date - return false; - } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) { - // Other user (unlikely to happen - return false; - } - - // Maybe same receipt! - return true; - } - - /** - * Private default constructor - */ - private Receipts () { - // Utilities don't have instances - } - -} diff --git a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java index cb8da48..8ce2d05 100644 --- a/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java +++ b/src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java @@ -42,10 +42,10 @@ 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.jfinancials.model.utils.ReceiptUtils; import org.mxchange.jproduct.model.product.GenericProduct; import org.mxchange.jproduct.model.product.Product; -import org.mxchange.jproduct.model.product.Products; +import org.mxchange.jproduct.model.utils.ProductUtils; /** * A POJO for receipt items @@ -250,9 +250,9 @@ public class FinancialReceiptItem implements BillableReceiptItem { // ... product quanity this.getItemProductQuantity().compareTo(billableReceiptItem.getItemProductQuantity()), // ... product instance - Products.compare(this.getItemProduct(), billableReceiptItem.getItemProduct()), + ProductUtils.compare(this.getItemProduct(), billableReceiptItem.getItemProduct()), // and finally receipt instance - Receipts.compare(this.getItemReceipt(), billableReceiptItem.getItemReceipt()) + ReceiptUtils.compare(this.getItemReceipt(), billableReceiptItem.getItemReceipt()) }; // Check all values diff --git a/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java b/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java deleted file mode 100644 index b47afca..0000000 --- a/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.model.receipt_item; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Objects; - -/** - * A utilities class for receipt items - * - * @author Roland Häder - */ -public class ReceiptItems implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 2_867_938_676_165_402L; - - /** - * Copies all fields from source entity to target entity. An exception might - * be thrown when both instances are the same. - *

- * @param sourceReceiptItem Source receipt item instance - * @param targetReceiptItem Target receipt item instance - */ - public static void copyReceiptItemData (final BillableReceiptItem sourceReceiptItem, final BillableReceiptItem targetReceiptItem) { - // Check parameter - if (null == sourceReceiptItem) { - // Throw NPE - throw new NullPointerException("sourceReceiptItem is null"); //NOI18N - } else if (null == targetReceiptItem) { - // Throw NPE - throw new NullPointerException("targetReceiptItem is null"); //NOI18N - } else if (Objects.equals(sourceReceiptItem, targetReceiptItem)) { - // Throw IAE - throw new IllegalArgumentException("sourceReceiptItem and targetReceiptItem are the same."); //NOI18N - } - - // Copy all fields - targetReceiptItem.setItemBrandName(sourceReceiptItem.getItemBrandName()); - targetReceiptItem.setItemCouponNumber(sourceReceiptItem.getItemCouponNumber()); - targetReceiptItem.setItemGrossPrice(sourceReceiptItem.getItemGrossPrice()); - targetReceiptItem.setItemId(sourceReceiptItem.getItemId()); - targetReceiptItem.setItemIsDiscount(sourceReceiptItem.getItemIsDiscount()); - targetReceiptItem.setItemIsRefund(sourceReceiptItem.getItemIsRefund()); - targetReceiptItem.setItemManufacturer(sourceReceiptItem.getItemManufacturer()); - targetReceiptItem.setItemNetPrice(sourceReceiptItem.getItemNetPrice()); - targetReceiptItem.setItemNumber(sourceReceiptItem.getItemNumber()); - targetReceiptItem.setItemProduct(sourceReceiptItem.getItemProduct()); - targetReceiptItem.setItemProductQuantity(sourceReceiptItem.getItemProductQuantity()); - targetReceiptItem.setItemReceipt(sourceReceiptItem.getItemReceipt()); - targetReceiptItem.setItemTaxRate(sourceReceiptItem.getItemTaxRate()); - } - - /** - * Checks if both receipt items are the same by assigned receipt, product - * and quantity. - *

- * @param receiptItem1 Receipt item 1 - * @param receiptItem2 Receipt item 2 - *

- * @return Whether both are equal - */ - public static boolean isSameReceiptItem (final BillableReceiptItem receiptItem1, final BillableReceiptItem receiptItem2) { - // Pre-compare both as entities (same id) - if (Objects.equals(receiptItem1, receiptItem2)) { - // Same entity (with id number) - return true; - } - - // Validate parameter - if (null == receiptItem1) { - // Throw NPE - throw new NullPointerException("receiptItem1 is null"); //NOI18N - } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId())); //NOI18N - } else if (receiptItem1.getItemReceipt() == null) { - // Throw NPE - throw new NullPointerException("receiptItem1.itemReceipt is null"); //NOI18N - } else if (receiptItem1.getItemReceipt().getReceiptId() == null) { - // Throw NPE - throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null"); //NOI18N - } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId())); //NOI18N - } else if (receiptItem1.getItemProduct() == null) { - // Throw NPE again - throw new NullPointerException("receiptItem1.itemProduct is null."); //NOI18N - } else if (receiptItem1.getItemProduct().getProductId() == null) { - // Throw NPE again - throw new NullPointerException("receiptItem1.itemProduct.productId is null."); //NOI18N - } else if (receiptItem1.getItemProduct().getProductId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId())); //NOI18N - } else if (null == receiptItem2) { - // Throw NPE - throw new NullPointerException("receiptItem2 is null"); //NOI18N - } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId())); //NOI18N - } else if (receiptItem2.getItemReceipt() == null) { - // Throw NPE - throw new NullPointerException("receiptItem2.itemReceipt is null"); //NOI18N - } else if (receiptItem2.getItemReceipt().getReceiptId() == null) { - // Throw NPE - throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null"); //NOI18N - } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId())); //NOI18N - } else if (receiptItem2.getItemProduct() == null) { - // Throw NPE again - throw new NullPointerException("receiptItem2.itemProduct is null."); //NOI18N - } else if (receiptItem2.getItemProduct().getProductId() == null) { - // Throw NPE again - throw new NullPointerException("receiptItem2.itemProduct.productId is null."); //NOI18N - } else if (receiptItem2.getItemProduct().getProductId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId())); //NOI18N - } else if (null == receiptItem2) { - // Throw NPE - throw new NullPointerException("receiptItem2 is null"); //NOI18N - } - - // Now check all individually - if (!Objects.equals(receiptItem1.getItemReceipt(), receiptItem2.getItemReceipt())) { - // Other item receipt - return false; - } else if (!Objects.equals(receiptItem1.getItemProduct(), receiptItem2.getItemProduct())) { - // Other item product - return false; - } else if (!Objects.equals(receiptItem1.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) { - // Other item quantity - return false; - } else if (!Objects.equals(receiptItem1.getItemNumber(), receiptItem2.getItemNumber())) { - // Other item number - return false; - } - - // Maybe same receipt! - return true; - } - - /** - * Private default constructor - */ - private ReceiptItems () { - // Utilities don't have instances - } - -} diff --git a/src/org/mxchange/jfinancials/model/utils/IncomeUtils.java b/src/org/mxchange/jfinancials/model/utils/IncomeUtils.java new file mode 100644 index 0000000..6bebeae --- /dev/null +++ b/src/org/mxchange/jfinancials/model/utils/IncomeUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.model.utils; + +import java.io.Serializable; + +/** + * An utilities class for incomes + *

+ * @author Roland Häder + */ +public class IncomeUtils implements Serializable { + + /** + * Serial number + */ + 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/utils/ReceiptItemUtils.java b/src/org/mxchange/jfinancials/model/utils/ReceiptItemUtils.java new file mode 100644 index 0000000..f3da633 --- /dev/null +++ b/src/org/mxchange/jfinancials/model/utils/ReceiptItemUtils.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.model.utils; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; + +/** + * A utilities class for receipt items + * + * @author Roland Häder + */ +public class ReceiptItemUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 2_867_938_676_165_402L; + + /** + * Copies all fields from source entity to target entity. An exception might + * be thrown when both instances are the same. + *

+ * @param sourceReceiptItem Source receipt item instance + * @param targetReceiptItem Target receipt item instance + */ + public static void copyReceiptItemData (final BillableReceiptItem sourceReceiptItem, final BillableReceiptItem targetReceiptItem) { + // Check parameter + if (null == sourceReceiptItem) { + // Throw NPE + throw new NullPointerException("sourceReceiptItem is null"); //NOI18N + } else if (null == targetReceiptItem) { + // Throw NPE + throw new NullPointerException("targetReceiptItem is null"); //NOI18N + } else if (Objects.equals(sourceReceiptItem, targetReceiptItem)) { + // Throw IAE + throw new IllegalArgumentException("sourceReceiptItem and targetReceiptItem are the same."); //NOI18N + } + + // Copy all fields + targetReceiptItem.setItemBrandName(sourceReceiptItem.getItemBrandName()); + targetReceiptItem.setItemCouponNumber(sourceReceiptItem.getItemCouponNumber()); + targetReceiptItem.setItemGrossPrice(sourceReceiptItem.getItemGrossPrice()); + targetReceiptItem.setItemId(sourceReceiptItem.getItemId()); + targetReceiptItem.setItemIsDiscount(sourceReceiptItem.getItemIsDiscount()); + targetReceiptItem.setItemIsRefund(sourceReceiptItem.getItemIsRefund()); + targetReceiptItem.setItemManufacturer(sourceReceiptItem.getItemManufacturer()); + targetReceiptItem.setItemNetPrice(sourceReceiptItem.getItemNetPrice()); + targetReceiptItem.setItemNumber(sourceReceiptItem.getItemNumber()); + targetReceiptItem.setItemProduct(sourceReceiptItem.getItemProduct()); + targetReceiptItem.setItemProductQuantity(sourceReceiptItem.getItemProductQuantity()); + targetReceiptItem.setItemReceipt(sourceReceiptItem.getItemReceipt()); + targetReceiptItem.setItemTaxRate(sourceReceiptItem.getItemTaxRate()); + } + + /** + * Checks if both receipt items are the same by assigned receipt, product + * and quantity. + *

+ * @param receiptItem1 Receipt item 1 + * @param receiptItem2 Receipt item 2 + *

+ * @return Whether both are equal + */ + public static boolean isSameReceiptItem (final BillableReceiptItem receiptItem1, final BillableReceiptItem receiptItem2) { + // Pre-compare both as entities (same id) + if (Objects.equals(receiptItem1, receiptItem2)) { + // Same entity (with id number) + return true; + } + + // Validate parameter + if (null == receiptItem1) { + // Throw NPE + throw new NullPointerException("receiptItem1 is null"); //NOI18N + } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId())); //NOI18N + } else if (receiptItem1.getItemReceipt() == null) { + // Throw NPE + throw new NullPointerException("receiptItem1.itemReceipt is null"); //NOI18N + } else if (receiptItem1.getItemReceipt().getReceiptId() == null) { + // Throw NPE + throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null"); //NOI18N + } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId())); //NOI18N + } else if (receiptItem1.getItemProduct() == null) { + // Throw NPE again + throw new NullPointerException("receiptItem1.itemProduct is null."); //NOI18N + } else if (receiptItem1.getItemProduct().getProductId() == null) { + // Throw NPE again + throw new NullPointerException("receiptItem1.itemProduct.productId is null."); //NOI18N + } else if (receiptItem1.getItemProduct().getProductId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId())); //NOI18N + } else if (null == receiptItem2) { + // Throw NPE + throw new NullPointerException("receiptItem2 is null"); //NOI18N + } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId())); //NOI18N + } else if (receiptItem2.getItemReceipt() == null) { + // Throw NPE + throw new NullPointerException("receiptItem2.itemReceipt is null"); //NOI18N + } else if (receiptItem2.getItemReceipt().getReceiptId() == null) { + // Throw NPE + throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null"); //NOI18N + } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId())); //NOI18N + } else if (receiptItem2.getItemProduct() == null) { + // Throw NPE again + throw new NullPointerException("receiptItem2.itemProduct is null."); //NOI18N + } else if (receiptItem2.getItemProduct().getProductId() == null) { + // Throw NPE again + throw new NullPointerException("receiptItem2.itemProduct.productId is null."); //NOI18N + } else if (receiptItem2.getItemProduct().getProductId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId())); //NOI18N + } else if (null == receiptItem2) { + // Throw NPE + throw new NullPointerException("receiptItem2 is null"); //NOI18N + } + + // Now check all individually + if (!Objects.equals(receiptItem1.getItemReceipt(), receiptItem2.getItemReceipt())) { + // Other item receipt + return false; + } else if (!Objects.equals(receiptItem1.getItemProduct(), receiptItem2.getItemProduct())) { + // Other item product + return false; + } else if (!Objects.equals(receiptItem1.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) { + // Other item quantity + return false; + } else if (!Objects.equals(receiptItem1.getItemNumber(), receiptItem2.getItemNumber())) { + // Other item number + return false; + } + + // Maybe same receipt! + return true; + } + + /** + * Private default constructor + */ + private ReceiptItemUtils () { + // Utilities don't have instances + } + +} diff --git a/src/org/mxchange/jfinancials/model/utils/ReceiptUtils.java b/src/org/mxchange/jfinancials/model/utils/ReceiptUtils.java new file mode 100644 index 0000000..8788fc3 --- /dev/null +++ b/src/org/mxchange/jfinancials/model/utils/ReceiptUtils.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.model.utils; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * A utilities class for receipts + * + * @author Roland Häder + */ +public class ReceiptUtils implements Serializable { + + /** + * Serial number + */ + 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 equality, 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); + } + + /** + * Copies all fields from source receipt to target receipt. + *

+ * @param sourceReceipt Source receipt instance + * @param targetReceipt Target Receipt instance + */ + public static void copyReceiptData (final BillableReceipt sourceReceipt, final BillableReceipt targetReceipt) { + // Both should not be null + if (null == sourceReceipt) { + // Throw NPE + throw new NullPointerException("sourceReceipt is null"); //NOI18N + } else if (null == targetReceipt) { + // Throw NPE + throw new NullPointerException("targetReceipt is null"); //NOI18N + } else if (Objects.equals(sourceReceipt, targetReceipt)) { + // Is exactly the same! + throw new IllegalArgumentException("sourcerReceipt and targetReceipt are the same."); //NOI18N + } + + // Copy all fields + targetReceipt.setReceiptBarCodeNumber(sourceReceipt.getReceiptBarCodeNumber()); + targetReceipt.setReceiptBonusCard(sourceReceipt.getReceiptBonusCard()); + targetReceipt.setReceiptBranchOffice(sourceReceipt.getReceiptBranchOffice()); + targetReceipt.setReceiptId(sourceReceipt.getReceiptId()); + targetReceipt.setReceiptIssued(sourceReceipt.getReceiptIssued()); + targetReceipt.setReceiptNumber(sourceReceipt.getReceiptNumber()); + targetReceipt.setReceiptPaymentType(sourceReceipt.getReceiptPaymentType()); + targetReceipt.setReceiptQrCode(sourceReceipt.getReceiptQrCode()); + targetReceipt.setReceiptRegisterNumber(sourceReceipt.getReceiptRegisterNumber()); + targetReceipt.setReceiptSellerEmployee(sourceReceipt.getReceiptSellerEmployee()); + targetReceipt.setReceiptSequenceNumber(sourceReceipt.getReceiptSequenceNumber()); + targetReceipt.setReceiptTransactionNumber(sourceReceipt.getReceiptTransactionNumber()); + targetReceipt.setReceiptUser(sourceReceipt.getReceiptUser()); + } + + /** + * 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)) { + // Same entity (with id number) + return true; + } + + // Validate parameter + if (null == receipt1) { + // Throw NPE + throw new NullPointerException("receipt1 is null"); //NOI18N + } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId())); //NOI18N + } else if (receipt1.getReceiptBranchOffice() == null) { + // Throw NPE + throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N + } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) { + // Throw NPE + throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null"); //NOI18N + } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId())); //NOI18N + } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) { + // Throw IAE + throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N + } else if (receipt1.getReceiptPaymentType() == null) { + // Throw NPE + throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N + } else if (null == receipt2) { + // Throw NPE + throw new NullPointerException("receipt2 is null"); //NOI18N + } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId())); //NOI18N + } else if (receipt2.getReceiptBranchOffice() == null) { + // Throw NPE + throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N + } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) { + // Throw NPE + throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null"); //NOI18N + } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId())); //NOI18N + } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) { + // Throw IAE + throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N + } else if (receipt2.getReceiptPaymentType() == null) { + // Throw NPE + throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N + } + + // Now check all individually + if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) { + // Other branch offices + return false; + } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) { + // Other receipt number + return false; + } else if (!Objects.equals(receipt1.getReceiptIssued(), receipt2.getReceiptIssued())) { + // Other issue date + return false; + } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) { + // Other user (unlikely to happen + return false; + } + + // Maybe same receipt! + return true; + } + + /** + * Private default constructor + */ + private ReceiptUtils () { + // Utilities don't have instances + } + +}