# 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 Summary

  Constructors
  Constructor
  Description
  `MaterialLeaf(Material material)`
  Creates a new material leaf wrapping the specified material.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `String`
  `getCreator()`
  Gets the material creator.
  `String`
  `getDescription()`
  Gets a description of this component.
  `double`
  `getDiscountedPrice()`
  Gets the discounted price of this component.
  `double`
  `getDiscountRate()`
  Gets the discount rate applied to this component.
  `String`
  `getId()`
  Gets the material ID.
  `int`
  `getItemCount()`
  Gets the total number of items in this component.
  `Material`
  `getMaterial()`
  Gets the wrapped material.
  `List<Material>`
  `getMaterials()`
  Gets all materials contained in this component.
  `double`
  `getPrice()`
  Gets the total price of this component.
  `String`
  `getTitle()`
  Gets the title of this component.
  `Material.MaterialType`
  `getType()`
  Gets the material type.
  `int`
  `getYear()`
  Gets the material year.
  `int`
  `hashCode()`
  `boolean`
  `isLeaf()`
  Checks if this component is a leaf (individual material).
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface com.university.bookstore.composite.MaterialComponent

  `isComposite`

- ## 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`