spiny94

Untitled

Sep 6th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. package ticketing;
  2.  
  3. import java.util.Collection;
  4. import java.util.Collections;
  5. import java.util.Comparator;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.TreeMap;
  9.  
  10. public class Tracker {
  11.     private String url;
  12.     private TreeMap<String,Utente> utenti = new TreeMap<String,Utente>();
  13.     private TreeMap<String,Prodotto> prodotti = new TreeMap<String,Prodotto>();
  14.     private TreeMap<Long,Ticket> tickets = new TreeMap<Long,Ticket>();
  15.     private long idProd = 1;
  16.     private long idTk = 1;
  17.  
  18.     public Tracker(String url){
  19.         this.url = url;
  20.        
  21.     }
  22.    
  23.     public String getURL(){
  24.         return url;
  25.     }
  26.    
  27.     public void nuovoUtente(String nick, String nome, String email, String pwd) throws InvalidInformationException {
  28.         if(nick==null || email==null || pwd==null){
  29.              throw new InvalidInformationException();
  30.         }
  31.         Utente u = new Utente(nick,nome,email,pwd);
  32.         utenti.put(nick, u);
  33.     }
  34.    
  35.     public Utente getUtente(String nick){
  36.         return utenti.get(nick);
  37.     }
  38.    
  39.     public Collection<Utente> getUtenti(){
  40.         return utenti.values();
  41.     }
  42.    
  43.    
  44.     public String nuovoProdotto(String nome, String descrizione) throws InvalidInformationException {
  45.         if(nome==null || descrizione==null){
  46.             throw new InvalidInformationException();
  47.        }
  48.         String id = "P" + idProd++;
  49.         Prodotto p = new Prodotto(id,nome,descrizione);
  50.         prodotti.put(id,p);
  51.         return id;
  52.     }
  53.    
  54.     public Prodotto getProdotto(String code){
  55.         return prodotti.get(code);
  56.     }
  57.  
  58.     public Collection<Prodotto> getProdotti(){
  59.         return prodotti.values();
  60.     }
  61.    
  62.     public Ticket nuovoTicket(String code, String nick, String label){
  63.         Prodotto p = prodotti.get(code);
  64.         Utente u = utenti.get(nick);
  65.         Ticket tk = new Ticket(this,idTk++,p,u,label);
  66.         tickets.put(tk.getCodice(), tk);
  67.         p.addTicket(tk);
  68.         u.addTicket();
  69.         return tk;
  70.     }
  71.    
  72.     public Ticket getTicket(long code){
  73.         return tickets.get(code);
  74.     }
  75.    
  76.     public List<Ticket> getTickets(){
  77.         LinkedList<Ticket> res = new LinkedList<Ticket>(tickets.values());
  78.         Collections.sort(res);
  79.         return res;
  80.     }
  81.    
  82.     public List<Prodotto> prodottiPerTicket(){
  83.         LinkedList<Prodotto> risultato=new LinkedList<Prodotto>(prodotti.values());
  84.         Collections.sort(risultato,new Comparator<Prodotto>(){
  85.             public int compare(Prodotto a, Prodotto b){
  86.                 return (int)(b.numeroTicket()-a.numeroTicket());
  87.             }
  88.         });
  89.         return risultato;
  90.     }
  91.    
  92.    
  93.    
  94.     public List<Utente> utentiPerTicket(){
  95.         LinkedList<Utente> risultato=new LinkedList<Utente>(utenti.values());
  96.         Collections.sort(risultato,new Comparator<Utente>(){
  97.             public int compare(Utente a, Utente b){
  98.                 return (int)(b.numeroTicket()-a.numeroTicket());
  99.             }
  100.         });
  101.         return risultato;
  102.     }
  103.  
  104.    
  105. }
Advertisement
Add Comment
Please, Sign In to add comment