Class Product.Builder

  • Enclosing class:
    Product

    public static class Product.Builder
    extends java.lang.Object
    This class is designed to construct a Product object using the Builder pattern.
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder​(Product product)
      Create a Product.Builder from an existing Product.
      Builder​(java.lang.String name, java.lang.String sku, double unitPrice)
      Create a Product.Builder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Product.Builder brand​(java.lang.String brand)
      Sets the brand to associate with this Product.
      Product build()
      Build the Product object.
      Product.Builder category​(java.lang.String category)
      Sets the category associated with the Product.
      Product.Builder couponCode​(java.lang.String couponCode)
      Sets the coupon code to associate with this Product.
      Product.Builder customAttributes​(java.util.Map<java.lang.String,​java.lang.String> attributes)
      Set a custom Map of attributes on an object.
      Product.Builder name​(java.lang.String name)
      Change the name/description to associate with this Product.
      Product.Builder position​(java.lang.Integer position)
      Sets the position of the product on the page or product impression list.
      Product.Builder quantity​(double quantity)
      Sets the quantity to associate with this Product.
      Product.Builder sku​(java.lang.String sku)
      Change unique SKU or ID to associate with this Product.
      Product.Builder unitPrice​(double price)
      Sets the unit price to associate with this Product.
      Product.Builder variant​(java.lang.String variant)
      Sets the variant to associate with this Product.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Builder

        public Builder​(@NonNull
                       java.lang.String name,
                       @NonNull
                       java.lang.String sku,
                       double unitPrice)
        Create a Product.Builder. The parameters of this method are all required for a valid product.
        Parameters:
        name - a description/name for the Product
        sku - a SKU or ID that uniquely identifies this Product
        unitPrice - the cost of a single Product
      • Builder

        public Builder​(@NonNull
                       Product product)
        Create a Product.Builder from an existing Product. This may be useful if you need to alter or duplicate an existing Product.
        Parameters:
        product - an existing Product object
    • Method Detail

      • customAttributes

        @NonNull
        public Product.Builder customAttributes​(@Nullable
                                                java.util.Map<java.lang.String,​java.lang.String> attributes)
        Set a custom Map of attributes on an object. Use this only if there is an attribute of a Product that does not correlate to any of the default attributes.
        Parameters:
        attributes - a Map of custom keys and values
        Returns:
        returns this Builder object for use in method chaining
      • category

        @NonNull
        public Product.Builder category​(@Nullable
                                        java.lang.String category)
        Sets the category associated with the Product.
        Parameters:
        category - the Product's category
        Returns:
        returns this Builder object for use in method chaining
      • couponCode

        @NonNull
        public Product.Builder couponCode​(@Nullable
                                          java.lang.String couponCode)
        Sets the coupon code to associate with this Product.
        Parameters:
        couponCode - the Product's coupon code
        Returns:
        returns this Builder object for use in method chaining
      • sku

        @NonNull
        public Product.Builder sku​(@NonNull
                                   java.lang.String sku)
        Change unique SKU or ID to associate with this Product.
        Parameters:
        sku - the Product's SKU or ID
        Returns:
        returns this Builder object for use in method chaining
      • name

        @NonNull
        public Product.Builder name​(@NonNull
                                    java.lang.String name)
        Change the name/description to associate with this Product.
        Parameters:
        name - the Product's name
        Returns:
        returns this Builder object for use in method chaining
      • position

        @NonNull
        public Product.Builder position​(@Nullable
                                        java.lang.Integer position)
        Sets the position of the product on the page or product impression list.
        Parameters:
        position - the Products position
        Returns:
        returns this Builder object for use in method chaining
      • unitPrice

        @NonNull
        public Product.Builder unitPrice​(double price)
        Sets the unit price to associate with this Product.
        Parameters:
        price - the Product's price
        Returns:
        returns this Builder object for use in method chaining
      • quantity

        @NonNull
        public Product.Builder quantity​(double quantity)
        Sets the quantity to associate with this Product. This field defaults to 1
        Parameters:
        quantity - the Product's quantity
        Returns:
        returns this Builder object for use in method chaining
      • brand

        @NonNull
        public Product.Builder brand​(@Nullable
                                     java.lang.String brand)
        Sets the brand to associate with this Product.
        Parameters:
        brand - the Product's brand
        Returns:
        returns this Builder object for use in method chaining
      • variant

        @NonNull
        public Product.Builder variant​(@Nullable
                                       java.lang.String variant)
        Sets the variant to associate with this Product.
        Parameters:
        variant - the Product's variant
        Returns:
        returns this Builder object for use in method chaining
      • build

        @NonNull
        public Product build()
        Build the Product object.
        Returns:
        a Product object to be added to a CommerceEvent}