Class PriceRangeIterator
java.lang.Object
com.university.bookstore.iterator.PriceRangeIterator
- All Implemented Interfaces:
MaterialIterator
Iterator that filters materials by price range.
Only returns materials within the specified price range.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
ConstructorsConstructorDescriptionPriceRangeIterator(List<Material> materials, double minPrice, double maxPrice) Creates a new price range iterator. -
Method Summary
Modifier and TypeMethodDescriptionintGets the current position in the iteration.doubleGets the maximum price.doubleGets the minimum price.doubleGets the price range.intGets the number of materials remaining to be iterated.intGets the total number of materials that can be iterated.booleanhasNext()Checks if there are more materials to iterate over.booleanChecks if the iterator is at the beginning.booleanisAtEnd()Checks if the iterator is at the end.next()Gets the next material in the iteration.voidreset()Resets the iterator to the beginning.toString()
-
Constructor Details
-
PriceRangeIterator
Creates a new price range iterator.- Parameters:
materials- the list of materials to iterate overminPrice- the minimum price (inclusive)maxPrice- the maximum price (inclusive)- Throws:
IllegalArgumentException- if price range is invalid
-
-
Method Details
-
hasNext
public boolean hasNext()Description copied from interface:MaterialIteratorChecks if there are more materials to iterate over.- Specified by:
hasNextin interfaceMaterialIterator- Returns:
- true if there are more materials
-
next
Description copied from interface:MaterialIteratorGets the next material in the iteration.- Specified by:
nextin interfaceMaterialIterator- Returns:
- the next material
-
reset
public void reset()Description copied from interface:MaterialIteratorResets the iterator to the beginning.- Specified by:
resetin interfaceMaterialIterator
-
getCurrentPosition
public int getCurrentPosition()Description copied from interface:MaterialIteratorGets the current position in the iteration.- Specified by:
getCurrentPositionin interfaceMaterialIterator- Returns:
- the current position (0-based)
-
getTotalCount
public int getTotalCount()Description copied from interface:MaterialIteratorGets the total number of materials that can be iterated.- Specified by:
getTotalCountin interfaceMaterialIterator- Returns:
- the total count
-
getRemainingCount
public int getRemainingCount()Description copied from interface:MaterialIteratorGets the number of materials remaining to be iterated.- Specified by:
getRemainingCountin interfaceMaterialIterator- Returns:
- the remaining count
-
isAtBeginning
public boolean isAtBeginning()Description copied from interface:MaterialIteratorChecks if the iterator is at the beginning.- Specified by:
isAtBeginningin interfaceMaterialIterator- Returns:
- true if at the beginning
-
isAtEnd
public boolean isAtEnd()Description copied from interface:MaterialIteratorChecks if the iterator is at the end.- Specified by:
isAtEndin interfaceMaterialIterator- Returns:
- true if at the end
-
getMinPrice
public double getMinPrice()Gets the minimum price.- Returns:
- the minimum price
-
getMaxPrice
public double getMaxPrice()Gets the maximum price.- Returns:
- the maximum price
-
getPriceRange
public double getPriceRange()Gets the price range.- Returns:
- the price range
-
toString
-