Class MaterialLeaf

java.lang.Object
com.university.bookstore.composite.MaterialLeaf
All Implemented Interfaces:
MaterialComponent

public class MaterialLeaf extends Object implements MaterialComponent
Leaf component in the Composite pattern. Represents an individual material that cannot contain other components.

This class wraps a Material object and implements the MaterialComponent interface, allowing individual materials to be treated uniformly with composite bundles.

Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • MaterialLeaf

      public MaterialLeaf(Material material)
      Creates a new material leaf wrapping the specified material.
      Parameters:
      material - the material to wrap
      Throws:
      IllegalArgumentException - if material is null
  • Method Details

    • getTitle

      public String getTitle()
      Description copied from interface: MaterialComponent
      Gets the title of this component. For individual materials, this is the material title. For bundles, this is the bundle name.
      Specified by:
      getTitle in interface MaterialComponent
      Returns:
      the component title
    • getPrice

      public double getPrice()
      Description copied from interface: MaterialComponent
      Gets the total price of this component. For individual materials, this is the material price. For bundles, this is the sum of all contained materials.
      Specified by:
      getPrice in interface MaterialComponent
      Returns:
      the total price
    • getDiscountedPrice

      public double getDiscountedPrice()
      Description copied from interface: MaterialComponent
      Gets the discounted price of this component. For individual materials, this applies the material's discount. For bundles, this applies the bundle discount to the total price.
      Specified by:
      getDiscountedPrice in interface MaterialComponent
      Returns:
      the discounted price
    • getDescription

      public String getDescription()
      Description copied from interface: MaterialComponent
      Gets a description of this component. Provides detailed information about the component and its contents.
      Specified by:
      getDescription in interface MaterialComponent
      Returns:
      the component description
    • getMaterials

      public List<Material> getMaterials()
      Description copied from interface: MaterialComponent
      Gets all materials contained in this component. For individual materials, returns a list containing only itself. For bundles, returns all materials in the bundle (recursively).
      Specified by:
      getMaterials in interface MaterialComponent
      Returns:
      list of all contained materials
    • getItemCount

      public int getItemCount()
      Description copied from interface: MaterialComponent
      Gets the total number of items in this component. For individual materials, returns 1. For bundles, returns the sum of all contained items.
      Specified by:
      getItemCount in interface MaterialComponent
      Returns:
      the total item count
    • getDiscountRate

      public double getDiscountRate()
      Description copied from interface: MaterialComponent
      Gets the discount rate applied to this component.
      Specified by:
      getDiscountRate in interface MaterialComponent
      Returns:
      the discount rate (0.0 to 1.0)
    • isLeaf

      public boolean isLeaf()
      Description copied from interface: MaterialComponent
      Checks if this component is a leaf (individual material).
      Specified by:
      isLeaf in interface MaterialComponent
      Returns:
      true if this is a leaf component
    • getMaterial

      public Material getMaterial()
      Gets the wrapped material.
      Returns:
      the underlying material
    • getId

      public String getId()
      Gets the material ID.
      Returns:
      the material ID
    • getType

      public Material.MaterialType getType()
      Gets the material type.
      Returns:
      the material type
    • getCreator

      public String getCreator()
      Gets the material creator.
      Returns:
      the material creator
    • getYear

      public int getYear()
      Gets the material year.
      Returns:
      the material year
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object