Class MaterialBundleBuilder

java.lang.Object
com.university.bookstore.builder.MaterialBundleBuilder
All Implemented Interfaces:
ComponentBuilder<MaterialBundle>

public class MaterialBundleBuilder extends Object implements ComponentBuilder<MaterialBundle>
Builder for creating MaterialBundle instances with a fluent interface. Demonstrates the Builder pattern for complex composite object construction.
Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • MaterialBundleBuilder

      public MaterialBundleBuilder()
  • Method Details

    • setBundleName

      public MaterialBundleBuilder setBundleName(String bundleName)
      Sets the bundle name.
      Parameters:
      bundleName - the bundle name
      Returns:
      this builder for method chaining
    • setBundleDiscount

      public MaterialBundleBuilder setBundleDiscount(double discount)
      Sets the bundle discount rate.
      Parameters:
      discount - the discount rate (0.0 to 1.0)
      Returns:
      this builder for method chaining
    • setBundleDiscountPercent

      public MaterialBundleBuilder setBundleDiscountPercent(double discountPercent)
      Sets the bundle discount percentage.
      Parameters:
      discountPercent - the discount percentage (0.0 to 100.0)
      Returns:
      this builder for method chaining
    • addMaterial

      public MaterialBundleBuilder addMaterial(Material material)
      Adds a material to the bundle.
      Parameters:
      material - the material to add
      Returns:
      this builder for method chaining
    • addBundle

      public MaterialBundleBuilder addBundle(MaterialBundle bundle)
      Adds a bundle to this bundle (nested bundles).
      Parameters:
      bundle - the bundle to add
      Returns:
      this builder for method chaining
    • addComponent

      public MaterialBundleBuilder addComponent(MaterialComponent component)
      Adds a material component to the bundle.
      Parameters:
      component - the component to add
      Returns:
      this builder for method chaining
    • addMaterials

      public MaterialBundleBuilder addMaterials(List<Material> materials)
      Adds multiple materials to the bundle.
      Parameters:
      materials - the materials to add
      Returns:
      this builder for method chaining
    • addComponents

      public MaterialBundleBuilder addComponents(List<MaterialComponent> components)
      Adds multiple components to the bundle.
      Parameters:
      components - the components to add
      Returns:
      this builder for method chaining
    • removeMaterial

      public MaterialBundleBuilder removeMaterial(Material material)
      Removes a material from the bundle.
      Parameters:
      material - the material to remove
      Returns:
      this builder for method chaining
    • removeComponent

      public MaterialBundleBuilder removeComponent(MaterialComponent component)
      Removes a component from the bundle.
      Parameters:
      component - the component to remove
      Returns:
      this builder for method chaining
    • clearComponents

      public MaterialBundleBuilder clearComponents()
      Clears all components from the bundle.
      Returns:
      this builder for method chaining
    • setSmallDiscount

      public MaterialBundleBuilder setSmallDiscount()
      Sets a 10% discount.
      Returns:
      this builder for method chaining
    • setMediumDiscount

      public MaterialBundleBuilder setMediumDiscount()
      Sets a 20% discount.
      Returns:
      this builder for method chaining
    • setLargeDiscount

      public MaterialBundleBuilder setLargeDiscount()
      Sets a 30% discount.
      Returns:
      this builder for method chaining
    • build

      public MaterialBundle build()
      Description copied from interface: ComponentBuilder
      Builds and returns the component instance.
      Specified by:
      build in interface ComponentBuilder<MaterialBundle>
      Returns:
      the built component
    • validate

      public void validate()
      Description copied from interface: ComponentBuilder
      Validates that all required fields are set.
      Specified by:
      validate in interface ComponentBuilder<MaterialBundle>
    • reset

      public void reset()
      Description copied from interface: ComponentBuilder
      Resets the builder to its initial state.
      Specified by:
      reset in interface ComponentBuilder<MaterialBundle>
    • getBundleName

      public String getBundleName()
      Gets the current bundle name.
      Returns:
      the current bundle name
    • getBundleDiscount

      public double getBundleDiscount()
      Gets the current bundle discount.
      Returns:
      the current bundle discount
    • getBundleDiscountPercent

      public double getBundleDiscountPercent()
      Gets the current bundle discount percentage.
      Returns:
      the current bundle discount percentage
    • getComponents

      public List<MaterialComponent> getComponents()
      Gets the current components.
      Returns:
      the current components
    • getComponentCount

      public int getComponentCount()
      Gets the number of components.
      Returns:
      the component count
    • hasComponents

      public boolean hasComponents()
      Checks if the bundle has any components.
      Returns:
      true if the bundle has components
    • getTotalPrice

      public double getTotalPrice()
      Gets the total price of all components.
      Returns:
      the total price
    • getTotalDiscountedPrice

      public double getTotalDiscountedPrice()
      Gets the total discounted price of all components.
      Returns:
      the total discounted price
    • getTotalSavings

      public double getTotalSavings()
      Gets the total savings from the bundle discount.
      Returns:
      the total savings
    • toString

      public String toString()
      Overrides:
      toString in class Object