Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package correcteur;
  2.  
  3.  
  4. import correcteur.exceptions.*;
  5.  
  6. import java.util.Collections;
  7. import java.util.Iterator;
  8. import java.util.LinkedList;
  9.  
  10.  
  11. /**
  12. * Implémentation d'un dico en utilisant une liste chainée.
  13. * @author Arnaud Lanoix
  14. * @version 7/10/2018
  15. */
  16. public class DicoList implements Dico{
  17.  
  18. LinkedList<String> liste;
  19.  
  20. public DicoList() {
  21. this.liste = new LinkedList<String>();
  22. }
  23.  
  24.  
  25. @Override
  26. public boolean dicoVide() {
  27. return liste.isEmpty();
  28. }
  29.  
  30. @Override
  31. public boolean appartient(String mot) {
  32. return liste.contains(mot);
  33. }
  34.  
  35. @Override
  36. public void ajoutMot(String mot) throws MotDejaPresentException {
  37. if(!liste.contains(mot)) {
  38. liste.add(mot);
  39. Collections.sort(liste);
  40. } else throw new MotDejaPresentException();
  41. }
  42.  
  43. @Override
  44. public int nbMots() {
  45. return liste.size();
  46. }
  47.  
  48. @Override
  49. public String premierMot() throws DicoVideException {
  50. if(!liste.isEmpty()) {
  51. return liste.getFirst();
  52. }else throw new DicoVideException();
  53. }
  54.  
  55. @Override
  56. public String dernierMot() throws DicoVideException {
  57. if(!liste.isEmpty()) {
  58. return liste.getLast();
  59. } else throw new DicoVideException();
  60. }
  61.  
  62. @Override
  63. public String motSuivant(String mot) throws DernierMotRechercheException, MotNonPresentException {
  64. if(liste.contains(mot)) {
  65. if(!liste.getLast().equals(mot)) {
  66. return liste.get(liste.indexOf(mot)+1);
  67. }else throw new DernierMotRechercheException();
  68. }else throw new MotNonPresentException();
  69. }
  70.  
  71. @Override
  72. public void suppressionMot(String mot) throws MotNonPresentException {
  73. if(liste.contains(mot)) {
  74. liste.remove(mot);
  75. } else throw new MotNonPresentException();
  76. }
  77.  
  78. @Override
  79. public Iterator<String> iterator() {
  80. return liste.iterator();
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement