*/
package org.mxchange.jfinancials.model.receipt;
+import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Objects;
import javax.persistence.Basic;
}
/**
- * Constructor with payment type, seller and user
+ * Constructor with payment type, seller (branch office) and user
* <p>
- * @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
+ * <p>
+ * @param receiptPaymentType Payment type
+ * @param receiptBranchOffice Branch office instance
+ * @param receiptIssued When this receipt has been issued
+ * <p>
+ * @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;
}