All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.minijson.tool.profiler.SampleJsonCompatibleArray Maven / Gradle / Ivy

The newest version!
package org.minijson.tool.profiler;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.minijson.JsonCompatible;
import org.minijson.builder.JsonBuilderException;


public class SampleJsonCompatibleArray implements JsonCompatible
{

    public SampleJsonCompatibleArray()
    {
    }

//    @Override
//    public boolean isJsonStructureArray()
//    {
//        return true;
//    }

    @Override
    public Object toJsonStructure() throws JsonBuilderException
    {
        return toJsonStructure(1);
    }

    @Override
    public Object toJsonStructure(int depth) throws JsonBuilderException
    {
        List list = new ArrayList();
        Map map = new LinkedHashMap();
        if(depth > 0) {
            list.add(map);
            if(depth > 1) {
                map.put("k1", "v1");
                if(depth > 2) {
                    Map map2 = new LinkedHashMap();
                    map2.put("x1", "y1");
                    map.put("k2", map2);
                    if(depth > 3) {
                        Map map3 = new LinkedHashMap();
                        map3.put("m1", "n1");
                        map2.put("x2", map3);
                    }
                }
            }        
        }        
        return list;
    }

    @Override
    public String toString()
    {
        return "SampleJsonCompatibleArray []";
    }

}