Class EBookBuilder
java.lang.Object
com.university.bookstore.builder.EBookBuilder
- All Implemented Interfaces:
MaterialBuilder<EBook>
Builder for creating EBook instances with a fluent interface.
Demonstrates the Builder pattern for complex object construction.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns the material instance.Sets DRM enabled to false.Sets DRM enabled to true.Gets the current author.Gets the current file format.doubleGets the current file size.getId()Gets the current ID.doublegetPrice()Gets the current price.Gets the current quality.getTitle()Gets the current title.intGets the current word count.intgetYear()Gets the current year.booleanGets the current DRM enabled status.voidreset()Resets the builder to its initial state.Sets the eBook author.setDrmEnabled(boolean drmEnabled) Sets the DRM enabled status.setFileFormat(String fileFormat) Sets the eBook file format.setFileSize(double fileSize) Sets the eBook file size.Sets the quality to high.Sets the eBook ID.Sets the quality to low.setPrice(double price) Sets the eBook price.setQuality(Media.MediaQuality quality) Sets the eBook quality.Sets the eBook title.setWordCount(int wordCount) Sets the eBook word count.setYear(int year) Sets the eBook publication year.toString()voidvalidate()Validates that all required fields are set.
-
Constructor Details
-
EBookBuilder
public EBookBuilder()
-
-
Method Details
-
setId
Sets the eBook ID.- Parameters:
id- the eBook ID- Returns:
- this builder for method chaining
-
setTitle
Sets the eBook title.- Parameters:
title- the eBook title- Returns:
- this builder for method chaining
-
setAuthor
Sets the eBook author.- Parameters:
author- the eBook author- Returns:
- this builder for method chaining
-
setPrice
Sets the eBook price.- Parameters:
price- the eBook price- Returns:
- this builder for method chaining
-
setYear
Sets the eBook publication year.- Parameters:
year- the publication year- Returns:
- this builder for method chaining
-
setFileFormat
Sets the eBook file format.- Parameters:
fileFormat- the file format (e.g., "EPUB", "PDF", "MOBI")- Returns:
- this builder for method chaining
-
setFileSize
Sets the eBook file size.- Parameters:
fileSize- the file size in MB- Returns:
- this builder for method chaining
-
setDrmEnabled
Sets the DRM enabled status.- Parameters:
drmEnabled- true if DRM is enabled- Returns:
- this builder for method chaining
-
setWordCount
Sets the eBook word count.- Parameters:
wordCount- the word count- Returns:
- this builder for method chaining
-
setQuality
Sets the eBook quality.- Parameters:
quality- the media quality- Returns:
- this builder for method chaining
-
enableDRM
-
disableDRM
Sets DRM enabled to false.- Returns:
- this builder for method chaining
-
setHighQuality
Sets the quality to high.- Returns:
- this builder for method chaining
-
setLowQuality
Sets the quality to low.- Returns:
- this builder for method chaining
-
build
Description copied from interface:MaterialBuilderBuilds and returns the material instance.- Specified by:
buildin interfaceMaterialBuilder<EBook>- Returns:
- the built material
-
validate
public void validate()Description copied from interface:MaterialBuilderValidates that all required fields are set.- Specified by:
validatein interfaceMaterialBuilder<EBook>
-
reset
public void reset()Description copied from interface:MaterialBuilderResets the builder to its initial state.- Specified by:
resetin interfaceMaterialBuilder<EBook>
-
getId
-
getTitle
-
getAuthor
-
getPrice
public double getPrice()Gets the current price.- Returns:
- the current price
-
getYear
public int getYear()Gets the current year.- Returns:
- the current year
-
getFileFormat
-
getFileSize
public double getFileSize()Gets the current file size.- Returns:
- the current file size
-
isDrmEnabled
public boolean isDrmEnabled()Gets the current DRM enabled status.- Returns:
- the current DRM enabled status
-
getWordCount
public int getWordCount()Gets the current word count.- Returns:
- the current word count
-
getQuality
-
toString
-