Class MaterialBundleBuilder
java.lang.Object
com.university.bookstore.builder.MaterialBundleBuilder
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddBundle(MaterialBundle bundle) Adds a bundle to this bundle (nested bundles).addComponent(MaterialComponent component) Adds a material component to the bundle.addComponents(List<MaterialComponent> components) Adds multiple components to the bundle.addMaterial(Material material) Adds a material to the bundle.addMaterials(List<Material> materials) Adds multiple materials to the bundle.build()Builds and returns the component instance.Clears all components from the bundle.doubleGets the current bundle discount.doubleGets the current bundle discount percentage.Gets the current bundle name.intGets the number of components.Gets the current components.doubleGets the total discounted price of all components.doubleGets the total price of all components.doubleGets the total savings from the bundle discount.booleanChecks if the bundle has any components.removeComponent(MaterialComponent component) Removes a component from the bundle.removeMaterial(Material material) Removes a material from the bundle.voidreset()Resets the builder to its initial state.setBundleDiscount(double discount) Sets the bundle discount rate.setBundleDiscountPercent(double discountPercent) Sets the bundle discount percentage.setBundleName(String bundleName) Sets the bundle name.Sets a 30% discount.Sets a 20% discount.Sets a 10% discount.toString()voidvalidate()Validates that all required fields are set.
-
Constructor Details
-
MaterialBundleBuilder
public MaterialBundleBuilder()
-
-
Method Details
-
setBundleName
Sets the bundle name.- Parameters:
bundleName- the bundle name- Returns:
- this builder for method chaining
-
setBundleDiscount
Sets the bundle discount rate.- Parameters:
discount- the discount rate (0.0 to 1.0)- Returns:
- this builder for method chaining
-
setBundleDiscountPercent
Sets the bundle discount percentage.- Parameters:
discountPercent- the discount percentage (0.0 to 100.0)- Returns:
- this builder for method chaining
-
addMaterial
Adds a material to the bundle.- Parameters:
material- the material to add- Returns:
- this builder for method chaining
-
addBundle
Adds a bundle to this bundle (nested bundles).- Parameters:
bundle- the bundle to add- Returns:
- this builder for method chaining
-
addComponent
Adds a material component to the bundle.- Parameters:
component- the component to add- Returns:
- this builder for method chaining
-
addMaterials
Adds multiple materials to the bundle.- Parameters:
materials- the materials to add- Returns:
- this builder for method chaining
-
addComponents
Adds multiple components to the bundle.- Parameters:
components- the components to add- Returns:
- this builder for method chaining
-
removeMaterial
Removes a material from the bundle.- Parameters:
material- the material to remove- Returns:
- this builder for method chaining
-
removeComponent
Removes a component from the bundle.- Parameters:
component- the component to remove- Returns:
- this builder for method chaining
-
clearComponents
Clears all components from the bundle.- Returns:
- this builder for method chaining
-
setSmallDiscount
Sets a 10% discount.- Returns:
- this builder for method chaining
-
setMediumDiscount
Sets a 20% discount.- Returns:
- this builder for method chaining
-
setLargeDiscount
Sets a 30% discount.- Returns:
- this builder for method chaining
-
build
Description copied from interface:ComponentBuilderBuilds and returns the component instance.- Specified by:
buildin interfaceComponentBuilder<MaterialBundle>- Returns:
- the built component
-
validate
public void validate()Description copied from interface:ComponentBuilderValidates that all required fields are set.- Specified by:
validatein interfaceComponentBuilder<MaterialBundle>
-
reset
public void reset()Description copied from interface:ComponentBuilderResets the builder to its initial state.- Specified by:
resetin interfaceComponentBuilder<MaterialBundle>
-
getBundleName
-
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
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
-