class ExecutionPlanConverter {

    public static MapValue convert( ExecutionPlanDescription plan )
    {
        boolean hasProfilerStatistics = plan.hasProfilerStatistics();
        int size = hasProfilerStatistics ? 9 : 4;
        MapValueBuilder out = new MapValueBuilder( size );
        out.add( "operatorType", stringValue( plan.getName() ) );
        out.add( "args", ValueUtils.asMapValue( plan.getArguments() ) );
        out.add( "identifiers", ValueUtils.asListValue( plan.getIdentifiers() ) );
        out.add( "children", children( plan ) );
        if ( hasProfilerStatistics )
        {
            ExecutionPlanDescription.ProfilerStatistics profile = plan.getProfilerStatistics();
            out.add( "dbHits", longValue( profile.getDbHits() ) );
            out.add( "pageCacheHits", longValue( profile.getPageCacheHits() ) );
            out.add( "pageCacheMisses", longValue( profile.getPageCacheMisses() ) );
            out.add( "pageCacheHitRatio", doubleValue( profile.getPageCacheHitRatio() ) );
            out.add( "rows", longValue( profile.getRows() ) );
        }
        return out.build();
    }

    private  ExecutionPlanConverter();

}