Class DigitalAnnotationDecorator
java.lang.Object
com.university.bookstore.model.Material
com.university.bookstore.decorator.MaterialDecorator
com.university.bookstore.decorator.DigitalAnnotationDecorator
- All Implemented Interfaces:
Comparable<Material>
Decorator that adds digital annotation functionality to materials.
Increases the price and provides annotation management capabilities.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Nested Class Summary
Nested classes/interfaces inherited from class com.university.bookstore.model.Material
Material.MaterialType -
Constructor Summary
ConstructorsConstructorDescriptionDigitalAnnotationDecorator(Material material) Creates a new digital annotation decorator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(String annotation) Adds an annotation to the material.voidClears all annotations.booleanMaterials are equal if they have the same ID.intGets the number of annotations.Gets all annotations.doubleGets the digital annotation cost.Abstract method to get a formatted display string.doublegetPrice()booleanChecks if the material has any annotations.inthashCode()removeAnnotation(int index) Removes an annotation by index.Methods inherited from class com.university.bookstore.decorator.MaterialDecorator
getBaseMaterial, getCreator, getDecoratedMaterial, getDecoratorCount, getDiscountRate, hasDecorators, toString
-
Constructor Details
-
DigitalAnnotationDecorator
Creates a new digital annotation decorator.- Parameters:
material- the material to add annotations to
-
-
Method Details
-
getPrice
-
getDisplayInfo
Description copied from class:MaterialAbstract method to get a formatted display string. Each material type should provide its own formatting.- Overrides:
getDisplayInfoin classMaterialDecorator- Returns:
- formatted display string
-
addAnnotation
Adds an annotation to the material.- Parameters:
annotation- the annotation text- Throws:
IllegalArgumentException- if annotation is null or empty
-
removeAnnotation
Removes an annotation by index.- Parameters:
index- the index of the annotation to remove- Returns:
- the removed annotation
- Throws:
IndexOutOfBoundsException- if index is invalid
-
getAnnotations
-
getAnnotationCount
public int getAnnotationCount()Gets the number of annotations.- Returns:
- the annotation count
-
clearAnnotations
public void clearAnnotations()Clears all annotations. -
getDigitalAnnotationCost
public double getDigitalAnnotationCost()Gets the digital annotation cost.- Returns:
- the annotation cost
-
hasAnnotations
public boolean hasAnnotations()Checks if the material has any annotations.- Returns:
- true if annotations exist
-
equals
Description copied from class:MaterialMaterials are equal if they have the same ID.- Overrides:
equalsin classMaterialDecorator
-
hashCode
public int hashCode()- Overrides:
hashCodein classMaterialDecorator
-