Class PriceSortedIterator

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

public class PriceSortedIterator extends Object implements MaterialIterator
Iterator that returns materials sorted by price. Can sort in ascending or descending order.
Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • PriceSortedIterator

      public PriceSortedIterator(List<Material> materials, boolean ascending)
      Creates a new price sorted iterator.
      Parameters:
      materials - the list of materials to iterate over
      ascending - true for ascending order, false for descending
  • 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
    • isAscending

      public boolean isAscending()
      Gets the sort order.
      Returns:
      true if ascending, false if descending
    • peek

      public Material peek()
      Gets the current material without advancing the iterator.
      Returns:
      the current material
      Throws:
      NoSuchElementException - if at the end
    • peekNext

      public Material peekNext()
      Gets the next material without advancing the iterator.
      Returns:
      the next material
      Throws:
      NoSuchElementException - if no next element
    • toString

      public String toString()
      Overrides:
      toString in class Object