class RadioStation {
constructor(private frequency: number) {}
getFrequency(): number {
return this.frequency;
}
}
interface Iterator<T> {
first(): T | null;
next(): T | null;
isDone(): boolean;
currentItem(): T | null;
}
class RadioStationIterator implements Iterator<RadioStation> {
private counter = 0;
constructor(private stations: RadioStation[]) {}
currentItem(): RadioStation | null {
return this.isDone() ? null : this.stations[this.counter];
}
first(): RadioStation | null {
this.counter = 0;
return this.currentItem();
}
next(): RadioStation | null {
this.counter += 1;
return this.currentItem();
}
isDone(): boolean {
return this.counter >= this.stations.length;
}
}