From 22d2612baaf497bffa799e5fcc4c4e38faa29a9c Mon Sep 17 00:00:00 2001 From: orange Date: Thu, 29 Dec 2016 16:56:31 +0100 Subject: [PATCH] add museo --- src/Museo/Archivio.java | 55 ++++++++++++++++++++++++++++++++++++++++ src/Museo/Libri.dat | 10 ++++++++ src/Museo/Libro.java | 35 +++++++++++++++++++++++++ src/Museo/Opera.java | 33 ++++++++++++++++++++++++ src/Museo/OperaMult.java | 40 +++++++++++++++++++++++++++++ src/Museo/OpereMult.dat | 18 +++++++++++++ src/Museo/Stampa.java | 40 +++++++++++++++++++++++++++++ src/Museo/Stampe.dat | 18 +++++++++++++ src/Museo/Test.java | 14 ++++++++++ 9 files changed, 263 insertions(+) create mode 100644 src/Museo/Archivio.java create mode 100644 src/Museo/Libri.dat create mode 100644 src/Museo/Libro.java create mode 100644 src/Museo/Opera.java create mode 100644 src/Museo/OperaMult.java create mode 100644 src/Museo/OpereMult.dat create mode 100644 src/Museo/Stampa.java create mode 100644 src/Museo/Stampe.dat create mode 100644 src/Museo/Test.java diff --git a/src/Museo/Archivio.java b/src/Museo/Archivio.java new file mode 100644 index 0000000..39138f9 --- /dev/null +++ b/src/Museo/Archivio.java @@ -0,0 +1,55 @@ +import java.util.Set; +import java.util.HashSet; +import java.util.Scanner; +import java.io.PrintStream; + +public class Archivio{ + + public Archivio(Scanner scMult, Scanner scLibri, Scanner scStampe){ + archivio=new HashSet(); + + Opera op=Libro.read(scLibri); + while(op!=null){ + archivio.add(op); + op=Libro.read(scLibri); + } + + op=OperaMult.read(scMult); + while(op!=null){ + archivio.add(op); + op=OperaMult.read(scMult); + } + + op=Stampa.read(scStampe); + while(op!=null){ + archivio.add(op); + op=Stampa.read(scStampe); + } + } + + public Archivio(Set archivio){ + this.archivio=archivio; + } + + public void print(PrintStream ps){ + for(Opera o: archivio){ + if(o instanceof Libro) + ((Libro) o).print(ps); + if(o instanceof Stampa) + ((Stampa) o).print(ps); + if(o instanceof OperaMult) + ((OperaMult) o).print(ps); + } + } + + public Archivio filtroAutore(String autore){ + Set nuovoSet = new HashSet(); + for(Opera o: archivio) + if(o.getAutore().equals(autore)) + nuovoSet.add(o); + + return new Archivio(nuovoSet); + } + + private Set archivio; +} \ No newline at end of file diff --git a/src/Museo/Libri.dat b/src/Museo/Libri.dat new file mode 100644 index 0000000..87ed2a4 --- /dev/null +++ b/src/Museo/Libri.dat @@ -0,0 +1,10 @@ +Autore3 +Titolo4 +1998 +5S +# +Autore3 +Titolo5 +1233 +5F +# diff --git a/src/Museo/Libro.java b/src/Museo/Libro.java new file mode 100644 index 0000000..31443a2 --- /dev/null +++ b/src/Museo/Libro.java @@ -0,0 +1,35 @@ +import java.util.Scanner; +import java.io.PrintStream; + +public class Libro extends Opera{ + + public Libro(String autore, String titolo, int anno, String pos){ + super(autore, titolo, anno, pos); + } + + public int hashCode(){ + return super.hashCode(); + } + + public void print(PrintStream ps){ + ps.println("L "+autore+" "+titolo+" "+anno+" "+pos+"."); + } + + public static Libro read(Scanner sc){ + String autore, titolo, pos; + int anno; + + if(!sc.hasNextLine()) return null; + autore=sc.nextLine(); + if(!sc.hasNextLine()) return null; + titolo=sc.nextLine(); + if(!sc.hasNextLine()) return null; + anno=Integer.parseInt(sc.nextLine()); + if(!sc.hasNextLine()) return null; + pos=sc.nextLine(); + if(!sc.hasNextLine()) return null; + sc.nextLine(); + + return new Libro(autore, titolo, anno, pos); + } +} \ No newline at end of file diff --git a/src/Museo/Opera.java b/src/Museo/Opera.java new file mode 100644 index 0000000..b2668e6 --- /dev/null +++ b/src/Museo/Opera.java @@ -0,0 +1,33 @@ +public class Opera{ + public Opera(String autore, String titolo, int anno, String pos){ + this.anno=anno; + this.autore=autore; + this.titolo=titolo; + this.pos=pos; + } + + public int getAnno(){ + return anno; + } + + public String getAutore(){ + return autore; + } + + public String getTitolo(){ + return titolo; + } + + public String getPos(){ + return pos; + } + + public int hashCode(){ + return autore.hashCode()*titolo.hashCode()*pos.hashCode()*anno; + } + + protected int anno; + protected String autore; + protected String titolo; + protected String pos; +} \ No newline at end of file diff --git a/src/Museo/OperaMult.java b/src/Museo/OperaMult.java new file mode 100644 index 0000000..a06cff5 --- /dev/null +++ b/src/Museo/OperaMult.java @@ -0,0 +1,40 @@ +import java.util.Scanner; +import java.io.PrintStream; + +public class OperaMult extends Opera{ + + public OperaMult(String autore, String titolo, String supporto, int anno, String pos){ + super(autore, titolo, anno, pos); + this.supporto=supporto; + } + + public int hashCode(){ + return super.hashCode()*supporto.hashCode(); + } + + public void print(PrintStream ps){ + ps.println("OM "+autore+" "+titolo+" "+supporto+" "+anno+" "+pos+"."); + } + + public static OperaMult read(Scanner sc){ + String autore, titolo, pos, supporto; + int anno; + + if(!sc.hasNextLine()) return null; + autore=sc.nextLine(); + if(!sc.hasNextLine()) return null; + titolo=sc.nextLine(); + if(!sc.hasNextLine()) return null; + supporto=sc.nextLine(); + if(!sc.hasNextLine()) return null; + anno=Integer.parseInt(sc.nextLine()); + if(!sc.hasNextLine()) return null; + pos=sc.nextLine(); + if(!sc.hasNextLine()) return null; + sc.nextLine(); + + return new OperaMult(autore, titolo, supporto, anno, pos); + } + + private String supporto; +} \ No newline at end of file diff --git a/src/Museo/OpereMult.dat b/src/Museo/OpereMult.dat new file mode 100644 index 0000000..9d90da8 --- /dev/null +++ b/src/Museo/OpereMult.dat @@ -0,0 +1,18 @@ +Autore3 +Titolo6 +CD +1345 +45R +# +Autore1 +Titolo7 +USB +1996 +4S +# +Autore5 +Titolo8 +HD +1990 +45R +# diff --git a/src/Museo/Stampa.java b/src/Museo/Stampa.java new file mode 100644 index 0000000..956cc5c --- /dev/null +++ b/src/Museo/Stampa.java @@ -0,0 +1,40 @@ +import java.util.Scanner; +import java.io.PrintStream; + +public class Stampa extends Opera{ + + public Stampa(String autore, String titolo, String tecnica, int anno, String pos){ + super(autore, titolo, anno, pos); + this.tecnica=tecnica; + } + + public int hashCode(){ + return super.hashCode()*tecnica.hashCode(); + } + + public void print(PrintStream ps){ + ps.println("S "+autore+" "+titolo+" "+tecnica+" "+anno+" "+pos+"."); + } + + public static Stampa read(Scanner sc){ + String autore, titolo, pos, tecnica; + int anno; + + if(!sc.hasNextLine()) return null; + autore=sc.nextLine(); + if(!sc.hasNextLine()) return null; + titolo=sc.nextLine(); + if(!sc.hasNextLine()) return null; + tecnica=sc.nextLine(); + if(!sc.hasNextLine()) return null; + anno=Integer.parseInt(sc.nextLine()); + if(!sc.hasNextLine()) return null; + pos=sc.nextLine(); + if(!sc.hasNextLine()) return null; + sc.nextLine(); + + return new Stampa(autore, titolo, tecnica, anno, pos); + } + + private String tecnica; +} \ No newline at end of file diff --git a/src/Museo/Stampe.dat b/src/Museo/Stampe.dat new file mode 100644 index 0000000..15db771 --- /dev/null +++ b/src/Museo/Stampe.dat @@ -0,0 +1,18 @@ +Autore1 +Titolo1 +Pergamena +2000 +4D +# +Autore2 +Titolo2 +Carta +1990 +34C +# +Autore1 +Titolo3 +Pergamena +1999 +2C +# diff --git a/src/Museo/Test.java b/src/Museo/Test.java new file mode 100644 index 0000000..fed30d9 --- /dev/null +++ b/src/Museo/Test.java @@ -0,0 +1,14 @@ +import java.util.Scanner; +import java.io.File; + +public class Test{ + public static void main(String [] args) throws Exception{ + Scanner scLibri=new Scanner(new File("Libri.dat")); + Scanner scMult=new Scanner(new File("OpereMult.dat")); + Scanner scStampe=new Scanner(new File("Stampe.dat")); + + Archivio arch=new Archivio(scMult, scLibri, scStampe); + + arch.filtroAutore("Autore1").print(System.out); + } +} \ No newline at end of file