spiny94

Untitled

Sep 5th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.84 KB | None | 0 0
  1. package abbigliamento;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. public class Abbigliamento {
  12.     Collezione collezione;
  13.     Map<String,Modello> modelli = new HashMap<String, Modello>();
  14.     Map<String,Colore> colori = new HashMap<String, Colore>();
  15.     Map<String,Materiale> materiali = new HashMap<String, Materiale>();
  16.     Map<String,Capo> capi = new HashMap<String, Capo>();
  17.    
  18.     public Abbigliamento(Collezione c){
  19.         collezione = c;
  20.     }
  21.    
  22.     public void leggiFile(String fileName){
  23.         try {
  24.             File name = new File(fileName);
  25.             BufferedReader reader = new BufferedReader(new FileReader(name));
  26.            
  27.             String line=reader.readLine();
  28.             while(line!=null){
  29.                 String[] tok = line.split(";");
  30.                 String type = tok[0];
  31.                 line=reader.readLine();
  32.                
  33.                 if(type.equals("MOD")){
  34.                     String nome = tok[1];
  35.                     double cf = Double.parseDouble(tok[2]);
  36.                     double q = Double.parseDouble(tok[3]);
  37.                     modelli.put(nome,new Modello(nome,cf,q));
  38.                 }
  39.                 if(type.equals("COL")){
  40.                     String nome = tok[1];
  41.                     colori.put(nome,new Colore(nome));
  42.                 }
  43.                 if(type.equals("MAT")){
  44.                     String nome = tok[1];
  45.                     double c = Double.parseDouble(tok[2]);
  46.                     materiali.put(nome,new Materiale(nome,c));
  47.                 }
  48.                 if(type.equals("CAP")){
  49.                     String nome = tok[1];
  50.                     String mod = tok[2];
  51.                     String mat = tok[3];
  52.                     String col = tok[4];
  53.                     Modello modello = getModello(mod);
  54.                     Materiale materiale = getMateriale(mat);
  55.                     Colore colore = getColore(col);
  56.                     capi.put(nome,new Capo(modello,materiale,colore));
  57.                 }
  58.                 if(type.equals("COLL")){
  59.                     for(int i=1; i<tok.length; i++) {
  60.                         Capo c = capi.get(tok[i]);
  61.                         collezione.add(c);
  62.                     }
  63.                 }
  64.                
  65.             }
  66. //          System.out.println("Modelli: "+modelli);
  67. //          System.out.println("Colori: "+colori);
  68. //          System.out.println("Materiali: "+materiali);
  69. //          System.out.println("Capi: "+capi);
  70. //          System.out.println("Collezione: "+collezione.getCollezione());
  71.             reader.close();
  72.         } catch (FileNotFoundException e) {
  73.             e.printStackTrace();
  74.         } catch (IOException e) {
  75.             // TODO Auto-generated catch block
  76.             e.printStackTrace();
  77.         }
  78.     }
  79.  
  80.     public Modello getModello(String name){
  81.         return modelli.get(name);
  82.     }
  83.  
  84.     public Colore getColore(String name){
  85.         return colori.get(name);
  86.     }
  87.  
  88.     public Materiale getMateriale(String name){
  89.         return materiali.get(name);
  90.     }
  91.  
  92.     public Capo getCapo(String name){
  93.         return capi.get(name);
  94.     }
  95.  
  96.     public Collezione getCollezione(){
  97.         return collezione;
  98.     }
  99.  
  100. }
  101. package abbigliamento;
  102.  
  103. import java.util.Collection;
  104. import java.util.Iterator;
  105. import java.util.LinkedList;
  106.  
  107. public class Collezione {
  108.  
  109.     private Collection<Capo> capi = new LinkedList<Capo>();
  110.    
  111.     public void add(Capo capo) {
  112.         capi.add(capo);
  113.     }
  114.  
  115.     public Collection<Capo> trova(Colore colore) {
  116.         LinkedList<Capo> richiesti = new LinkedList<Capo>();
  117.         for (Iterator<Capo> iter = capi.iterator(); iter.hasNext();) {
  118.             Capo capo = iter.next();
  119.             if(capo.colore.getNome().equals(colore.getNome())){
  120.                 richiesti.add(capo);
  121.             }
  122.         }
  123.         return richiesti;
  124.     }
  125.  
  126.     public Collection<Capo> trova(Materiale materiale) {
  127.         LinkedList<Capo> richiesti = new LinkedList<Capo>();
  128.         for (Iterator<Capo> iter = capi.iterator(); iter.hasNext();) {
  129.             Capo capo = iter.next();
  130.             if(capo.materiale == materiale){
  131.                 richiesti.add(capo);
  132.             }
  133.         }
  134.         return richiesti;
  135.     }
  136.  
  137.     public Collection<Capo> trova(Modello modello) {
  138.         LinkedList<Capo> richiesti = new LinkedList<Capo>();
  139.         for (Iterator<Capo> iter = capi.iterator(); iter.hasNext();) {
  140.             Capo capo = iter.next();
  141.             if(capo.modello == modello){
  142.                 richiesti.add(capo);
  143.             }
  144.         }
  145.         return richiesti;
  146.     }
  147.    
  148.     public Collection<Capo> getCollezione(){
  149.         return capi;
  150.     }
  151.     }
Advertisement
Add Comment
Please, Sign In to add comment