@@ -0,0 +1,2212 @@
+/*%0A * JSONArrayBuilder.java%0A *%0A * Copyright (C) 2009-17 by RStudio, Inc.%0A *%0A * Unless you have received this program directly from RStudio pursuant%0A * to the terms of a commercial license agreement with RStudio, then%0A * this program is licensed to you under the terms of version 3 of the%0A * GNU Affero General Public License. This program is distributed WITHOUT%0A * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,%0A * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the%0A * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.%0A *%0A */%0Apackage org.rstudio.studio.client.common;%0A%0Aimport com.google.gwt.core.client.JsArrayString;%0Aimport com.google.gwt.json.client.JSONArray;%0Aimport com.google.gwt.json.client.JSONBoolean;%0Aimport com.google.gwt.json.client.JSONNull;%0Aimport com.google.gwt.json.client.JSONNumber;%0Aimport com.google.gwt.json.client.JSONString;%0Aimport com.google.gwt.json.client.JSONValue;%0A%0Apublic class JSONArrayBuilder%0A%7B%0A   public JSONArrayBuilder()%0A   %7B%0A      array_ = new JSONArray();%0A      index_ = 0;%0A   %7D%0A   %0A   public final JSONArray get()%0A   %7B%0A      return array_;%0A   %7D%0A   %0A   public final JSONArrayBuilder add(String value)%0A   %7B%0A      append(fromString(value));%0A      return this;%0A   %7D%0A   %0A   public final JSONArrayBuilder add(boolean value)%0A   %7B%0A      append(JSONBoolean.getInstance(value));%0A      return this;%0A   %7D%0A   %0A   public final JSONArrayBuilder add(int value)%0A   %7B%0A      append(new JSONNumber(value));%0A      return this;%0A   %7D%0A   %0A   public final JSONArrayBuilder add(double value)%0A   %7B%0A      append(new JSONNumber(value));%0A      return this;%0A   %7D%0A   %0A   public final JSONArrayBuilder add(JsArrayString value)%0A   %7B%0A      JSONArray array = new JSONArray();%0A      for (int i = 0, n = value.length(); i %3C n; i++)%0A         array.set(i, fromString(value.get(i)));%0A      append(array);%0A      return this;%0A   %7D%0A   %0A   private final JSONValue fromString(String value)%0A   %7B%0A      return (value == null)%0A            ? JSONNull.getInstance()%0A            : new JSONString(value);%0A   %7D%0A   %0A   private final void append(JSONValue value)%0A   %7B%0A      array_.set(index_++, value);%0A   %7D%0A   %0A   private final JSONArray array_;%0A   private int index_;%0A%7D%0A

add JSON array builder helper