Author: agiraudet Date: 2013-04-30 12:20:18 +0200 (Tue, 30 Apr 2013) New Revision: 604 Url: http://nuiton.org/projects/sandbox/repository/revisions/604 Log: correction du fichier uml4.yaml (ne pouvais pas etre parse correctement) et ajout d'une methode affichant l'arbre des type des objets d'un document yaml (parcourirClass:testsnakeyaml.java) Modified: testEugeneUML-YAML/testsnakeyaml/src/main/java/testsnakeyaml.java testEugeneUML-YAML/testsnakeyaml/uml4.yaml Modified: testEugeneUML-YAML/testsnakeyaml/src/main/java/testsnakeyaml.java =================================================================== --- testEugeneUML-YAML/testsnakeyaml/src/main/java/testsnakeyaml.java 2013-04-29 15:50:54 UTC (rev 603) +++ testEugeneUML-YAML/testsnakeyaml/src/main/java/testsnakeyaml.java 2013-04-30 10:20:18 UTC (rev 604) @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.Map; // http://code.google.com/p/snakeyaml/wiki/Documentation @@ -65,6 +66,61 @@ } } + public static void parcourirClass(Object obj, String indent, int type) + { + if(obj instanceof Map.Entry) + { + parcourirClass(((Map.Entry) obj).getKey(), indent + " ",1); + parcourirClass(((Map.Entry) obj).getValue(), indent + " ",2); + } + else if(obj instanceof Map) + { + afficherClass(obj,indent,type); + parcourirClass(((Map) obj).entrySet(), indent + " ",0); + } + else if (obj instanceof Iterable) + { + afficherClass(obj,indent,type); + for (Object tmp : (Iterable) obj) + { + parcourirClass(tmp, indent + " ",0); + } + } + else + { + afficherClass(obj,indent,type); + } + } + + public void afficherClass() + { + this.parcourirClass(this.data,"",0); + + } + + public static void afficherClass(Object obj, String indent, int type) + { + if (obj == null) + { + System.out.println(indent+"null"); + } + else + { + if(type == 1) + { + System.out.println(indent+"[KEY] "+obj.getClass()); + } + else if(type == 2) + { + System.out.println(indent+"[VALUE] "+obj.getClass()); + } + else + { + System.out.println(indent+obj.getClass()); + } + } + } + public String toString() { return this.yaml.dump(this.data); @@ -72,6 +128,8 @@ public static void main (String[] args) throws IOException { //new testsnakeyaml("uml4.yaml").afficher(); - System.out.println(new testsnakeyaml("uml4.yaml").toString()); + //System.out.println(new testsnakeyaml("uml4.yaml").toString()); + // afficher arbre des objets // pattern composit + new testsnakeyaml("uml4.yaml").afficherClass(); } } Modified: testEugeneUML-YAML/testsnakeyaml/uml4.yaml =================================================================== --- testEugeneUML-YAML/testsnakeyaml/uml4.yaml 2013-04-29 15:50:54 UTC (rev 603) +++ testEugeneUML-YAML/testsnakeyaml/uml4.yaml 2013-04-30 10:20:18 UTC (rev 604) @@ -43,8 +43,8 @@ - String chaine - Classe4 [0..*] [label1] - tagvalues: - key1: value1 - key2: value2 + key1: value1 + key2: value2 - coments: - comment1 - comment2