01 package fr.isae.lists;
02
03 import java.util.Iterator;
04
05 /**
06 * <code>IterateurListe</code> est un iterateur pour une liste
07 * realisant <code>java.util.Iterable</code>.
08 *
09 * @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
10 * @version 1.0
11 */
12 public class ListeIterator implements Iterator<Double> {
13
14 private Liste liste;
15 private int index;
16
17 /**
18 * Creer un iterateur sur une liste.
19 *
20 * @param liste la liste a parcourir
21 */
22 public ListeIterator(Liste liste) {
23 this.liste = liste;
24 this.index = -1;
25 }
26
27 @Override public boolean hasNext() {
28 if (this.liste.getNbElements() == 0) {
29 return false;
30 }
31
32 return (this.index + 1 < this.liste.getNbElements());
33 }
34
35 @Override public Double next() {
36 this.index++;
37 return this.liste.getElement(this.index);
38 }
39
40 @Override public void remove() {
41 if (this.index != -1) {
42 this.liste.supprimer(this.index);
43 }
44 }
45 }
|