SHARE
TWEET

Untitled

a guest Oct 15th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import exceptions.DernierMotRechercheException;
  2. import exceptions.DicoVideException;
  3. import exceptions.MotDejaPresentException;
  4. import exceptions.MotNonPresentException;
  5.  
  6. import java.util.Iterator;
  7. import java.util.SortedSet;
  8. import java.util.TreeSet;
  9.  
  10. /**
  11.  * Impl√©mentation d'un dictionnaire en utilisant une ensemble ordonn√©.
  12.  */
  13.  
  14. public class DicoTreeSet implements iDico {
  15.  
  16.     private TreeSet<String> set;
  17.  
  18.     public DicoTreeSet() {
  19.         set = new TreeSet<>();
  20.     }
  21.  
  22.     @Override
  23.     public boolean dicoVide() {
  24.         return set.isEmpty();
  25.     }
  26.  
  27.     @Override
  28.     public boolean appartient(String mot) {
  29.         return set.contains(mot);
  30.     }
  31.  
  32.     @Override
  33.     public void ajoutMot(String mot) throws MotDejaPresentException {
  34.         if (appartient(mot))
  35.             throw new MotDejaPresentException();
  36.         set.add(mot);
  37.     }
  38.  
  39.     @Override
  40.     public int nbMots() {
  41.         return set.size();
  42.     }
  43.  
  44.     @Override
  45.     public String premierMot() throws DicoVideException {
  46.         if(dicoVide())
  47.             throw new DicoVideException();
  48.         return set.first();
  49.     }
  50.  
  51.     @Override
  52.     public String dernierMot() throws DicoVideException {
  53.         if(dicoVide())
  54.             throw new DicoVideException();
  55.         return set.last();
  56.     }
  57.  
  58.     @Override
  59.     public String motSuivant(String mot) throws DernierMotRechercheException, MotNonPresentException {
  60.         if (!appartient(mot))
  61.             throw new MotNonPresentException();
  62.         if (set.higher(mot)==null)
  63.             throw new DernierMotRechercheException();
  64.  
  65.         return set.higher(mot);
  66.     }
  67.  
  68.     @Override
  69.     public void suppressionMot(String mot) throws MotNonPresentException {
  70.         if (!appartient(mot))
  71.             throw new MotNonPresentException();
  72.         set.remove(mot);
  73.     }
  74.  
  75.     @Override
  76.     public Iterator<String> iterator() {
  77.         return set.iterator();
  78.     }
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top