/**
 * Copyright (c) 2013, Groupon, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * Neither the name of GROUPON nor the names of its contributors may be
 * used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 * Created with IntelliJ IDEA.
 * User: Dima Kovalenko (@dimacus) && Darko Marinov
 * Date: 5/10/13
 * Time: 4:06 PM
 */

package com.groupon;

import org.json.simple.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonResponseBuilder {


  private Map<String, String> keyDescriptions = new HashMap<String, String>();
  private JSONObject keyValues = new JSONObject();

  public JsonResponseBuilder(){
    keyDescriptions.put("error","Error recived during execution of command");
    keyDescriptions.put("exit_code", "Exit code for operation");
    keyDescriptions.put("out", "All of the StandardOut received from the system");

    addKeyValues("exit_code", 0);
    addKeyValues("out", "");
    addKeyValues("error", "");
  }

  public void addKeyDescriptions(String key, String description){
    keyDescriptions.put(key, description);
    addKeyValues(key, "");
  }

  public void addKeyValues(String key, String value){
    keyValues.put(key, value);
  }

  public void addKeyValues(String key, Boolean value){
    keyValues.put(key, value);
  }

  public void addKeyValues(String key, Map value){
    keyValues.put(key, value);
  }

  public void addKeyValues(String key, int value){
    keyValues.put(key, value);
  }

  public void addKeyValues(String key, List<String> value){
    keyValues.put(key, value);
  }

  public String toString(){
    return keyValues.toJSONString();
  }

  protected Map<String, String> getKeyDescriptions(){
    return keyDescriptions;
  }


}

@@ -1748,16 +1748,45 @@
 ashMap;%0A
+import java.util.LinkedList;%0A
 import j
@@ -2021,16 +2021,17 @@
 uilder()
+ 
 %7B%0A    ke
@@ -2056,16 +2056,17 @@
 %22error%22,
+ 
 %22Error r
@@ -2252,16 +2252,101 @@
 tem%22);%0A%0A
+    List%3CString%3E out = new LinkedList();%0A    List%3CString%3E error = new LinkedList();%0A%0A
     addK
@@ -2395,18 +2395,19 @@
 (%22out%22, 
-%22%22
+out
 );%0A    a
@@ -2427,26 +2427,29 @@
 error%22, 
-%22%22
+error
 );%0A  %7D%0A%0A
   public
@@ -2432,32 +2432,33 @@
 %22, error);%0A  %7D%0A%0A
+%0A
   public void ad
@@ -2505,16 +2505,17 @@
 ription)
+ 
 %7B%0A    ke
@@ -2631,26 +2631,242 @@
 tring value)
+ 
 %7B%0A
+%0A    List%3CString%3E valueArray = convertLineToArray(value);%0A%0A    if (key.equals(%22out%22)) %7B%0A      addKeyValues(key, valueArray);%0A    %7D else if (key.equals(%22error%22)) %7B%0A      addKeyValues(key, valueArray);%0A    %7D else %7B%0A  
     keyValue
@@ -2873,34 +2873,47 @@
 s.put(key, value
-);
+Array);%0A    %7D%0A%0A
 %0A  %7D%0A%0A  public v
@@ -2951,24 +2951,25 @@
 olean value)
+ 
 %7B%0A    keyVal
@@ -3039,24 +3039,25 @@
 , Map value)
+ 
 %7B%0A    keyVal
@@ -3127,24 +3127,25 @@
 , int value)
+ 
 %7B%0A    keyVal
@@ -3228,16 +3228,17 @@
 %3E value)
+ 
 %7B%0A    ke
@@ -3293,16 +3293,17 @@
 String()
+ 
 %7B%0A    re
@@ -3390,16 +3390,17 @@
 ptions()
+ 
 %7B%0A    re
@@ -3426,11 +3426,253 @@
 s;%0A  %7D%0A%0A
+  private List%3CString%3E convertLineToArray(String input) %7B%0A    List output = new LinkedList%3CString%3E();%0A%0A    String stdOutLines%5B%5D = input.split(%22%5Cn%22);%0A    for (String line : stdOutLines) %7B%0A      output.add(line);%0A    %7D%0A%0A    return output;%0A  %7D%0A%0A
 %0A%7D%0A

Change standard out to break into an array instead of a 1 long list