Class MaterialIteratorFactory
java.lang.Object
com.university.bookstore.iterator.MaterialIteratorFactory
Factory for creating different types of material iterators.
Provides a centralized way to create iterators with different traversal strategies.
This factory demonstrates the Factory pattern by providing methods to create various types of iterators without exposing the concrete iterator classes.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanallMatch(MaterialIterator iterator, Predicate<Material> predicate) Checks if all materials match a predicate.booleananyMatch(MaterialIterator iterator, Predicate<Material> predicate) Checks if any material matches a predicate.collectAll(MaterialIterator iterator) Collects all materials from an iterator into a list.intcount(MaterialIterator iterator, Predicate<Material> predicate) Counts materials matching a predicate.createAudioBookIterator(List<Material> materials) Creates an audio book iterator.createBookIterator(List<Material> materials) Creates a book iterator.createCheapIterator(List<Material> materials, double threshold) Creates a cheap materials iterator.createEBookIterator(List<Material> materials) Creates an e-book iterator.createExpensiveIterator(List<Material> materials, double threshold) Creates an expensive materials iterator.createMagazineIterator(List<Material> materials) Creates a magazine iterator.createPriceRangeIterator(List<Material> materials, double minPrice, double maxPrice) Creates a price range iterator.createPriceSortedIterator(List<Material> materials, boolean ascending) Creates a price-sorted iterator.createTypeIterator(List<Material> materials, Material.MaterialType type) Creates a type-filtering iterator.createVideoIterator(List<Material> materials) Creates a video iterator.findAll(MaterialIterator iterator, Predicate<Material> predicate) Finds all materials matching a predicate.findFirst(MaterialIterator iterator, Predicate<Material> predicate) Finds the first material matching a predicate.intgetRemainingCount(MaterialIterator iterator) Gets the remaining count of materials in an iterator.intgetTotalCount(MaterialIterator iterator) Gets the total count of materials in an iterator.toString()
-
Constructor Details
-
MaterialIteratorFactory
public MaterialIteratorFactory()
-
-
Method Details
-
createTypeIterator
Creates a type-filtering iterator.- Parameters:
materials- the list of materials to iterate overtype- the material type to filter for- Returns:
- iterator for materials of the specified type
-
createPriceSortedIterator
Creates a price-sorted iterator.- Parameters:
materials- the list of materials to iterate overascending- true for ascending order, false for descending- Returns:
- iterator for materials sorted by price
-
createPriceRangeIterator
public MaterialIterator createPriceRangeIterator(List<Material> materials, double minPrice, double maxPrice) Creates a price range iterator.- Parameters:
materials- the list of materials to iterate overminPrice- the minimum price (inclusive)maxPrice- the maximum price (inclusive)- Returns:
- iterator for materials within the price range
-
createEBookIterator
Creates an e-book iterator.- Parameters:
materials- the list of materials to iterate over- Returns:
- iterator for e-books only
-
createExpensiveIterator
Creates an expensive materials iterator.- Parameters:
materials- the list of materials to iterate overthreshold- the minimum price threshold- Returns:
- iterator for materials above the price threshold
-
createCheapIterator
Creates a cheap materials iterator.- Parameters:
materials- the list of materials to iterate overthreshold- the maximum price threshold- Returns:
- iterator for materials below the price threshold
-
createBookIterator
Creates a book iterator.- Parameters:
materials- the list of materials to iterate over- Returns:
- iterator for books only
-
createMagazineIterator
Creates a magazine iterator.- Parameters:
materials- the list of materials to iterate over- Returns:
- iterator for magazines only
-
createAudioBookIterator
Creates an audio book iterator.- Parameters:
materials- the list of materials to iterate over- Returns:
- iterator for audio books only
-
createVideoIterator
Creates a video iterator.- Parameters:
materials- the list of materials to iterate over- Returns:
- iterator for videos only
-
collectAll
Collects all materials from an iterator into a list.- Parameters:
iterator- the iterator to collect from- Returns:
- list of all materials from the iterator
-
findFirst
Finds the first material matching a predicate.- Parameters:
iterator- the iterator to searchpredicate- the predicate to test- Returns:
- Optional containing the first matching material
-
findAll
Finds all materials matching a predicate.- Parameters:
iterator- the iterator to searchpredicate- the predicate to test- Returns:
- list of all matching materials
-
count
Counts materials matching a predicate.- Parameters:
iterator- the iterator to countpredicate- the predicate to test- Returns:
- the count of matching materials
-
anyMatch
Checks if any material matches a predicate.- Parameters:
iterator- the iterator to checkpredicate- the predicate to test- Returns:
- true if any material matches
-
allMatch
Checks if all materials match a predicate.- Parameters:
iterator- the iterator to checkpredicate- the predicate to test- Returns:
- true if all materials match
-
getTotalCount
Gets the total count of materials in an iterator.- Parameters:
iterator- the iterator to count- Returns:
- the total count
-
getRemainingCount
Gets the remaining count of materials in an iterator.- Parameters:
iterator- the iterator to check- Returns:
- the remaining count
-
toString
-