Class MaterialLeaf
java.lang.Object
com.university.bookstore.composite.MaterialLeaf
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionMaterialLeaf(Material material) Creates a new material leaf wrapping the specified material. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the material creator.Gets a description of this component.doubleGets the discounted price of this component.doubleGets the discount rate applied to this component.getId()Gets the material ID.intGets the total number of items in this component.Gets the wrapped material.Gets all materials contained in this component.doublegetPrice()Gets the total price of this component.getTitle()Gets the title of this component.getType()Gets the material type.intgetYear()Gets the material year.inthashCode()booleanisLeaf()Checks if this component is a leaf (individual material).toString()Methods inherited from interface com.university.bookstore.composite.MaterialComponent
isComposite
-
Constructor Details
-
MaterialLeaf
Creates a new material leaf wrapping the specified material.- Parameters:
material- the material to wrap- Throws:
IllegalArgumentException- if material is null
-
-
Method Details
-
getTitle
Description copied from interface:MaterialComponentGets the title of this component. For individual materials, this is the material title. For bundles, this is the bundle name.- Specified by:
getTitlein interfaceMaterialComponent- Returns:
- the component title
-
getPrice
public double getPrice()Description copied from interface:MaterialComponentGets 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:
getPricein interfaceMaterialComponent- Returns:
- the total price
-
getDiscountedPrice
public double getDiscountedPrice()Description copied from interface:MaterialComponentGets 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:
getDiscountedPricein interfaceMaterialComponent- Returns:
- the discounted price
-
getDescription
Description copied from interface:MaterialComponentGets a description of this component. Provides detailed information about the component and its contents.- Specified by:
getDescriptionin interfaceMaterialComponent- Returns:
- the component description
-
getMaterials
Description copied from interface:MaterialComponentGets 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:
getMaterialsin interfaceMaterialComponent- Returns:
- list of all contained materials
-
getItemCount
public int getItemCount()Description copied from interface:MaterialComponentGets the total number of items in this component. For individual materials, returns 1. For bundles, returns the sum of all contained items.- Specified by:
getItemCountin interfaceMaterialComponent- Returns:
- the total item count
-
getDiscountRate
public double getDiscountRate()Description copied from interface:MaterialComponentGets the discount rate applied to this component.- Specified by:
getDiscountRatein interfaceMaterialComponent- Returns:
- the discount rate (0.0 to 1.0)
-
isLeaf
public boolean isLeaf()Description copied from interface:MaterialComponentChecks if this component is a leaf (individual material).- Specified by:
isLeafin interfaceMaterialComponent- Returns:
- true if this is a leaf component
-
getMaterial
-
getId
-
getType
-
getCreator
-
getYear
public int getYear()Gets the material year.- Returns:
- the material year
-
equals
-
hashCode
-
toString
-