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;
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.getReceiptNumber() == null) {
51 throw new NullPointerException("receipt1.receiptNumber is null");
52 } else if (receipt1.getReceiptNumber() < 1) {
54 throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptNumber={0} is not valid", receipt1.getReceiptNumber()));
55 } else if (receipt1.getReceiptBranchOffice() == null) {
57 throw new NullPointerException("receipt1.receiptBranchOffice is null");
58 } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
60 throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
61 } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
63 throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
64 } else if (receipt1.getReceiptPaymentType()== null) {
66 throw new NullPointerException("receipt1.receiptPaymentType is null");
67 } else if (null == receipt2) {
69 throw new NullPointerException("receipt2 is null");
70 } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
72 throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
73 } else if (receipt2.getReceiptNumber() == null) {
75 throw new NullPointerException("receipt2.receiptNumber is null");
76 } else if (receipt2.getReceiptNumber() < 1) {
78 throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptNumber={0} is not valid", receipt2.getReceiptNumber()));
79 } else if (receipt2.getReceiptBranchOffice() == null) {
81 throw new NullPointerException("receipt2.receiptBranchOffice is null");
82 } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
84 throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
85 } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
87 throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
88 } else if (receipt2.getReceiptPaymentType()== null) {
90 throw new NullPointerException("receipt2.receiptPaymentType is null");
93 // Now check all individually
94 if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) {
95 // Other branch offices
97 } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
98 // Other receipt number
100 } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
101 // Other user (unlikely to happen
105 // Maybe same receipt!
110 * Private default constructor
112 private Receipts () {
113 // Utilities don't have instances