Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package correcteur;
- import correcteur.exceptions.*;
- import java.util.Collections;
- import java.util.Iterator;
- import java.util.LinkedList;
- /**
- * Implémentation d'un dico en utilisant une liste chainée.
- * @author Arnaud Lanoix
- * @version 7/10/2018
- */
- public class DicoList implements Dico{
- LinkedList<String> liste;
- public DicoList() {
- this.liste = new LinkedList<String>();
- }
- @Override
- public boolean dicoVide() {
- return liste.isEmpty();
- }
- @Override
- public boolean appartient(String mot) {
- return liste.contains(mot);
- }
- @Override
- public void ajoutMot(String mot) throws MotDejaPresentException {
- if(!liste.contains(mot)) {
- liste.add(mot);
- Collections.sort(liste);
- } else throw new MotDejaPresentException();
- }
- @Override
- public int nbMots() {
- return liste.size();
- }
- @Override
- public String premierMot() throws DicoVideException {
- if(!liste.isEmpty()) {
- return liste.getFirst();
- }else throw new DicoVideException();
- }
- @Override
- public String dernierMot() throws DicoVideException {
- if(!liste.isEmpty()) {
- return liste.getLast();
- } else throw new DicoVideException();
- }
- @Override
- public String motSuivant(String mot) throws DernierMotRechercheException, MotNonPresentException {
- if(liste.contains(mot)) {
- if(!liste.getLast().equals(mot)) {
- return liste.get(liste.indexOf(mot)+1);
- }else throw new DernierMotRechercheException();
- }else throw new MotNonPresentException();
- }
- @Override
- public void suppressionMot(String mot) throws MotNonPresentException {
- if(liste.contains(mot)) {
- liste.remove(mot);
- } else throw new MotNonPresentException();
- }
- @Override
- public Iterator<String> iterator() {
- return liste.iterator();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement