From 41df0a89b900f7bc5bf2f2efc9279b1aeaf5a0a4 Mon Sep 17 00:00:00 2001 From: val Date: Wed, 10 Dec 2025 00:14:53 +0100 Subject: [PATCH] maj --- TP4/stub/0Bad/Base.class | Bin 0 -> 879 bytes TP4/stub/0Bad/Base.java | 4 + TP4/stub/0Bad/Exemple.class | Bin 0 -> 1215 bytes TP4/stub/0Bad/Exemple.java | 31 +++++++ TP4/stub/0Bad/MonBrin.class | Bin 0 -> 331 bytes TP4/stub/0Bad/MonBrin.java | 28 ++++++ TP4/stub/0Bad/MonMaillon.class | Bin 0 -> 534 bytes TP4/stub/0Bad/MonMaillon.java | 40 +++++++++ TP4/stub/1Iterable/Base.class | Bin 0 -> 879 bytes TP4/stub/1Iterable/Base.java | 4 + TP4/stub/1Iterable/Exemple.class | Bin 0 -> 1096 bytes TP4/stub/1Iterable/Exemple.java | 35 ++++++++ TP4/stub/1Iterable/MonBrin.class | Bin 0 -> 1062 bytes TP4/stub/1Iterable/MonBrin.java | 55 ++++++++++++ TP4/stub/1Iterable/MonMaillon.class | Bin 0 -> 534 bytes TP4/stub/1Iterable/MonMaillon.java | 36 ++++++++ TP4/stub/2Iterator/Base.class | Bin 0 -> 879 bytes TP4/stub/2Iterator/Base.java | 4 + TP4/stub/2Iterator/Exemple.class | Bin 0 -> 2294 bytes TP4/stub/2Iterator/Exemple.java | 35 ++++++++ TP4/stub/2Iterator/MonBrin.class | Bin 0 -> 584 bytes TP4/stub/2Iterator/MonBrin.java | 40 +++++++++ TP4/stub/2Iterator/MonBrinIterator.class | Bin 0 -> 846 bytes TP4/stub/2Iterator/MonBrinIterator.java | 32 +++++++ TP4/stub/2Iterator/MonMaillon.class | Bin 0 -> 534 bytes TP4/stub/2Iterator/MonMaillon.java | 37 ++++++++ .../Base.java | 4 + .../Exemple.java | 58 ++++++++++++ .../MonBrin.java | 83 ++++++++++++++++++ .../MonBrinIterator.java | 33 +++++++ TP4/stub/explication.txt | 20 +++++ 31 files changed, 579 insertions(+) create mode 100644 TP4/stub/0Bad/Base.class create mode 100644 TP4/stub/0Bad/Base.java create mode 100644 TP4/stub/0Bad/Exemple.class create mode 100644 TP4/stub/0Bad/Exemple.java create mode 100644 TP4/stub/0Bad/MonBrin.class create mode 100644 TP4/stub/0Bad/MonBrin.java create mode 100644 TP4/stub/0Bad/MonMaillon.class create mode 100644 TP4/stub/0Bad/MonMaillon.java create mode 100644 TP4/stub/1Iterable/Base.class create mode 100644 TP4/stub/1Iterable/Base.java create mode 100644 TP4/stub/1Iterable/Exemple.class create mode 100644 TP4/stub/1Iterable/Exemple.java create mode 100644 TP4/stub/1Iterable/MonBrin.class create mode 100644 TP4/stub/1Iterable/MonBrin.java create mode 100644 TP4/stub/1Iterable/MonMaillon.class create mode 100644 TP4/stub/1Iterable/MonMaillon.java create mode 100644 TP4/stub/2Iterator/Base.class create mode 100644 TP4/stub/2Iterator/Base.java create mode 100644 TP4/stub/2Iterator/Exemple.class create mode 100644 TP4/stub/2Iterator/Exemple.java create mode 100644 TP4/stub/2Iterator/MonBrin.class create mode 100644 TP4/stub/2Iterator/MonBrin.java create mode 100644 TP4/stub/2Iterator/MonBrinIterator.class create mode 100644 TP4/stub/2Iterator/MonBrinIterator.java create mode 100644 TP4/stub/2Iterator/MonMaillon.class create mode 100644 TP4/stub/2Iterator/MonMaillon.java create mode 100644 TP4/stub/3IteratorDifferentInnerStructure/Base.java create mode 100644 TP4/stub/3IteratorDifferentInnerStructure/Exemple.java create mode 100644 TP4/stub/3IteratorDifferentInnerStructure/MonBrin.java create mode 100644 TP4/stub/3IteratorDifferentInnerStructure/MonBrinIterator.java create mode 100644 TP4/stub/explication.txt diff --git a/TP4/stub/0Bad/Base.class b/TP4/stub/0Bad/Base.class new file mode 100644 index 0000000000000000000000000000000000000000..c0797ce5650bdb605923016b4439551aa02f4193 GIT binary patch literal 879 zcmX^0Z`VEs1_oOOGj;|hMg|tA#Nt#=21W)J9tKthHbw?UM@9xVACRauNSK3%ffFq3 z4B~O~Fz|qR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JNP_(-1ptyBRd@gZ literal 0 HcmV?d00001 diff --git a/TP4/stub/0Bad/MonMaillon.java b/TP4/stub/0Bad/MonMaillon.java new file mode 100644 index 0000000..1bc920f --- /dev/null +++ b/TP4/stub/0Bad/MonMaillon.java @@ -0,0 +1,40 @@ +/** + MonMaillon code un maillon d'un brin d'ADN. + plusieurs instances reliées convenablement forment une structure + simplement chaînée contenant pour chaque maillon le nom de la base. + On n'utilise pas java.util et on recode tout. + +*/ +public class MonMaillon { + + // la base portée par ce maillon + private Base base; + + // le maillon suivant dans le brin (null si fin de chaîne) + private MonMaillon suite; + + // Le constructeur de base retourne un brin à une base; + public MonMaillon(Base b){ + this.base = b; + this.suite = null; + } + + // Le constructeur évolué ajoute une base à un brin. + + public MonMaillon(Base b, MonMaillon l){ + this.base = b; + this.suite = l; + } + + public Base getBase(){ + return this.base; + } + + public MonMaillon getSuiteMaillon(){ + return this.suite; + } + +} + + + diff --git a/TP4/stub/1Iterable/Base.class b/TP4/stub/1Iterable/Base.class new file mode 100644 index 0000000000000000000000000000000000000000..c0797ce5650bdb605923016b4439551aa02f4193 GIT binary patch literal 879 zcmX^0Z`VEs1_oOOGj;|hMg|tA#Nt#=21W)J9tKthHbw?UM@9xVACRauNSK3%ffFq3 z4B~O~Fz|qR?jRl?4+B4#7Xso5@-PT72s1LUtAsiFgt`VZGO$NO%;91XWe{U$5awYJ zXOLiIU`@`+&r4-w5Yf=|$x19s)Xz!GOV{^L%1TWxvF2isVvuHMkl|sFWsqZJ;6o^I z%`44iWMD5#%qdOvPh(^-)j-nioRe5wY>gxkTvC*omu`)01IPfd`3gJ?iVRAO3~V-; zd6^}4j0|GPMnQFYYKCzzuyQdlGAM8`aB?v4a4_(Lc$z#6S`6ACZ-QM?%*ep0p$YXU zBLf>uki|JaC6$qZ-zPIK)vq)+DYYmhF)1gNkwFTJU7C<^Vr1Y9&P>lsEGaEYWn^I1 z&9N`gy@ zQWJBnIT-jD8Kjf*^NLG~N|Q@6^Yau^N)?idGV>JNokKz#-MJV97zEiFgm@T)8AKQv zgs~XH$iQ9zGBPKRkwH`gVhz~6!6ikRdFj@gVeAZIj0{}9`FXyHnK?Q6d7KOq43g{& zQalXO3^I%iEKZ5Vsf-Ma?u-mfs8EnttWcI; zTC7lzlbBhQ3W`e;9tKkeGe!oEl6**jFfxc}XkrEv2ZIG8gOh)rLP2V2i9&8-W?o5Z zUSeK}0>tLjB8AjEh0GF=#YJG@veaaS(maLojLe)=h2;F)+*F0+)Z|Q%XRLS_tQl+= z8Q3!ti~Uk7O2A1a3M6C4!(h+gz{tRo2Nveg(1e68D4v}_k?af(O>i`WBN3A5z>(<6 z$iVJek(yhOlgh}z;+&t7%E-X)lbM(5SDKrYS`?C)1eO3fosmIIBO23>nqiC#yul@j z$=SY%1yJ=|!TF^{$*FFcAk92b^YuUuU{GXmVPIka0VW1UP3(V31{CWME`q zU|`kS&cL{lfq{XM!JUDDfekFk%)rUu!Qcs1`jml%fti7Up?wnryAba-2L9a)qLG^z z#J4lZ`aqZp+S?hFp=>oAY)vF_aVT3SQhPgto-fE;!)*-wn;6)2wlNq(SVHF882ELz zF<8!I5P(S7Zews<{{KD5u}omcS~2i3Ffed{axa500~dol12=;<0}q2a122O!10RDw zg8)MWgAhXkgD^uDgD680gE&Jag9JkxgCc_$0|NsO1JhrIB6bE*b_N|`21W*N1_lNu G1|I;SmH2o7 literal 0 HcmV?d00001 diff --git a/TP4/stub/1Iterable/Exemple.java b/TP4/stub/1Iterable/Exemple.java new file mode 100644 index 0000000..8bf7349 --- /dev/null +++ b/TP4/stub/1Iterable/Exemple.java @@ -0,0 +1,35 @@ +// Fichier Exemple pour le second exercice sur l'ADN + +public class Exemple{ + public static void main(String[] args) { + // codon GCT code l'analine https://en.wikipedia.org/wiki/DNA_codon_table + // stop codon TAG, voir https://en.wikipedia.org/wiki/Stop_codon + + System.out.println("construction du brin GCTTAG"); + MonMaillon l = new MonMaillon(Base.G); + l = new MonMaillon(Base.A,l); + l = new MonMaillon(Base.T,l); + l = new MonMaillon(Base.T,l); + l = new MonMaillon(Base.C,l); + l = new MonMaillon(Base.G,l); + + MonBrin b = new MonBrin(l); + + System.out.println("l'affichage par défaut du brin ne va pas vous plaire"); + System.out.println(b.toString()); + + System.out.println("On peut maintenant afficher en itérant avec un while comme ceci"); + + while (b.hasNext()){ + System.out.println(b.next()); + } + + // ajouter du code ici pour gérer les questions en plus + // (simulation de plusieurs navigations successives) + + + + // (simulation de plusieurs navigations simultanées) + } + +} diff --git a/TP4/stub/1Iterable/MonBrin.class b/TP4/stub/1Iterable/MonBrin.class new file mode 100644 index 0000000000000000000000000000000000000000..7a7918b515ca863e526559d2cd697188957e75f0 GIT binary patch literal 1062 zcmX^0Z`VEs1_oOO3oZsG24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3Us-~2qMqRc!-2G*3+q|y>b1|A>Z{5;>p%$%J3 zJZq3@J{|^su+rrG(xSw?5_SebMg|42HKiq)Ir@J2!KKL=t~sf>sd*)?70IauC7Jno z91OyY43YskrNs&Bo5X%~*T#ko9oR9B)BxQBo*onMg~3&O=NGeGbk}Ks3R;5%_}Y~D9A4=Nlo!DNG(bPc>u{LDvS(r zMX9;@WvLpP3VG_O#U%;_iNy*~J%^hQt>j`*WDwC9(fyFsLC6$qZ-zPIK)vq)+DYYmhF)0V+!}Qb=7f95w zXCxN;rB;-HV={`7fj77$F*(~eu>h)+4dO^f1`!QSq#%W)18YVG&fv`Syu^~yqEto( zJxm1<5fqo&Kmym!nvsDkIKQ+gIn^x_GkwKGziGc}}t{4~? zm_Uh!fq{XIfsuigL7Rb*L5G2X!5FN9fq`FZI|HMZ_ErXV5W%~Vfq{XML6?DnL5P8c zfq_ASfrUYmfs;Xsfsa9&fssLvK>=!jECVA0BLf2itJW3<_6=}tAX^w1@3R}SeVy!Mg}8rpn!ryiGdmH8?N09ijhLf+Zj~%qj||xz>z_N!5Hc&gzvX8 ZsDbQ+1RBIE{0vMCCSdQGGMIsBa{wmw({TU* literal 0 HcmV?d00001 diff --git a/TP4/stub/1Iterable/MonBrin.java b/TP4/stub/1Iterable/MonBrin.java new file mode 100644 index 0000000..ae826dd --- /dev/null +++ b/TP4/stub/1Iterable/MonBrin.java @@ -0,0 +1,55 @@ +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + MonBrin code un brin d'ADN sous forme de liste simplement chaînée. + + Plusieurs instances de MonMaillon reliées convenablement forment une structure + simplement chaînée contenant pour chaque maillon le nom de la base. + + On n'utilise pas java.util (pas de ArrayList, etc.) et on recode tout. + + Dans cet exercice, cette classe implémente aussi Iterator : + elle sait donc se parcourir elle-même. +*/ +public class MonBrin implements Iterator { + + // Premier maillon du brin + private MonMaillon debut; + + // Maillon courant pour la navigation (iterator) + private MonMaillon courant; + + // Le constructeur fabrique un brin à partir du premier maillon p; + public MonBrin(MonMaillon p){ + this.debut = p; + this.courant = p; // l'itération commence au début du brin + } + + public MonMaillon getDebut(){ + return this.debut; + } + + /** Méthodes de l'interface Iterator */ + + @Override + public boolean hasNext() { + return this.courant != null; + } + + @Override + public Base next() { + if (this.courant == null) { + throw new NoSuchElementException("Plus de base dans ce brin"); + } + Base valeur = this.courant.getBase(); + this.courant = this.courant.getSuiteMaillon(); + return valeur; + } + + @Override + public void remove() { + // On ne gère pas la suppression dans ce TP + throw new UnsupportedOperationException("remove() n'est pas supporté"); + } +} diff --git a/TP4/stub/1Iterable/MonMaillon.class b/TP4/stub/1Iterable/MonMaillon.class new file mode 100644 index 0000000000000000000000000000000000000000..73ce349bf6b3cc06be071e4a46a630b24af2d843 GIT binary patch literal 534 zcmX^0Z`VEs1_oOOX)XpP24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3T(-~2q^#LS$W{5(bmmZZeuR7M6iAE(6PRBMn* zJ{|^s1_4F}*5cC4l2k?p9v_5yYeoi64Tw_BFh&Lz=lqmZMh1SL%)C^;(%hufqL9R- zoK!{zQK%whtso8T>8T|kix?R=G&CXRFf#C`rGoTot zgT(+b1{MZ!22KVE20jK!21W)^1~I4svJ8w2j0_A6tXf+b*f+rKWdjS!FfcNRGe}@j Q%8Ra4fq{`h66{YY0E@&`XaE2J literal 0 HcmV?d00001 diff --git a/TP4/stub/1Iterable/MonMaillon.java b/TP4/stub/1Iterable/MonMaillon.java new file mode 100644 index 0000000..8dc3245 --- /dev/null +++ b/TP4/stub/1Iterable/MonMaillon.java @@ -0,0 +1,36 @@ +/** + MonMaillon code un maillon d'un brin d'ADN. + Plusieurs instances reliées convenablement forment une structure + simplement chaînée contenant pour chaque maillon le nom de la base. + On n'utilise pas java.util et on recode tout. +*/ +public class MonMaillon { + + // La base stockée dans ce maillon + private Base base; + + // Le maillon suivant dans la chaîne (null si fin du brin) + private MonMaillon suite; + + // Le constructeur de base retourne un brin à une base; + public MonMaillon(Base b){ + this.base = b; + this.suite = null; + } + + // Le constructeur évolué ajoute une base à un brin. + public MonMaillon(Base b, MonMaillon l){ + this.base = b; + this.suite = l; + } + + public Base getBase(){ + return this.base; + } + + public MonMaillon getSuiteMaillon(){ + return this.suite; + } +} + + diff --git a/TP4/stub/2Iterator/Base.class b/TP4/stub/2Iterator/Base.class new file mode 100644 index 0000000000000000000000000000000000000000..c0797ce5650bdb605923016b4439551aa02f4193 GIT binary patch literal 879 zcmX^0Z`VEs1_oOOGj;|hMg|tA#Nt#=21W)J9tKthHbw?UM@9xVACRauNSK3%ffFq3 z4B~O~Fz|qR?jRl?4+B4#7Xso5@-PT72s1LUtAsiFgt`VZGO$NO%;91XWe{U$5awYJ zXOLiIU`@`+&r4-w5Yf=|$x19s)Xz!GOV{^L%1TWxvF2isVvuHMkl|sFWsqZJ;6o^I z%`44iWMD5#%qdOvPh(^-)j-nioRe5wY>gxkTvC*omu`)01IPfd`3gJ?iVRAO3~V-; zd6^}4j0|GPMnQFYYKCzzuyQdlGAM8`aB?v4a4_(Lc$z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hJ&q%BrXnR>qKgAXVCKnnQOR>fqxSN zyUsQSV+c#gd>aG5&MpQ^28L}6wjd>r5CLbnfD1@q8-tsl?oI|TMuwRTlDaz?0vH(% zFi2RjY+_)SWZA|Lvi$!OkoTCt-t%J+W?*38V&GulW)NoJVUTCwWzc5eV=!mnXK-c^ zVDM)UVu)Z6VMt&QWyoR>XDDKjV5nx0VrXWNX6Rv%WthSs$FP<`o?$D40>cglMTS@g z1_nU}rhg1G*%?IH8Fbhgynivs32=d87!rC63Jgr(Fy+|9z^=88Aq3 System.out.println(b)); + + System.out.println("On a découplé la navigation de la structuration en implémentant iterable plutôt que iterator. On peut maintenant naviguer 2 fois facilement, c'est vraiment trop fort."); + m.forEach(b -> System.out.println(b)); + + System.out.println("On peut même utiliser les boucles avancées de Java 8 et notre code en devient presque pythonesque"); + for(Base b: m){ + System.out.println(b); + } + } + +} diff --git a/TP4/stub/2Iterator/MonBrin.class b/TP4/stub/2Iterator/MonBrin.class new file mode 100644 index 0000000000000000000000000000000000000000..abc772784b30eafd4bfffee702552c1406d9c573 GIT binary patch literal 584 zcmX^0Z`VEs1_oOOc`gPf24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3Us-~2qMqRc!-2G*3+q|y>b1|A>Z{5;>p%$%J3 zJZp9aK1K$9s2b0b)S|?a{30#}UIqb>b%Klx{2Iv0HN)5$gc%ux5N-hLNy^gKiVPeKObm<+LJW)yOrYRoU|?WoU}Rur5M*Fv5Mf|o&|+X> zU}9ik;L_U8z^J9Ym4SUD0|NsigD3+710Mr30|SEu0}F#B11EzN10#bNgE&;5ECVA0 zBLf2itJW3<_6=|?Y+ylri8mVqjokVvuHF Mg0f^7WWgeG0PrMsE&u=k literal 0 HcmV?d00001 diff --git a/TP4/stub/2Iterator/MonBrin.java b/TP4/stub/2Iterator/MonBrin.java new file mode 100644 index 0000000..e6566a8 --- /dev/null +++ b/TP4/stub/2Iterator/MonBrin.java @@ -0,0 +1,40 @@ +import java.util.Iterator; +import java.util.NoSuchElementException; +/** + MonBrin code un brin d'ADN sous forme de liste simplement chaînée. + + Plusieurs instances de MonMaillon reliées convenablement forment une structure de liste simplement chaînée contenant pour chaque maillon le nom de la base. + + On n'utilise pas java.util et on recode tout. + + Cette version est correcte : la structuration et la navigation sont dans 2 classes séparées. +La classe MonBrin implémente Iterable au sens où elle peut générer à la demande un objet Iterator. + +NB : Notez que j'implémente Iterable plutôt que Iterable qui n'était pas tout à fait propre +c'est un peu technique et c'est lié aux types génériques. + Il y a des détails ici +https://stackoverflow.com/questions/20790770/why-cant-i-assign-a-raw-type-to-a-parameterized-type-java?rq=1 +*/ +public class MonBrin implements Iterable { + + // premier maillon du brin + private MonMaillon debut; + + // Le constructeur fabrique un brin à partir du premier maillon p; + public MonBrin(MonMaillon p){ + this.debut = p; + } + + public MonMaillon getDebut(){ + return this.debut; + } + + /** Pour naviguer? + On implémente l'interface iterator de java.util ici + L'avantage c'est que c'est standard et tout le monde comprendra sans trop de mal comment la navigation fonctionne. + **/ + @Override + public Iterator iterator() { + return new MonBrinIterator(this.debut); + } +} diff --git a/TP4/stub/2Iterator/MonBrinIterator.class b/TP4/stub/2Iterator/MonBrinIterator.class new file mode 100644 index 0000000000000000000000000000000000000000..ebaaf57499b177544fb72050051c25a2decb135f GIT binary patch literal 846 zcmX^0Z`VEs1_oOOJuU_&24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3U!-~2qMqRc$clGLKalKdh@2KMCq(xSw?5=I6d zAK&~u-^9$Eocug%b_PC11_iL;r6rj;`hNMrrO6qtIjOm+c_pqD$*Bb;nfZAf3<8V{ zk^woT#R@5@3Q38@sR}8HdBqCJsR~I&nR#3cybMAhhYB+?h-&zNO#?eMxTGjEFWp)* zjEg~(L5!V2oQFYzL6VVy3*iDr2KMyS5~sxCR7M644NV^q%NnFynukG#L6(t$KRvZ1 zxHPjQ73yS020jflsEGaEYWn|F9Q~(h{ag`0k%XZd`3|ztarA5i9ZkZqlh@eHG9>_xs ziVPeKObm<+iVTblOrW@CU|?WjU}RurP-b9cP+?$T&|+X>U}9ik;L_U8z^J9Ym4SUD z0|NsigDL|910Mr3m}Ft#XW(QIU|?iWV^D|cGhkq3U}Rum;MLl~z { + + // maillon courant de la navigation + private MonMaillon courant; + + public MonBrinIterator(MonMaillon m){ + this.courant = m; + } + + @Override + public boolean hasNext(){ + return this.courant != null; + } + + @Override + public Base next() { + if (this.courant == null) { + throw new NoSuchElementException("Plus de base dans ce brin"); + } + Base valeur = this.courant.getBase(); + this.courant = this.courant.getSuiteMaillon(); + return valeur; + } +} diff --git a/TP4/stub/2Iterator/MonMaillon.class b/TP4/stub/2Iterator/MonMaillon.class new file mode 100644 index 0000000000000000000000000000000000000000..73ce349bf6b3cc06be071e4a46a630b24af2d843 GIT binary patch literal 534 zcmX^0Z`VEs1_oOOX)XpP24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00SP6iGJPId+^9tLg(9!3T(-~2q^#LS$W{5(bmmZZeuR7M6iAE(6PRBMn* zJ{|^s1_4F}*5cC4l2k?p9v_5yYeoi64Tw_BFh&Lz=lqmZMh1SL%)C^;(%hufqL9R- zoK!{zQK%whtso8T>8T|kix?R=G&CXRFf#C`rGoTot zgT(+b1{MZ!22KVE20jK!21W)^1~I4svJ8w2j0_A6tXf+b*f+rKWdjS!FfcNRGe}@j Q%8Ra4fq{`h66{YY0E@&`XaE2J literal 0 HcmV?d00001 diff --git a/TP4/stub/2Iterator/MonMaillon.java b/TP4/stub/2Iterator/MonMaillon.java new file mode 100644 index 0000000..9d54454 --- /dev/null +++ b/TP4/stub/2Iterator/MonMaillon.java @@ -0,0 +1,37 @@ +/** + MonMaillon code un maillon d'un brin d'ADN. + plusieurs instances reliées convenablement forment une structure de liste simplement chaînée contenant pour chaque maillon le nom de la base. + On n'utilise pas java.util et on recode tout. + +*/ +public class MonMaillon { + + // la base stockée dans ce maillon + private Base base; + + // le maillon suivant dans la chaîne (null si fin) + private MonMaillon suite; + + // Le constructeur de base retourne un brin à une base; + public MonMaillon(Base b){ + this.base = b; + this.suite = null; + } + + // Le constructeur évolué ajoute une base à un brin. + public MonMaillon(Base b, MonMaillon l){ + this.base = b; + this.suite = l; + } + + public Base getBase(){ + return this.base; + } + + public MonMaillon getSuiteMaillon(){ + return this.suite; + } + +} + + diff --git a/TP4/stub/3IteratorDifferentInnerStructure/Base.java b/TP4/stub/3IteratorDifferentInnerStructure/Base.java new file mode 100644 index 0000000..5e6a4cf --- /dev/null +++ b/TP4/stub/3IteratorDifferentInnerStructure/Base.java @@ -0,0 +1,4 @@ +// juste un type énuméré pour nommer les bases +public enum Base { + A,C,G,T +} diff --git a/TP4/stub/3IteratorDifferentInnerStructure/Exemple.java b/TP4/stub/3IteratorDifferentInnerStructure/Exemple.java new file mode 100644 index 0000000..b4afd21 --- /dev/null +++ b/TP4/stub/3IteratorDifferentInnerStructure/Exemple.java @@ -0,0 +1,58 @@ +// Fichier Exemple pour le dernier exercice sur l'ADN (Iterable) + +public class Exemple{ + + public static void main(String[] args) { + + // codon GCT code l'analine https://en.wikipedia.org/wiki/DNA_codon_table + // codon CAT code Histidine + // codon CGT code Arginine + // codon GCC code Analine + // stop codon TAG, voir https://en.wikipedia.org/wiki/Stop_codon + + System.out.println("construction du brin CGT CAT CGT GCC CAT GCT TAG"); + MonBrin l = new MonBrin(Base.G); + l = new MonBrin(Base.A,l); + l = new MonBrin(Base.T,l); + // + l = new MonBrin(Base.T,l); + l = new MonBrin(Base.C,l); + l = new MonBrin(Base.G,l); + // + l = new MonBrin(Base.T,l); + l = new MonBrin(Base.A,l); + l = new MonBrin(Base.C,l); + // + l = new MonBrin(Base.C,l); + l = new MonBrin(Base.C,l); + l = new MonBrin(Base.G,l); + // + l = new MonBrin(Base.T,l); + l = new MonBrin(Base.G,l); + l = new MonBrin(Base.C,l); + // + l = new MonBrin(Base.T,l); + l = new MonBrin(Base.A,l); + l = new MonBrin(Base.C,l); + // + l = new MonBrin(Base.T,l); + l = new MonBrin(Base.G,l); + l = new MonBrin(Base.C,l); + // + + System.out.println("l'affichage par défaut ne va toujours pas vous plaire"); + System.out.println(l.toString()); + + System.out.println("On peut afficher en itérant avec forEach (une méthode proposée par Iterable, regardez la doc)"); + l.forEach(b -> System.out.println(b)); + + System.out.println("On a découplé la navigation de la structuration en implémentant iterable plutôt que iterator. On peut maintenant naviguer 2 fois facilement, c'est vraiment trop fort."); + l.forEach(b -> System.out.println(b)); + + System.out.println("On peut même utiliser les boucles avancées de Java 8 et notre code en devient presque pythonesque"); + for(Base b: l){ + System.out.println(b); + } + } + +} diff --git a/TP4/stub/3IteratorDifferentInnerStructure/MonBrin.java b/TP4/stub/3IteratorDifferentInnerStructure/MonBrin.java new file mode 100644 index 0000000..6cd0ad1 --- /dev/null +++ b/TP4/stub/3IteratorDifferentInnerStructure/MonBrin.java @@ -0,0 +1,83 @@ +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** +MonBrin code un brin d'ADN sous forme de tableaux. Dynamiquement, la taille du tableau est augmentée en cas de besoin (la taille est initialement 3*4 elle est multipliée ensuite pour être toujours de la forme 3*2^n). +On utilise System.arraycopy et java.util.Arrays.copyOfRange pour faire ça efficacement. +voir +https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#arraycopy-java.lang.Object-int-java.lang.Object-int-int- +https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#copyOfRange-T:A-int-int- + +Cette version est correcte : la structuration et la navigation sont dans 2 classes séparées. +La classe MonBrin implémente Iterable au sens où elle peut générer à la demande un objet Iterator. + +NB : Notez que j'implémente Iterable plutôt que Iterable qui n'était pas tout à fait propre +c'est un peu technique et c'est lié aux types génériques. + Il y a des détails ici +https://stackoverflow.com/questions/20790770/why-cant-i-assign-a-raw-type-to-a-parameterized-type-java?rq=1 +*/ + +public class MonBrin implements Iterable { + + /** + C'est le constructeur de base (pun intended) qui construit un brin à une base + + @param b : la base + + Ici je pourrais mettre un commentaire plus long sur le fonctionement détaillé de mon super constructeur. + + */ + public MonBrin(Base b){ + + } + + /** + C'est le constructeur évolué qui construit un brin en ajoutant la base donnée en argument devant le brin donné en argument. + + @param b : la base qui va aller devant + @param l : le brin qui sera à la suite + + NB. Ce constructeur est un peu obsolète avec la nouvelle structure interne. + On devrait en ajouter un qui prend en paramètre un tableau de bases. + */ + public MonBrin(Base b, MonBrin l){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public Base getBase(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public int length(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public int limit(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public int capacity(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public Base getBase(int i){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + public Base[] getBases(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + /** Pour naviguer? + On implémente l'interface iterator de java.util ici + L'avantage c'est que c'est standard et tout le monde comprendra sans trop de mal comment la navigation fonctionne. + **/ + @Override + public Iterator iterator() { + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + +} + + diff --git a/TP4/stub/3IteratorDifferentInnerStructure/MonBrinIterator.java b/TP4/stub/3IteratorDifferentInnerStructure/MonBrinIterator.java new file mode 100644 index 0000000..363d355 --- /dev/null +++ b/TP4/stub/3IteratorDifferentInnerStructure/MonBrinIterator.java @@ -0,0 +1,33 @@ +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** +MonBrinIterator + +gère la navigation dans un Brin d'ADN + +*/ +public class MonBrinIterator implements Iterator { + + //Le constructeur de base retourne un brin à une base; + public MonBrinIterator(MonBrin brin){ + } + + /** Pour naviguer? + On implémente l'interface iterable de java.util ici + L'avantage c'est que c'est standard et tout le monde comprendra sans trop de mal comment la navigation fonctionne. + **/ + + @Override + public boolean hasNext(){ + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + + @Override + public Base next() { + throw new UnsupportedOperationException("cette méthode n'est pas implémentée"); + } + +} + + diff --git a/TP4/stub/explication.txt b/TP4/stub/explication.txt new file mode 100644 index 0000000..9254e46 --- /dev/null +++ b/TP4/stub/explication.txt @@ -0,0 +1,20 @@ +Les biologistes sont des gens étranges pour lesquels les string n'ont que 4 lettres : A,C,G ou T. +Ils ne connaissent pas les String, ils parlent d'ADN. + + +Le Brin est une succession de Maillons. +Il suffit de connaître le premier maillon pour définir un brin d'ADN. + + +----------+ + | maillon | + | | _____ next __> autre Maillon + | | + +----+-----+ + | + | val + \|/ + +----------+ + | Base | + | A | + | | + +----+-----+