2 * Copyright (C) 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.model.receipt.item;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.Objects;
24 * A utilities class for receipts
26 * @author Roland Häder<roland@mxchange.org>
28 public class ReceiptItems implements Serializable {
33 private static final long serialVersionUID = 2_867_938_676_165_402L;
36 * Checks if both receipt items are the same by assigned receipt, product
39 * @param receiptItem1 Receipt item 1
40 * @param receiptItem2 Receipt item 2
42 * @return Whether both are equal
44 public static boolean isSameReceiptItem (final BillableReceiptItem receiptItem1, final BillableReceiptItem receiptItem2) {
45 // Pre-compare both as entities (same id)
46 if (Objects.equals(receiptItem1, receiptItem2)) {
47 // Same entity (with id number)
52 if (null == receiptItem1) {
54 throw new NullPointerException("receiptItem1 is null"); //NOI18N
55 } else if ((receiptItem1.getItemId() instanceof Long) && (receiptItem1.getItemId() < 1)) {
57 throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemId={0} is not valid.", receiptItem1.getItemId())); //NOI18N
58 } else if (receiptItem1.getItemReceipt() == null) {
60 throw new NullPointerException("receiptItem1.itemReceipt is null"); //NOI18N
61 } else if (receiptItem1.getItemReceipt().getReceiptId() == null) {
63 throw new NullPointerException("receiptItem1.itemReceipt.receiptId is null"); //NOI18N
64 } else if (receiptItem1.getItemReceipt().getReceiptId() < 1) {
66 throw new NullPointerException(MessageFormat.format("receiptItem1.itemReceipt.receiptId={0} is not valid", receiptItem1.getItemReceipt().getReceiptId())); //NOI18N
67 } else if (receiptItem1.getItemProduct() == null) {
69 throw new NullPointerException("receiptItem1.itemProduct is null."); //NOI18N
70 } else if (receiptItem1.getItemProduct().getProductId() == null) {
72 throw new NullPointerException("receiptItem1.itemProduct.productId is null."); //NOI18N
73 } else if (receiptItem1.getItemProduct().getProductId() < 1) {
75 throw new IllegalArgumentException(MessageFormat.format("receiptItem1.itemProduct.productId={0} is invalid.", receiptItem1.getItemProduct().getProductId())); //NOI18N
76 } else if (null == receiptItem2) {
78 throw new NullPointerException("receiptItem2 is null"); //NOI18N
79 } else if ((receiptItem2.getItemId() instanceof Long) && (receiptItem2.getItemId() < 1)) {
81 throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemId={0} is not valid.", receiptItem2.getItemId())); //NOI18N
82 } else if (receiptItem2.getItemReceipt() == null) {
84 throw new NullPointerException("receiptItem2.itemReceipt is null"); //NOI18N
85 } else if (receiptItem2.getItemReceipt().getReceiptId() == null) {
87 throw new NullPointerException("receiptItem2.itemReceipt.receiptId is null"); //NOI18N
88 } else if (receiptItem2.getItemReceipt().getReceiptId() < 1) {
90 throw new NullPointerException(MessageFormat.format("receiptItem2.itemReceipt.receiptId={0} is not valid", receiptItem2.getItemReceipt().getReceiptId())); //NOI18N
91 } else if (receiptItem2.getItemProduct() == null) {
93 throw new NullPointerException("receiptItem2.itemProduct is null."); //NOI18N
94 } else if (receiptItem2.getItemProduct().getProductId() == null) {
96 throw new NullPointerException("receiptItem2.itemProduct.productId is null."); //NOI18N
97 } else if (receiptItem2.getItemProduct().getProductId() < 1) {
99 throw new IllegalArgumentException(MessageFormat.format("receiptItem2.itemProduct.productId={0} is invalid.", receiptItem2.getItemProduct().getProductId())); //NOI18N
100 } else if (null == receiptItem2) {
102 throw new NullPointerException("receiptItem2 is null"); //NOI18N
105 // Now check all individually
106 if (!Objects.equals(receiptItem1.getItemReceipt(), receiptItem2.getItemReceipt())) {
107 // Other item receipt
109 } else if (!Objects.equals(receiptItem1.getItemProduct(), receiptItem2.getItemProduct())) {
110 // Other item product
112 } else if (!Objects.equals(receiptItem1.getItemProductQuantity(), receiptItem2.getItemProductQuantity())) {
113 // Other item quantity
117 // Maybe same receipt!
122 * Private default constructor
124 private ReceiptItems () {
125 // Utilities don't have instances