From 8c224faa0ea999f1f9f86ab27ed4c2ceab6ba023 Mon Sep 17 00:00:00 2001 From: peet Date: Sat, 8 Jun 2024 22:04:10 +0200 Subject: [PATCH] implemented ToTextVisitor --- bin/uebung08/doc/Book.class | Bin 1422 -> 3105 bytes bin/uebung08/doc/BookDemo.class | Bin 9126 -> 9148 bytes bin/uebung08/doc/CountWordsVisitor.class | Bin 1206 -> 2174 bytes bin/uebung08/doc/Image.class | Bin 534 -> 1031 bytes bin/uebung08/doc/Paragraph.class | Bin 795 -> 1293 bytes bin/uebung08/doc/Section.class | Bin 1098 -> 1713 bytes bin/uebung08/doc/TableOfContentsVisitor.class | Bin 0 -> 3002 bytes bin/uebung08/doc/TextComponent.class | Bin 267 -> 286 bytes bin/uebung08/doc/ToTextVisitor.class | Bin 0 -> 2746 bytes bin/uebung08/doc/Visitor.class | Bin 282 -> 452 bytes src/uebung08/doc/Book.java | 15 +++++++- src/uebung08/doc/BookDemo.java | 3 +- src/uebung08/doc/Image.java | 4 ++ src/uebung08/doc/TableOfContentsVisitor.java | 2 +- src/uebung08/doc/ToTextVisitor.java | 35 ++++++++++++++++++ 15 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 bin/uebung08/doc/TableOfContentsVisitor.class create mode 100644 bin/uebung08/doc/ToTextVisitor.class create mode 100644 src/uebung08/doc/ToTextVisitor.java diff --git a/bin/uebung08/doc/Book.class b/bin/uebung08/doc/Book.class index 7d5e4a7413a10c59de6120c68ceb4740d98f0254..02d8ec9e8ecfdbd27cfbf9d5f6fe4711a387ec46 100644 GIT binary patch literal 3105 zcmd5-U3U{z6x}yTJ8e4j3kU>i3oS^SHVp^}CZ*B_E77z?TUr4Trpb^_JDrKi1SsMM z%0JKtmrwe{ix0Y%z$&ce^4XujAMjUb-FIf%B$SV}@WqGB+&TB$bNAV2pOZiTdGtGg zG2B%U5a_7r3l*zy_+%n)=Mv+#y{sT4(7vQy*Ak{?6%x}6OM1=`XmAY2)CD@T)x8;~ zWLSliK%-W17VV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>3_Uplo|rdz&;u*s4`BLL>-Mg K{F~fU(E0(xZ*&O& delta 35 rcmZqYn8w0&>ff$?3=9m83^E(JbQmYMF_|zjP2SD4jFo|bi9s3w#C!=O diff --git a/bin/uebung08/doc/Paragraph.class b/bin/uebung08/doc/Paragraph.class index 1357da93544c62cfc7c1549432c6c3789de87edf..060a743a9357b4fb2c4f68049f2bee6382cf522a 100644 GIT binary patch delta 534 zcmZvY%Syvg5QhJW_F^nvOE)5j2)6Z-daJdm1vjpO3Ju+##zROcNr`FERiD6xxb!6y z-6-e-_yE3(8*!4jD45M$|M_Olc}U-?>gUhf2Y?eapVW66Wo#Lk@;V^oizTBghC=HJ z*VbBr@3^*3NDIr7eeRcw#z1xku3f2Vm!74yohv8se0_ZCywjCdz*AE#$96?9@Fk(z zFzaLFKTR{j8UJ_<)6|=KiS0D@aFD@1pO&;Zhbj&UsbP2rVY6u5%@sz;=VT(0=MxIa zj|dx{C396qb(4o`KvYd z#6DGi!R#Xk3g+3Sqv8q{IL^faEF#YtVVj2(R3hz81Uche;XJ!he#NeWkTWsHS&KM@ cSQBy9S%EBSIAUO(<9JC}(YZosa81GSFKw%N>;M1& delta 36 scmeC>n$5;_>ff$?3=9m840;>6_A*YEU^ZlA+U&(F%gD;Wz{H>n0L`lip8x;= diff --git a/bin/uebung08/doc/Section.class b/bin/uebung08/doc/Section.class index 3fdefa8b76c3765c9b7425bfdd2f0db66b4c8823..5193575b393d2a5e0338b563eeaafb3b411d6bd9 100644 GIT binary patch delta 594 zcmZvY%}&BV6ot=}@FQSCOhZ73abY50Vp%CtL=jX>h%Q9;rA(R<(i#}p@(hL-k?2Mj zJ^*`nK8x|TMO4x>xt%$4?z!L0JThC4&cEK?0n~6ci+)Hu1{ZbP65J9D8@YU|r;Rmb zB+S0jGKWHCDCY9hG~1srtdY0LwJskp$UoM;W*N$@7?_qp=8&fA{DGnhxz>nxMwU@5 zDP3Dv?#-bo?18!%;C9_~dR%u#98}t6Z}4Be`Y)of%&4^6YE{isjo}2fFir`_Z&(~> zs51n|&TJRyF(KdiBZOU(O*c#WgEM4&4?LRbr&MFX=dHjln;b$yj9yqm2?_cuVDtgO z!V8j5?m>!b$Q4sa(>m@Mu!#)q7>-b;y4ozSHfQ~s`%qC?A{@IZ*R+=?IkH!HMOA_m h6u>XVwi}f6JPQhPqk(hc$Sw&T<$@H3OVT7XzXACld4&J~ delta 36 scmdnUdy0eW)W2Q(7#J8F87ww(U1ge_z+%V9w0S;@IwLCs0~3Qe0OeE(+5i9m diff --git a/bin/uebung08/doc/TableOfContentsVisitor.class b/bin/uebung08/doc/TableOfContentsVisitor.class new file mode 100644 index 0000000000000000000000000000000000000000..3dda68a22975c55f36564443a5b3006de1609543 GIT binary patch literal 3002 zcma)8U3U{z6x}yXG9?|L&{9Y-$VVw@sSSb(Hnm!c*lJqPAPD$%n+)mDbSBPBD)n3O z#l;WM<(p5u>Wi%4S}vdc3H}$Y`_4?7j}ELpB)N0%Is5K&&OT@I_kWN71Tc&H8e#$` z>c(>2s+_ryE8C^qHMv|huH2ckEzht#_qyqtp6zIe3-sTW>oQlBRwZ|3`L0p&G$aKE zJKRHif#kGlncj>*Pj>9OKzzCoGrYmr=&~ZyN$-F>fUGWtd&2~C0tjUUzA1n9~)IGDBE10fFhh0UpVo9&=7y?r} za+(f6{4^9j$FwT>nY@Mr0s}4dS;vtZ>WUNw(MMjUBEV!t(GnQ%y7{VfWW|xSl_<(H zJ2sA_%9v|Sc!5KmgjyF1WV`Muvf`#~MNyjGp=l(c6prG!hGX4Q3h&c#0wW|{F}!(0 zmJNq?*|3uBMc7YCkLoyutiZuFxoS|tCF$KTy%nxpPg2dkFj^`O%NGIGhjC13I4!WJ zRa8|^9nWEsqL$^dz=3R=7J`<@kKI!7oYC<-&I+W+I&38hyh*zyKy}XxI$p#}#H6jl zTxjPLqH4GxFx=S##yvu>)ohD>+K2O)(vinBJ5QEMMvYM2stS9vS-`eNrheI}gRM~K z>}oYAw_^C3&S7y;A(zXu)v7=`4BQW-Wy|1|`6V5%82z?>k&-Y;- zZ)#XzZd!LYPj$S70w;&XK)Y+cm6oNBu@n?^KLoBSCA=+gD!b5Dqo);o9z`A3@UDQi zBHbnbQqC?vq8mEi!%cE=&Cl4y+$Lqs4Kl>&I-983C`?$zaOE1=_ivv(!W0mM>2VC| zGU@uGL`}hM`cxNmjK+;xb3Bf8;YK!?!0w_aORI~r7EaY}Wi%N_C@;liuIT7TMqr|= z&0Evr3687EF};11bd2M69je+g`2L@@@P>jkfJ{I9_A%Bg}8N**7Oq+g1oMC#%&WyE4Bw z3AY!Y3B-x0hhj)ay`w57L@l1%A*+M*`5Ji~@ z(8%jS$Z>Jv^zV4~F-`&vjKy%HXXYW6!^5d~I?m%nP=6Zu?Kk#Lz$}+AhAp(l<2KW64;ly3arYsGI(|l@qdxgFfKN678+%v z;i!7#hnbuQj%<>AymbKd&$5DB~CB+q#6`Ud3(*Fb5f#1;p literal 0 HcmV?d00001 diff --git a/bin/uebung08/doc/TextComponent.class b/bin/uebung08/doc/TextComponent.class index b029aac5b688b75e7825472eac6bdca370f98aaa..a89fa07edd404598fd7f2f5e7123dfd0a5bfc4ad 100644 GIT binary patch delta 55 zcmeBXn#VLDj!|o3yo91pR$^JAeokUuy1su>R%&vIH6sIOaAta5Vo7OHDkFp0#CBum KkPz#My8{5`P7$yG delta 36 scmbQo)Xg*@j!|-Ayo5j$BLin}W_n&?Noi3kBZJAr8ODrJ6VC+z0K7a3{{R30 diff --git a/bin/uebung08/doc/ToTextVisitor.class b/bin/uebung08/doc/ToTextVisitor.class new file mode 100644 index 0000000000000000000000000000000000000000..65e84187238fab5b16153fba1eb02c7e6c6f922c GIT binary patch literal 2746 zcma)7TXz#x6#h)$7T0GP#n4H1Fi zhOyYNswd85D|R`%U@sVVy=$gxdbXn>CeVLJuF7mpTGi~8#XCmX(~uC@5wZ&O1rp~> z%k*XhqM7k)0??+D3Hg>2h_5O)1u~hiUSUO6jof&#<#@?+OskqpVF)`l?BJ~-;HH6&UDz#wlRqbeIc%*JIyRt#s5B{QyL z0>=b)ugGO1Z(C*QT{pcY?p#k=9vK_UY|VO?6!zjcvKpoYwzvFKuIV^|7g;^BQW4nM z4(8WhZv3Wl{FIKD@Nz(wZFz>pG8o(>s~N3A%c*-#>o|k6#AGN6v(WBOfU1Gz)X@lR zgS@>`w=IJAVj8dNn89l-aak@KbwYJg5i~)Fil_Lqp+@rSQF)iwaRF}#Bu&q7BzsO^ zS167`aL!mRp`hV118wDOQ>x=lyv2UA=yhk=20je3$mVnsI4^KCQ+Q6EF5#+aCgJZD95^l4b)#%vL;p&3WJXx!6&Xmy(+;dy4XIKT>N}en)&&hf) ziaJ@|^tekErI_I*9sM})yfYx6Mj0+E!{O%{W^G26G8$kXl z%A)pz#UYkLluw-FR^!TlO}=~hmF3ER3dAQKBlR0M5$Jp;nuiH&<6id_upNE;B2yUP zTN$6_8sQp0_6UQ&a?@_y(=^`YD+I<=#U7+-reKBxn9~7FbZ~Dc$hJ0+=u?m=MzB8s zIpBkcDg)H$!h_#&@Wx{to|~joFFZj8SjS`p*P}BJu^0%aW9b;hCr8%tN(6smdSV^t z)aG?xHyvBYd4cJ~LmW;g)^SlN*>rp)9e;u%Fdd&v#{*T0uL%6S@%R0x7*U|>C<*+s z@#EwpTvzeLni-u!FZTmX{18*HlM(F37K*Ch!XUGF1dK&iw z+{7)$o5c6D`GBb%rp<@=h_R2MgpYX^qhtsYi%fNy)`|dMzrvlbRiTza*(t>S!H9B7zRua2XurXR_a=}3NXXfW&H%J`t5mFA@zSm>wZC+ml#R+KpB=N9DWrRJ4P oj8&3V#HV1g7Gt gesamt = new ArrayList<>(); + + for (int i = 0; i < content.size(); i++) { + List res = new ArrayList<>(); + res.add(content.get(i).accept(new ToTextVisitor())); + + for (String string : res) { + string = i +"." + string; + gesamt.add(string); + } + + } + + return gesamt.toString(); } public String tableOfContents() { diff --git a/src/uebung08/doc/BookDemo.java b/src/uebung08/doc/BookDemo.java index 5645f2b..1910342 100644 --- a/src/uebung08/doc/BookDemo.java +++ b/src/uebung08/doc/BookDemo.java @@ -106,7 +106,8 @@ public class BookDemo { // Aufgabe 2 System.out.println("Buch enthält " + book.countWordsByVisitor() + " Wörter"); - System.out.println("Inhalt: " + book.tableOfContents()); + System.out.println("TOC:\n" + book.tableOfContents()); + System.out.println("Inhalt:"); System.out.println(book.toText()); } diff --git a/src/uebung08/doc/Image.java b/src/uebung08/doc/Image.java index a9efdea..5c6ee75 100644 --- a/src/uebung08/doc/Image.java +++ b/src/uebung08/doc/Image.java @@ -14,6 +14,10 @@ public class Image implements TextComponent { return 0; } + public String getCaption() { + return caption; + } + // immer diese accept methode verwenden @Override public T accept(Visitor visitor) { return visitor.visit(this); } diff --git a/src/uebung08/doc/TableOfContentsVisitor.java b/src/uebung08/doc/TableOfContentsVisitor.java index f3a7e57..59d6635 100644 --- a/src/uebung08/doc/TableOfContentsVisitor.java +++ b/src/uebung08/doc/TableOfContentsVisitor.java @@ -16,7 +16,7 @@ public class TableOfContentsVisitor implements Visitor>{ public List visit(Section section) { List gesamt = new ArrayList<>(); - gesamt.add(section.getHeader()); + gesamt.add(" "+ section.getHeader()); for (int i = 0; i < section.getContent().size(); i++) { List res = new ArrayList<>(); diff --git a/src/uebung08/doc/ToTextVisitor.java b/src/uebung08/doc/ToTextVisitor.java new file mode 100644 index 0000000..903b94d --- /dev/null +++ b/src/uebung08/doc/ToTextVisitor.java @@ -0,0 +1,35 @@ +package uebung08.doc; + +import java.util.ArrayList; +import java.util.List; + +public class ToTextVisitor implements Visitor{ + + public String visit(Image image) { + return image.getCaption(); + } + + public String visit(Paragraph paragraph) { + return ""; + } + + public String visit(Section section) { + List gesamt = new ArrayList<>(); + + gesamt.add(" "+ section.getHeader()); + + for (int i = 0; i < section.getContent().size(); i++) { + + List res = new ArrayList<>(); + res.add(section.getContent().get(i).accept(this)); + + for (String string : res) { + string = i +"." + string; + gesamt.add(string); + } + + } + + return gesamt.toString(); + } +}