*/
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)) {
} 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) {
} 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");
}
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;
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