Class PriceRangeIterator

java.lang.Object
com.university.bookstore.iterator.PriceRangeIterator
All Implemented Interfaces:
MaterialIterator

public class PriceRangeIterator extends Object implements 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 Details

    • PriceRangeIterator

      public PriceRangeIterator(List<Material> materials, double minPrice, double maxPrice)
      Creates a new price range iterator.
      Parameters:
      materials - the list of materials to iterate over
      minPrice - 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: MaterialIterator
      Checks if there are more materials to iterate over.
      Specified by:
      hasNext in interface MaterialIterator
      Returns:
      true if there are more materials
    • next

      public Material next()
      Description copied from interface: MaterialIterator
      Gets the next material in the iteration.
      Specified by:
      next in interface MaterialIterator
      Returns:
      the next material
    • reset

      public void reset()
      Description copied from interface: MaterialIterator
      Resets the iterator to the beginning.
      Specified by:
      reset in interface MaterialIterator
    • getCurrentPosition

      public int getCurrentPosition()
      Description copied from interface: MaterialIterator
      Gets the current position in the iteration.
      Specified by:
      getCurrentPosition in interface MaterialIterator
      Returns:
      the current position (0-based)
    • getTotalCount

      public int getTotalCount()
      Description copied from interface: MaterialIterator
      Gets the total number of materials that can be iterated.
      Specified by:
      getTotalCount in interface MaterialIterator
      Returns:
      the total count
    • getRemainingCount

      public int getRemainingCount()
      Description copied from interface: MaterialIterator
      Gets the number of materials remaining to be iterated.
      Specified by:
      getRemainingCount in interface MaterialIterator
      Returns:
      the remaining count
    • isAtBeginning

      public boolean isAtBeginning()
      Description copied from interface: MaterialIterator
      Checks if the iterator is at the beginning.
      Specified by:
      isAtBeginning in interface MaterialIterator
      Returns:
      true if at the beginning
    • isAtEnd

      public boolean isAtEnd()
      Description copied from interface: MaterialIterator
      Checks if the iterator is at the end.
      Specified by:
      isAtEnd in interface MaterialIterator
      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

      public String toString()
      Overrides:
      toString in class Object