*/
package org.mxchange.jproduct.model.product;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
* <p>
* @param productI18nKey I18n key of product
* @param productGrossPrice Product's gross price
- * @param productCurrencyCode code for both prices
+ * @param productCurrencyCode Currency code for both prices
* @param productCategory Category instance
* @param productAvailability Availability (selectable by customer)
+ * @throws NullPointerException If a parameter is null
+ * @throws IllegalArgumentException If a parameter is empty (string) or out of bounds
*/
public GenericProduct (final String productI18nKey, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) {
+ // Call other constructor first
+ this();
+
+ // Validate all parameters
+ if (null == productAvailability) {
+ // Throw NPE
+ throw new NullPointerException("productAvailability is null"); //NOI18N
+ } else if (null == productCategory) {
+ // Throw it again
+ throw new NullPointerException("productCategory is null"); //NOI18N
+ } else if (productCategory.getCategoryId() == null) {
+ // Throw it again
+ throw new NullPointerException("productCategory.categoryId is null"); //NOI18N
+ } else if (productCategory.getCategoryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("productCategory.categoryId={0} is invalid", productCategory.getCategoryId())); //NOI18N
+ } else if (null == productCurrencyCode) {
+ // Throw it again
+ throw new NullPointerException("productCurrencyCode is null"); //NOI18N
+ } else if (productCurrencyCode.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("productCurrencyCode is empty"); //NOI18N
+ } else if (null == productGrossPrice) {
+ // Throw it again
+ throw new NullPointerException("productGrossPrice is null"); //NOI18N
+ } else if (productGrossPrice < 0) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("productGrossPrice={0} is invalid. Do not enter discounts as products.", productGrossPrice)); //NOI18N
+ } else if (null == productI18nKey) {
+ // Throw NPE
+ throw new NullPointerException("productI18nKey is null"); //NOI18N
+ } else if (productI18nKey.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("productI18nKey is empty"); //NOI18N
+ }
+
// Set all here
this.productI18nKey = productI18nKey;
this.productGrossPrice = productGrossPrice;
- this.productCurrencyCode = productCurrencyCode;
+ this.productCurrencyCode = productCurrencyCode.toUpperCase();
this.productCategory = productCategory;
this.productAvailability = productAvailability;
}