From 753d5e2780c78fd2be64bffa84ab2267619b833f Mon Sep 17 00:00:00 2001 From: peet Date: Fri, 7 Jun 2024 15:25:15 +0200 Subject: [PATCH] implemented composite pattern --- bin/uebung08/doc/Book.class | Bin 0 -> 1422 bytes bin/uebung08/doc/BookDemo.class | Bin 0 -> 9126 bytes bin/uebung08/doc/Image.class | Bin 0 -> 855 bytes bin/uebung08/doc/Paragraph.class | Bin 0 -> 795 bytes bin/uebung08/doc/Section.class | Bin 0 -> 1098 bytes bin/uebung08/doc/TextComponent.class | Bin 0 -> 267 bytes src/uebung08/doc/Book.java | 37 +++++++ src/uebung08/doc/BookDemo.java | 148 +++++++++++++++++++++++++++ src/uebung08/doc/Image.java | 22 ++++ src/uebung08/doc/Paragraph.java | 30 ++++++ src/uebung08/doc/Section.java | 23 +++++ src/uebung08/doc/TextComponent.java | 7 ++ 12 files changed, 267 insertions(+) create mode 100644 bin/uebung08/doc/Book.class create mode 100644 bin/uebung08/doc/BookDemo.class create mode 100644 bin/uebung08/doc/Image.class create mode 100644 bin/uebung08/doc/Paragraph.class create mode 100644 bin/uebung08/doc/Section.class create mode 100644 bin/uebung08/doc/TextComponent.class create mode 100644 src/uebung08/doc/Book.java create mode 100644 src/uebung08/doc/BookDemo.java create mode 100644 src/uebung08/doc/Image.java create mode 100644 src/uebung08/doc/Paragraph.java create mode 100644 src/uebung08/doc/Section.java create mode 100644 src/uebung08/doc/TextComponent.java diff --git a/bin/uebung08/doc/Book.class b/bin/uebung08/doc/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..7d5e4a7413a10c59de6120c68ceb4740d98f0254 GIT binary patch literal 1422 zcmbVL+fEZv6kTVgbb1+RX`u*3LGaQJEyXKnD+(kgBn2LdHSx)58OuPKA=5J|FaCsY z{(vt&Xd*HAV0`vR{0nuT=|EeQXiSqi=j`j+d#!%^@%amYB`hhB7zSOV=30%pg~FCy zFD%>ku7UtVd`Ew-7n-`&C~VYrj5=rN<0fw!42g2bSK*FnHHr*D-R0Z1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QE1rL&XX)?s9Q^~&f1>VRX!9RB!lu*nY!06D=nz{#PqHhpjaW`E zur>4|>%~k4=_`SqYgiY?KMv_t`Z>LgHwO7A{S0p{=(P%^$7ve+UJaNZ2M(t}7vr5% e^b0)aLH-r`yqEd?4gD51=J@hE`aS)TF8?nY?3afC literal 0 HcmV?d00001 diff --git a/bin/uebung08/doc/Image.class b/bin/uebung08/doc/Image.class new file mode 100644 index 0000000000000000000000000000000000000000..47f595cb30b2e0f0033a086653a13be194a50321 GIT binary patch literal 855 zcmZuvO>Yx15PeQUK9-P_v<1pX+49vSRD?qhsEHz>3ZzOANMs2rH)mr~SG#uPcq8~v zTsTyfK!Q6z3NhY9w4v2%$DZ-bdo$1e{pb5n057p!K!%}~h+(3}&tJ4gI&2-pd@Ksc zF{~W(8E-{gjazSr$0D=^2-EOsv5{eAfo>byZ5)Xw5 z_%IT#9Uby$z>ReNBAByBa>}sQTN)=Fo|^SSohbW3n-S#@*8z3S!%$3U#*O-N%|K42 z)u!F}$WZFbvEnu{M7!Gw_RdW+m$2Qvyt)$v?JhwSaGypvlkb%=+7z+H@b0}bVydH= z82KS7E+g*b^e0BsRPmngm4Yu5;m2|sa~mG*`5{+ITS`_lVXXhj=-3Z@tNo$Yk>JYn zu!)CG&_@jGm)wO@-s|hcgyOYyN_we2&s=-hBF(e(UqOaGx&(Sr8FvM=y10j{WXt3o zQanp*wRwtb&8H_=Y3`h$_AM<~BU?j`Y>{kWWPEKhn!C%l@zT!KV6{FL&hD-x|`xKz6|-^4{RRR{8K#m^&ise NIVA5N(&IGi$zNl`vv&Xh literal 0 HcmV?d00001 diff --git a/bin/uebung08/doc/Paragraph.class b/bin/uebung08/doc/Paragraph.class new file mode 100644 index 0000000000000000000000000000000000000000..1357da93544c62cfc7c1549432c6c3789de87edf GIT binary patch literal 795 zcmZWm(QXn^5Iw_g+3t1$+gfM~)Y@7FYC&U6Oe{?ZNfQ#RCN!Az?Xuj!R=P`;i~0fm z34QaaFTR*48Xx=s|G=NA&Mu@)V>b8ho|!pw&dmP4{P_z&4P^r{LV7GaW3Tto*w3^1Z72XG7nUo+9XqF=45BO>L>b z^?J_<@qO2G)d69p@PE44W^&!{N(&kiHcTW5TA|oB!A5Ktm?xx~t|yPiXB`r9C!q0l`WJ4kcOf%JN+ zPcYxHlgJW*8iaXw)bK)g3{UvDghWdT=gkW-oXu#p{BhvOLpR()@@lqn=!VsKDn4_3 zV&UrehsXHagvIv)qeI3qep{vQuuHq&kopqUEb^UXE|{e=&*W!`QF>a9W!z@Oyr?T% z!wTo7JtthFbMC3OuT`~!3v89XB9)&Y^8@)0Naa2vaZaRHFEFQ7&o#=2`3bf^{r!{u z%tQ^Ld^s|h;ATl~w-_17uyB^8H&|{H8Eo?wcR2S1xyW8=Dm=3nHq)$ literal 0 HcmV?d00001 diff --git a/bin/uebung08/doc/Section.class b/bin/uebung08/doc/Section.class new file mode 100644 index 0000000000000000000000000000000000000000..3fdefa8b76c3765c9b7425bfdd2f0db66b4c8823 GIT binary patch literal 1098 zcmah|+fEZv6kTUp7}`#uR2=1^TomnvQoNJ2Au%K-Bn2NzYT}dA>7*SfGh}+k%Xj$Z z5BTDXiNxT8@!22oFT{1GMJUFQrstf!_gQPNv-h5#zrTG4@D%GhG=ZtmX@*{VZN1#` z?Q-3*rR#e-;sTjH>$O$xT3);Syt&7Kj!}V`q5HeeTe;~U9QvN)NrBOhW3`+>AX_^F z*Ja>(?TUbI`<{&MW%}Vzy4`Zk?MVg`b+_$VG7KDn)eGTj?f*$D8w8J5UC)&p0?WC7 z6JH>!66 z!LHTp@{!q^Z(H4l6}ZYCIODS8_5{q~2M@Z!hnmBncZa9Ir0s{EeBlQz!YN}bg#|3> zSQHqKTJg8m25#ZDz?dtYz>+?jW#;ndYP2=*S5mlxoQ}Jcdd6@XHIPSv74SF!9HLW( zbJIfn2v!W-z)i)pYM_iY4nfE2?L;7|e96AQq2@@ufY=g9%i)ol8!pArz_B3dy0q;5 zZR>DQz+~MI1KWA#suCN6!mTR(SY$h5{EtB6kNx3SpsDWAmx|5?ZBk;Kd*3sG3?uur zW85bSUolxI9$~7mas=};T`^qennj#zl52{D1_{!bre~oK!whC=kswMdqLWIjVUA~m zNmWcCl>kDs)a8wk1;Q>^ATq07|Q}bFtRn#Z^${4?zTi;!M0k>(MDwze|o}jr&6G4^EIKeoKr>kFd5dHrS<2Z;) rgtL)4V|YqJ?8pt4!?=8@fcw literal 0 HcmV?d00001 diff --git a/src/uebung08/doc/Book.java b/src/uebung08/doc/Book.java new file mode 100644 index 0000000..ae82e76 --- /dev/null +++ b/src/uebung08/doc/Book.java @@ -0,0 +1,37 @@ +package uebung08.doc; + +import java.util.List; + +public class Book { + + private String title; + private String author; + + List content; + + public Book(String author, String title, List content) { + this.author = author; + this.title = title; + this.content = content; + } + + public int countWords() { + int wordcount = 0; + for (TextComponent textComponent : content) { + wordcount += textComponent.countWords(); + } + return wordcount; + } + + public String toText() { + return ""; + } + + public String tableOfContents() { + return ""; + } + + public int countWordsByVisitor() { + return 0; + } +} diff --git a/src/uebung08/doc/BookDemo.java b/src/uebung08/doc/BookDemo.java new file mode 100644 index 0000000..5645f2b --- /dev/null +++ b/src/uebung08/doc/BookDemo.java @@ -0,0 +1,148 @@ +package uebung08.doc; + +import java.util.List; + +public class BookDemo { + private static final String TEXT0 = "Über Entwurf und Realisierung eierlegender Wollmilchsäue."; + private static final String TEXT1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod " + + "tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. " + + "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd " + + "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum " + + "dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor " + + "invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + private static final String TEXT2 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan " + + "et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis " + + "dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer " + + "adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore " + + "magna aliquam erat volutpat."; + private static final String TEXT3 = "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit " + + "lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure " + + "dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore " + + "eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim " + + "qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla " + + "facilisi."; + private static final String TEXT4 = "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming " + + "id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, " + + "consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet " + + "dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud " + + "exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo " + + "consequat."; + private static final String TEXT5 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis."; + private static final String TEXT6 = "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, " + + "no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, " + + "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et " + + "dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo " + + "duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est " + + "Lorem ipsum dolor sit amet."; + private static final String TEXT7 = "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore " + + "et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et " + + "justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata " + + "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur " + + "sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore " + + "magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo " + + "dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est " + + "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing " + + "elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam " + + "erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea " + + "rebum. Stet clita kasd gubergren, no sea takimata sanctus."; + private static final String TEXT8 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " + + "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " + + "nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed " + + "diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. "; + private static final String TEXT9 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan " + + "et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis " + + "dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer " + + "adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore " + + "magna aliquam erat volutpat."; + private static final String TEXT10 = "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit " + + "lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure " + + "dolor in hendrerit in vulputate velit esse molestie consequat, vel illum " + + "dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio " + + "dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te " + + "feugait nulla facilisi."; + private static final String TEXT11 = "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet " + + "doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, " + + "consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut " + + "laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, " + + "quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex " + + "ea commodo"; + private static final String TEXT12 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " + + "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " + + "nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed " + + "diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT13 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita " + + "kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT14 = "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, " + + "no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit " + + "amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut " + + "labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam " + + "et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata " + + "sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT15 = "Lorem ipsum dolor sit amet, consetetur sadipscing " + + "elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et " + + "nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd " + + "magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum " + + "dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed " + + "diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; + + public static void main(String[] args) { + final Book book = makeBook(); + + // Aufgabe 1 + System.out.println("Buch enthält " + book.countWords() + " Wörter"); + + // Aufgabe 2 + System.out.println("Buch enthält " + book.countWordsByVisitor() + " Wörter"); + System.out.println("Inhalt: " + book.tableOfContents()); + System.out.println(book.toText()); + } + + private static Book makeBook() { + final Section sec1 = new Section("Einführung", + List.of(new Paragraph(TEXT1), + new Paragraph(TEXT2))); + final Section sec2 = new Section("Hintergrund", + List.of(new Paragraph(TEXT3), + new Section("Geschichte", + List.of(new Paragraph(TEXT4), + new Image("https://www.bekannt.de/p1.pdf", + "Bild 1"), + new Paragraph(TEXT5))), + new Section("Literatur", + List.of(new Paragraph(TEXT6), + new Image("https://www.eh-klar.de/p2.pdf", + "Bild 2"), + new Paragraph(TEXT7), + new Image("https://www.jeder-weiss-es.de/p3.pdf", + "Bild 3"), + new Paragraph(TEXT8))))); + final Section sec3 = new Section("Idee", + List.of(new Paragraph(TEXT9))); + final Section sec4 = new Section("Umsetzung", + List.of(new Paragraph(TEXT10), + new Section("Entwurf", + List.of(new Paragraph(TEXT11), + new Section("Grobentwurf", + List.of(new Paragraph(TEXT12))), + new Section("Feinentwurf", + List.of(new Paragraph(TEXT13))))), + new Section("Realisierung", + List.of(new Paragraph(TEXT14))))); + final Section sec5 = new Section("Zusammenfassung und Ausblick", List.of(new Paragraph(TEXT15))); + return new Book("Peter Mustermann", "Die eierlegende Wollmilchsau", + List.of(new Paragraph(TEXT0), sec1, sec2, sec3, sec4, sec5)); + } +} diff --git a/src/uebung08/doc/Image.java b/src/uebung08/doc/Image.java new file mode 100644 index 0000000..7b63d53 --- /dev/null +++ b/src/uebung08/doc/Image.java @@ -0,0 +1,22 @@ +package uebung08.doc; + +public class Image implements TextComponent { + + private String url; + private String caption; + + public Image(String url, String caption) { + this.url = url; + this.caption = caption; + } + + public int countWords() { + return 0; + } + + @Override + public boolean accept(CountWordsVisitor visitor) { + return visitor.visit(this); + } + +} diff --git a/src/uebung08/doc/Paragraph.java b/src/uebung08/doc/Paragraph.java new file mode 100644 index 0000000..ce20b69 --- /dev/null +++ b/src/uebung08/doc/Paragraph.java @@ -0,0 +1,30 @@ +package uebung08.doc; + +public class Paragraph implements TextComponent { + + private String text; + + public Paragraph(String text) { + this.text = text; + } + + + public int countWords() { + int wordcount = 0; + boolean isInWord = false; + + + for (int i = 0; i < text.length(); i++) { + if(Character.isAlphabetic(text.charAt(i))){ + if (!isInWord) { + wordcount++; + isInWord = true; + } + } else { + isInWord = false; + } + } + + return wordcount; + } +} diff --git a/src/uebung08/doc/Section.java b/src/uebung08/doc/Section.java new file mode 100644 index 0000000..ad312ee --- /dev/null +++ b/src/uebung08/doc/Section.java @@ -0,0 +1,23 @@ +package uebung08.doc; + +import java.util.List; + +public class Section implements TextComponent { + + private String header; + private List content; + + public Section(String header, List content) { + this.header = header; + this.content = content; + } + + public int countWords() { + int wordcount = 0; + for (TextComponent textComponent : content) { + wordcount += textComponent.countWords(); + } + return wordcount; + } + +} diff --git a/src/uebung08/doc/TextComponent.java b/src/uebung08/doc/TextComponent.java new file mode 100644 index 0000000..130430e --- /dev/null +++ b/src/uebung08/doc/TextComponent.java @@ -0,0 +1,7 @@ +package uebung08.doc; + +public interface TextComponent { + public int countWords(); + + public boolean accept(Visitor visitor); +}