From: Roland Häder Date: Wed, 20 Sep 2017 19:34:03 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c2008df94c118cc005815d1908021e998d7bb235;p=jbonuscard-core.git Continued a bit: - added constructor with all minimum required fields: payment type, branch office and date of issue Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java index 9a9685f..ede7bed 100644 --- a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java @@ -16,6 +16,7 @@ */ package org.mxchange.jfinancials.model.receipt; +import java.text.MessageFormat; import java.util.Calendar; import java.util.Objects; import javax.persistence.Basic; @@ -123,21 +124,71 @@ public class FinancialReceipt implements BillableReceipt { } /** - * Constructor with payment type, seller and user + * Constructor with payment type, seller (branch office) and user *

- * @param receiptPaymentType Payment type - * @param branchOffice Branch office instance - * @param receiptUser User instance - * @param receiptIssued When this receipt has been issued + * @param receiptPaymentType Payment type + * @param receiptBranchOffice Branch office instance + * @param receiptUser User instance + * @param receiptIssued When this receipt has been issued + * + * @throws NullPointerException If user instance is not set + * @throws IllegalArgumentException If user instance's userId is invalid */ - public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice branchOffice, final User receiptUser, final Calendar receiptIssued) { + public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice receiptBranchOffice, final User receiptUser, final Calendar receiptIssued) { + // Call other constructor first + this(receiptPaymentType, receiptBranchOffice, receiptIssued); + + // Validate parameter + if (null == receiptUser) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (receiptUser.getUserId() == null) { + // Throw it again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (receiptUser.getUserId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", receiptUser.getUserId())); //NOI18N + } + + // Set user instance + this.receiptUser = receiptUser; + } + + /** + * Constructor with payment type, branch office and when it has been issued + *

+ * @param receiptPaymentType Payment type + * @param receiptBranchOffice Branch office instance + * @param receiptIssued When this receipt has been issued + *

+ * @throws NullPointerException If user instance is not set + * @throws IllegalArgumentException If branchId is invalid + */ + public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice receiptBranchOffice, final Calendar receiptIssued) { // Call other constructor first this(); + // Validate all parameter + if (null == receiptPaymentType) { + // Throw NPE + throw new NullPointerException("receiptPaymentType is null"); //NOI18N + } else if (null == receiptBranchOffice) { + // Throw NPE + throw new NullPointerException("receiptBranchOffice is null"); //NOI18N + } else if (receiptBranchOffice.getBranchId() == null) { + // Throw NPE + throw new NullPointerException("receiptBranchOffice.branchId is null"); //NOI18N + } else if (receiptBranchOffice.getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptBranchOffice.branchId={0} is invalid", receiptBranchOffice.getBranchId())); //NOI18N + } else if (null == receiptIssued) { + // Throw NPE + throw new NullPointerException("receiptIssued is null"); //NOI18N + } + // Set all values this.receiptPaymentType = receiptPaymentType; - this.receiptBranchOffice = branchOffice; - this.receiptUser = receiptUser; + this.receiptBranchOffice = receiptBranchOffice; this.receiptIssued = receiptIssued; }