package com.github.diegopacheco.dynomite.cluster.checker.util;

import java.util.List;

import com.github.diegopacheco.dynomite.cluster.checker.ResultReport;

/**
 * Pritns a list of JsonPrinter in Json.
 * @author diegopacheco
 * @since 01/07/2016
 * @version 1.0
 *
 */
public class ListJsonPrinter {
	
	public static String print(ResultReport rr){
		List<? extends JsonPrinter> list = rr.getNodesReport();
		if (list.size()==1) return list.get(0).toPrettyJson();
		
		StringBuffer sb = new StringBuffer("{\n\r");
		sb.append(" \"failoverStatus\": \"" + rr.getFailoverStatus() +  "\",\n\r");
		Object[] array = list.toArray();
		sb.append("[\n\r");
		for(int i=0;i<array.length;i++){
			sb.append( ((JsonPrinter)array[i]).toPrettyJson() + ( (i+1<array.length) ? ",\n\r" : "\n\r") );
		}
		sb.append("]\n\r");
		sb.append("}\n\r");
		return sb.toString();
	}
	
}

@@ -587,16 +587,54 @@
 %5Cn%5Cr%22);%0A
+%09%09sb.append(%22 %5C%22nodesReport%5C%22:%5Cn%5Cr%22);%0A
 %09%09Object

make json format pretty again...