MCPcopy Create free account
hub / github.com/Anchals24/Low-Level-Design / BookIterator

Class BookIterator

IteratorDesignPattern/BookIterator.java:5–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.util.List;
4
5public class BookIterator implements Iterator{
6 private List<Book> books;
7 private int index = 0;
8
9 public BookIterator(List<Book> books){
10 this.books = books;
11 }
12
13
14 @Override
15 public boolean hasNext() {
16 return index < books.size();
17 }
18
19 @Override
20 public Object next() {
21 if (this.hasNext()){
22 return books.get(index++);
23 }
24 return null;
25 }
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected