package org.javaz.uml;

import org.javaz.util.GenericDeepComparator;
import org.javaz.util.JsonUtil;
import org.javaz.util.MapValueProducer;

import java.io.FileWriter;
import java.util.*;

/**
 * This is helper to parse Violet UML .class files
 */
public class VioletParser
{

    public static HashMap parseVioletModel(String fileInNew)
    {
        BasicVioletParser vp = null;
        if (fileInNew.endsWith(".json"))
        {
            vp = new JsonVioletParser();
        }
        else if (fileInNew.endsWith(".html"))
        {
            vp = new NewVioletParser();
        }
        else
        {
            vp = new OldVioletParser();
        }
        return vp.parseVioletClass(fileInNew);
    }

    public static void main(String[] args) throws Exception
    {
        if (args.length != 2)
        {
            System.out.println("Please, specify two parameters - in violet model file and out json file");
            System.exit(0);
        }

        HashMap<String, Object> model = parseVioletModel(args[0]);

        ArrayList<Map> allBeans = (ArrayList<Map>) model.get("beans");
        GenericDeepComparator c = new GenericDeepComparator();
        c.setProducerI(new MapValueProducer("name"));
        Collections.sort(allBeans, c);
        for (Map bean : allBeans) {
            ArrayList<Map> attributes = (ArrayList<Map>) bean.get("attributes");
            Collections.sort(attributes, c);
        }

        FileWriter fw = new FileWriter(args[1]);
        fw.write(JsonUtil.convertToJS(model, true, true));
        fw.close();
    }
}

@@ -1097,24 +1097,26 @@
 t(%22beans%22);%0A
+%0A%0A
         Gene
@@ -1133,17 +1133,31 @@
 parator 
-c
+beansComparator
  = new G
@@ -1188,17 +1188,31 @@
         
-c
+beansComparator
 .setProd
@@ -1244,24 +1244,25 @@
 r(%22name%22));%0A
+%0A
         Coll
@@ -1284,20 +1284,35 @@
 lBeans, 
-c
+beansComparator
 );%0A
+%0A
         
@@ -1416,24 +1416,355 @@
 tributes%22);%0A
+%0A            GenericDeepComparator c = new GenericDeepComparator();%0A            c.setProducerI(new MapValueProducer(%22primary_key%22));%0A            c.setInverted(true);%0A%0A            GenericDeepComparator c2 = new GenericDeepComparator();%0A            c.setSecondarySort(c2);%0A            c2.setProducerI(new MapValueProducer(%22name%22));%0A%0A
             

Make JSON from UML be sorted by name + attributes sorted by primary_key, then by name