2 * Copyright (C) 2017, 2018 Free Software Foundation
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;
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 Receipts implements Serializable {
33 private static final long serialVersionUID = 2_867_938_676_165_401L;
35 public static boolean isSameReceipt (final BillableReceipt receipt1, final BillableReceipt receipt2) {
36 // Pre-compare both as entities (same id)
37 if (Objects.equals(receipt1, receipt2)) {
38 // Same entity (with id number)
43 if (null == receipt1) {
45 throw new NullPointerException("receipt1 is null");
46 } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
48 throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId()));
49 } else if (receipt1.getReceiptBranchOffice() == null) {
51 throw new NullPointerException("receipt1.receiptBranchOffice is null");
52 } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
54 throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
55 } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
57 throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
58 } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) {
60 throw new IllegalArgumentException("receipt1.receiptNumber is empty.");
61 } else if (receipt1.getReceiptPaymentType()== null) {
63 throw new NullPointerException("receipt1.receiptPaymentType is null");
64 } else if (null == receipt2) {
66 throw new NullPointerException("receipt2 is null");
67 } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
69 throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
70 } else if (receipt2.getReceiptBranchOffice() == null) {
72 throw new NullPointerException("receipt2.receiptBranchOffice is null");
73 } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
75 throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
76 } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
78 throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
79 } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) {
81 throw new IllegalArgumentException("receipt2.receiptNumber is empty.");
82 } else if (receipt2.getReceiptPaymentType()== null) {
84 throw new NullPointerException("receipt2.receiptPaymentType is null");
87 // Now check all individually
88 if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) {
89 // Other branch offices
91 } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
92 // Other receipt number
94 } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
95 // Other user (unlikely to happen
99 // Maybe same receipt!
104 * Private default constructor
106 private Receipts () {
107 // Utilities don't have instances