fin tp3
This commit is contained in:
32
DEV3.2/TP03/03_Tableau/Iterateur.java
Normal file
32
DEV3.2/TP03/03_Tableau/Iterateur.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class Iterateur<T> implements Iterator<T> {
|
||||
|
||||
private CouleurList<T> liste;
|
||||
private int indice;
|
||||
|
||||
public Iterateur(CouleurList liste) {
|
||||
this.liste = liste;
|
||||
this.indice = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.indice < 10 && this.liste.valeurs[indice] != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (!hasNext()) {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
return this.liste.valeurs[this.indice++];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user