Class MaterialTypeIterator

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

public class MaterialTypeIterator extends Object implements MaterialIterator
Iterator that filters materials by type. Only returns materials of the specified type.
Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • MaterialTypeIterator

      public MaterialTypeIterator(List<Material> materials, Material.MaterialType targetType)
      Creates a new material type iterator.
      Parameters:
      materials - the list of materials to iterate over
      targetType - the type of materials to filter for
  • 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
    • getTargetType

      public Material.MaterialType getTargetType()
      Gets the target type this iterator filters for.
      Returns:
      the target material type
    • toString

      public String toString()
      Overrides:
      toString in class Object