]> git.mxchange.org Git - jbonuscard-core.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 20 Sep 2017 19:34:03 +0000 (21:34 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 20 Sep 2017 19:34:03 +0000 (21:34 +0200)
- added constructor with all minimum required fields: payment type, branch
  office and date of issue

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java

index 9a9685fa812a2dddd94b4212c232b585bcaf7a84..ede7bedfa8154107a5893ee317d80fe2326c2690 100644 (file)
@@ -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
         * <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;
        }