]> git.mxchange.org Git - jfinancials-core.git/blob - src/org/mxchange/jfinancials/model/receipt/Receipts.java
Continued a bit:
[jfinancials-core.git] / src / org / mxchange / jfinancials / model / receipt / Receipts.java
1 /*
2  * Copyright (C) 2017 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jfinancials.model.receipt;
18
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.Objects;
22
23 /**
24  * A utilities class for receipts
25  *
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class Receipts implements Serializable {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 2_867_938_676_165_401L;
34
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)
39                         return true;
40                 }
41
42                 // Validate parameter
43                 if (null == receipt1) {
44                         // Throw NPE
45                         throw new NullPointerException("receipt1 is null");
46                 } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
47                         // Throw IAE
48                         throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId()));
49                 } else if (receipt1.getReceiptBranchOffice() == null) {
50                         // Throw NPE
51                         throw new NullPointerException("receipt1.receiptBranchOffice is null");
52                 } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
53                         // Throw NPE
54                         throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
55                 } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
56                         // Throw NPE
57                         throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
58                 } else if ((receipt1.getReceiptNumber() instanceof Long) && (receipt1.getReceiptNumber() < 1)) {
59                         // Throw IAE
60                         throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptNumber={0} is not valid.", receipt1.getReceiptNumber()));
61                 } else if (receipt1.getReceiptPaymentType()== null) {
62                         // Throw NPE
63                         throw new NullPointerException("receipt1.receiptPaymentType is null");
64                 } else if (null == receipt2) {
65                         // Throw NPE
66                         throw new NullPointerException("receipt2 is null");
67                 } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
68                         // Throw IAE
69                         throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
70                 } else if (receipt2.getReceiptBranchOffice() == null) {
71                         // Throw NPE
72                         throw new NullPointerException("receipt2.receiptBranchOffice is null");
73                 } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
74                         // Throw NPE
75                         throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
76                 } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
77                         // Throw NPE
78                         throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
79                 } else if ((receipt2.getReceiptNumber() instanceof Long) && (receipt2.getReceiptNumber() < 1)) {
80                         // Throw IAE
81                         throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptNumber={0} is not valid.", receipt2.getReceiptNumber()));
82                 } else if (receipt2.getReceiptPaymentType()== null) {
83                         // Throw NPE
84                         throw new NullPointerException("receipt2.receiptPaymentType is null");
85                 }
86
87                 // Now check all individually
88                 if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) {
89                         // Other branch offices
90                         return false;
91                 } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
92                         // Other receipt number
93                         return false;
94                 } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
95                         // Other user (unlikely to happen
96                         return false;
97                 }
98
99                 // Maybe same receipt!
100                 return true;
101         }
102
103         /**
104          * Private default constructor
105          */
106         private Receipts () {
107                 // Utilities don't have instances
108         }
109
110 }