Class MaterialTypeIterator
java.lang.Object
com.university.bookstore.iterator.MaterialTypeIterator
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionMaterialTypeIterator(List<Material> materials, Material.MaterialType targetType) Creates a new material type iterator. -
Method Summary
Modifier and TypeMethodDescriptionintGets the current position in the iteration.intGets the number of materials remaining to be iterated.Gets the target type this iterator filters for.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
-
MaterialTypeIterator
Creates a new material type iterator.- Parameters:
materials- the list of materials to iterate overtargetType- the type of materials to filter for
-
-
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
-
getTargetType
Gets the target type this iterator filters for.- Returns:
- the target material type
-
toString
-