From 83a4e2f8cfad3abdaee408cf9687eb8e8fc0cbc0 Mon Sep 17 00:00:00 2001 From: Minh VU Date: Fri, 7 Feb 2025 16:14:18 +0100 Subject: [PATCH] pretty printer --- src/main/java/TP1/ASD_Turtle.java | 53 ++++++------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/src/main/java/TP1/ASD_Turtle.java b/src/main/java/TP1/ASD_Turtle.java index 683c24a..031a41c 100644 --- a/src/main/java/TP1/ASD_Turtle.java +++ b/src/main/java/TP1/ASD_Turtle.java @@ -18,7 +18,16 @@ public class ASD_Turtle implements TurtleASD { return str; } } - record PhraseImp(EntityImp entity, List affs) implements Phrase{} + record PhraseImp(EntityImp entity, List affs) implements Phrase{ + public String toString(){ + String str = "< " + this.entity.toString() + " >"; + for (AffectationImp affectation : this.affs) { + str+= affectation.toString(); + } + str+= "."; + return str; + } + } record AffectationImp(EntityImp entity, List complements) implements Affectation{} record Complement_EntityImp(EntityImp entity) implements Complement{} record Complement_TextImp(String string) implements Complement{ @@ -27,46 +36,4 @@ public class ASD_Turtle implements TurtleASD { } } - record EntityImp(String string) implements Entity{ - public String toString(){ - return this.string; - } - } - - public void prettyPrinter(TurtleImp t){ - for (PhraseImp phrase : t.phrases) { - prettyPrinter(phrase); - } - } - - public void prettyPrinter(PhraseImp phrase){ - System.out.println("< " + phrase.entity + " >"); - for (AffectationImp affectation : phrase.affs) { - prettyPrinter(affectation); - } - System.out.println("."); - } - public void prettyPrinter(AffectationImp affectation){ - System.out.println("< " + affectation.entity + " >"); - for (int i =0; i < affectation.complements.size(); i++) { - prettyPrinter(affectation.complements.get(i)); - if (i < affectation.complements.size() - 1) { - System.out.print(", "); - } - } - System.out.println(";"); - } - public void prettyPrinter(Complement complement){ - if( complement instanceof Complement_EntityImp ce){ - System.out.println(" < " + ce.entity + " >"); - } else if ( complement instanceof Complement_TextImp ct){ - System.out.println(" \" " + ct.string + " \""); - } - - - } - public void prettyPrint(EntityImp entity) { - System.out.print(entity.string); - } - }