/*
- * Copyright (C) 2017, 2018 Free Software Foundation
+ * 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
* @return Comparison value
*/
public static int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) {
- // Check euqality, then at least first must be given
+ // Check equality, then at least first must be given
if (Objects.equals(receipt1, receipt2)) {
// Both are same
return 0;
return receipt1.compareTo(receipt2);
}
+ /**
+ * Copies all fields from source receipt to target receipt.
+ * <p>
+ * @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
// Validate parameter
if (null == receipt1) {
// Throw NPE
- throw new NullPointerException("receipt1 is null");
+ 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()));
+ 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");
+ throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N
} else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
// Throw NPE
- throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
+ 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()));
+ 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.");
+ throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N
} else if (receipt1.getReceiptPaymentType() == null) {
// Throw NPE
- throw new NullPointerException("receipt1.receiptPaymentType is null");
+ throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N
} else if (null == receipt2) {
// Throw NPE
- throw new NullPointerException("receipt2 is null");
+ 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()));
+ 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");
+ throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N
} else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
// Throw NPE
- throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
+ 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()));
+ 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.");
+ throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N
} else if (receipt2.getReceiptPaymentType() == null) {
// Throw NPE
- throw new NullPointerException("receipt2.receiptPaymentType is null");
+ throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N
}
// Now check all individually
} 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;