From af6a40c95498af150a0208e2ee4c92cfdb8ad2fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 4 Nov 2017 13:35:52 +0100 Subject: [PATCH] Continued: - changed non-localizable unit type to localizable unit's i18n key - now unit amount and i18n key are no longer optional as they are really needed - if you don't know it, like UNIT_TYPE_GRAMS, enter UNIT_TYPE_ITEM for i18n key - added product number MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/product/GenericProduct.java | 54 +++++++++++++++---- .../jproduct/model/product/Product.java | 26 ++++++--- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index 5775a98..508360a 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -126,6 +126,12 @@ public class GenericProduct implements Product { @Column (name = "product_net_price") private Float productNetPrice; + /** + * Number of product + */ + @Column (name = "product_number") + private Long productNumber; + /** * Tax rate (0-1, by 1=100%) */ @@ -135,14 +141,16 @@ public class GenericProduct implements Product { /** * Amount of this product (for example 1 for 1 liter) */ - @Column (name = "product_unit_amount") + @Basic (optional = false) + @Column (name = "product_unit_amount", nullable = false) private Float productUnitAmount; /** * Unit type (for example liter) */ - @Column (name = "product_unit_type") - private String productUnitType; + @Basic (optional = false) + @Column (name = "product_unit_i18n_key", nullable = false) + private String productUnitI18nKey; /** * Default constructor @@ -158,10 +166,14 @@ public class GenericProduct implements Product { * @param productCurrencyCode Currency code for both prices * @param productCategory Category instance * @param productAvailability Availability (selectable by customer) + * @param productUnitAmount Unit amount + * @param productUnitI18nKey Unit's i18n key + *

* @throws NullPointerException If a parameter is null - * @throws IllegalArgumentException If a parameter is empty (string) or out of bounds + * @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) { + public GenericProduct (final String productI18nKey, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability, final Float productUnitAmount, final String productUnitI18nKey) { // Call other constructor first this(); @@ -196,6 +208,18 @@ public class GenericProduct implements Product { } else if (productI18nKey.isEmpty()) { // Throw IAE throw new IllegalArgumentException("productI18nKey is empty"); //NOI18N + } else if (null == productUnitAmount) { + // Throw it again + throw new NullPointerException("productUnitAmount is null"); //NOI18N + } else if (productUnitAmount < 0) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("productUnitAmount={0} is invalid. Do not enter discounts as products.", productUnitAmount)); //NOI18N + } else if (null == productUnitI18nKey) { + // Throw NPE + throw new NullPointerException("productUnitI18nKey is null"); //NOI18N + } else if (productUnitI18nKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("productUnitI18nKey is empty"); //NOI18N } // Set all here @@ -204,6 +228,8 @@ public class GenericProduct implements Product { this.productCurrencyCode = productCurrencyCode.toUpperCase(); this.productCategory = productCategory; this.productAvailability = productAvailability; + this.productUnitAmount = productUnitAmount; + this.productUnitI18nKey = productUnitI18nKey; } @Override @@ -319,6 +345,16 @@ public class GenericProduct implements Product { this.productNetPrice = productNetPrice; } + @Override + public Long getProductNumber () { + return this.productNumber; + } + + @Override + public void setProductNumber (final Long productNumber) { + this.productNumber = productNumber; + } + @Override public Float getProductTaxRate () { return this.productTaxRate; @@ -340,13 +376,13 @@ public class GenericProduct implements Product { } @Override - public String getProductUnitType () { - return this.productUnitType; + public String getProductUnitI18nKey () { + return this.productUnitI18nKey; } @Override - public void setProductUnitType (final String productUnitType) { - this.productUnitType = productUnitType; + public void setProductUnitI18nKey (final String productUnitI18nKey) { + this.productUnitI18nKey = productUnitI18nKey; } @Override diff --git a/src/org/mxchange/jproduct/model/product/Product.java b/src/org/mxchange/jproduct/model/product/Product.java index 19d4b56..dce0e96 100644 --- a/src/org/mxchange/jproduct/model/product/Product.java +++ b/src/org/mxchange/jproduct/model/product/Product.java @@ -183,18 +183,32 @@ public interface Product extends Serializable { void setProductUnitAmount (final Float productUnitAmount); /** - * Getter for product's unit type + * Getter for product's i18n key *

- * @return Product's unit type + * @return Product's i18n key */ - String getProductUnitType (); + String getProductUnitI18nKey (); /** - * Setter for product's unit type + * Setter for product's i18n key *

- * @param productUnitType Product's unit type + * @param productI18nKey Product's i18n key */ - void setProductUnitType (final String productUnitType); + void setProductUnitI18nKey (final String productI18nKey); + + /** + * Getter for product's number + *

+ * @return Product's number + */ + Long getProductNumber (); + + /** + * Setter for product's number + *

+ * @param productNumber Product's number + */ + void setProductNumber (final Long productNumber); @Override boolean equals (final Object object); -- 2.39.5