maj
This commit is contained in:
32
TP4/stub/2Iterator/MonBrinIterator.java
Normal file
32
TP4/stub/2Iterator/MonBrinIterator.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
MonBrinIterator
|
||||
|
||||
gère la navigation dans un Brin d'ADN
|
||||
*/
|
||||
public class MonBrinIterator implements Iterator<Base> {
|
||||
|
||||
// maillon courant de la navigation
|
||||
private MonMaillon courant;
|
||||
|
||||
public MonBrinIterator(MonMaillon m){
|
||||
this.courant = m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext(){
|
||||
return this.courant != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Base next() {
|
||||
if (this.courant == null) {
|
||||
throw new NoSuchElementException("Plus de base dans ce brin");
|
||||
}
|
||||
Base valeur = this.courant.getBase();
|
||||
this.courant = this.courant.getSuiteMaillon();
|
||||
return valeur;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user