Class PriceSortedIterator
java.lang.Object
com.university.bookstore.iterator.PriceSortedIterator
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionPriceSortedIterator(List<Material> materials, boolean ascending) Creates a new price sorted iterator. -
Method Summary
Modifier and TypeMethodDescriptionintGets the current position in the iteration.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.booleanGets the sort order.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.peek()Gets the current material without advancing the iterator.peekNext()Gets the next material without advancing the iterator.voidreset()Resets the iterator to the beginning.toString()
-
Constructor Details
-
PriceSortedIterator
-
-
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
-
isAscending
public boolean isAscending()Gets the sort order.- Returns:
- true if ascending, false if descending
-
peek
Gets the current material without advancing the iterator.- Returns:
- the current material
- Throws:
NoSuchElementException- if at the end
-
peekNext
Gets the next material without advancing the iterator.- Returns:
- the next material
- Throws:
NoSuchElementException- if no next element
-
toString
-