geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [2/8] geode git commit: Revert "GEODE-2142: Spotless"
Date Fri, 17 Feb 2017 21:58:10 GMT
http://git-wip-us.apache.org/repos/asf/geode/blob/1253d780/geode-json/src/main/java/org/json/JSONObject.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONObject.java b/geode-json/src/main/java/org/json/JSONObject.java
index bddfb56..d5de19f 100755
--- a/geode-json/src/main/java/org/json/JSONObject.java
+++ b/geode-json/src/main/java/org/json/JSONObject.java
@@ -1,15 +1,17 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
  *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 package org.json;
@@ -31,53 +33,55 @@ import java.util.TreeMap;
 // Note: this class was written without inspecting the non-free org.json sourcecode.
 
 /**
- * A modifiable set of name/value mappings. Names are unique, non-null strings. Values may be any
- * mix of {@link JSONObject JSONObjects}, {@link JSONArray JSONArrays}, Strings, Booleans, Integers,
- * Longs, Doubles or {@link #NULL}. Values may not be {@code null}, {@link Double#isNaN() NaNs},
- * {@link Double#isInfinite() infinities}, or of any type not listed here.
+ * A modifiable set of name/value mappings. Names are unique, non-null strings.
+ * Values may be any mix of {@link JSONObject JSONObjects}, {@link JSONArray
+ * JSONArrays}, Strings, Booleans, Integers, Longs, Doubles or {@link #NULL}.
+ * Values may not be {@code null}, {@link Double#isNaN() NaNs}, {@link
+ * Double#isInfinite() infinities}, or of any type not listed here.
  *
- * <p>
- * This class can coerce values to another type when requested.
+ * <p>This class can coerce values to another type when requested.
  * <ul>
- * <li>When the requested type is a boolean, strings will be coerced using a case-insensitive
- * comparison to "true" and "false".
- * <li>When the requested type is a double, other {@link Number} types will be coerced using
- * {@link Number#doubleValue() doubleValue}. Strings that can be coerced using
- * {@link Double#valueOf(String)} will be.
- * <li>When the requested type is an int, other {@link Number} types will be coerced using
- * {@link Number#intValue() intValue}. Strings that can be coerced using
- * {@link Double#valueOf(String)} will be, and then cast to int.
- * <li><a name="lossy">When the requested type is a long, other {@link Number} types will be coerced
- * using {@link Number#longValue() longValue}. Strings that can be coerced using
- * {@link Double#valueOf(String)} will be, and then cast to long. This two-step conversion is lossy
- * for very large values. For example, the string "9223372036854775806" yields the long
- * 9223372036854775807.</a>
- * <li>When the requested type is a String, other non-null values will be coerced using
- * {@link String#valueOf(Object)}. Although null cannot be coerced, the sentinel value
- * {@link JSONObject#NULL} is coerced to the string "null".
+ * <li>When the requested type is a boolean, strings will be coerced using a
+ * case-insensitive comparison to "true" and "false".
+ * <li>When the requested type is a double, other {@link Number} types will
+ * be coerced using {@link Number#doubleValue() doubleValue}. Strings
+ * that can be coerced using {@link Double#valueOf(String)} will be.
+ * <li>When the requested type is an int, other {@link Number} types will
+ * be coerced using {@link Number#intValue() intValue}. Strings
+ * that can be coerced using {@link Double#valueOf(String)} will be,
+ * and then cast to int.
+ * <li><a name="lossy">When the requested type is a long, other {@link Number} types will
+ * be coerced using {@link Number#longValue() longValue}. Strings
+ * that can be coerced using {@link Double#valueOf(String)} will be,
+ * and then cast to long. This two-step conversion is lossy for very
+ * large values. For example, the string "9223372036854775806" yields the
+ * long 9223372036854775807.</a>
+ * <li>When the requested type is a String, other non-null values will be
+ * coerced using {@link String#valueOf(Object)}. Although null cannot be
+ * coerced, the sentinel value {@link JSONObject#NULL} is coerced to the
+ * string "null".
  * </ul>
  *
- * <p>
- * This class can look up both mandatory and optional values:
+ * <p>This class can look up both mandatory and optional values:
  * <ul>
- * <li>Use <code>get<i>Type</i>()</code> to retrieve a mandatory value. This fails with a
- * {@code JSONException} if the requested name has no value or if the value cannot be coerced to the
- * requested type.
- * <li>Use <code>opt<i>Type</i>()</code> to retrieve an optional value. This returns a system- or
- * user-supplied default if the requested name has no value or if the value cannot be coerced to the
- * requested type.
+ * <li>Use <code>get<i>Type</i>()</code> to retrieve a mandatory value. This
+ * fails with a {@code JSONException} if the requested name has no value
+ * or if the value cannot be coerced to the requested type.
+ * <li>Use <code>opt<i>Type</i>()</code> to retrieve an optional value. This
+ * returns a system- or user-supplied default if the requested name has no
+ * value or if the value cannot be coerced to the requested type.
  * </ul>
  *
- * <p>
- * <strong>Warning:</strong> this class represents null in two incompatible ways: the standard Java
- * {@code null} reference, and the sentinel value {@link JSONObject#NULL}. In particular, calling
- * {@code put(name, null)} removes the named entry from the object but
- * {@code put(name, JSONObject.NULL)} stores an entry whose value is {@code JSONObject.NULL}.
+ * <p><strong>Warning:</strong> this class represents null in two incompatible
+ * ways: the standard Java {@code null} reference, and the sentinel value {@link
+ * JSONObject#NULL}. In particular, calling {@code put(name, null)} removes the
+ * named entry from the object but {@code put(name, JSONObject.NULL)} stores an
+ * entry whose value is {@code JSONObject.NULL}.
  *
- * <p>
- * Instances of this class are not thread safe. Although this class is nonfinal, it was not designed
- * for inheritance and should not be subclassed. In particular, self-use by overrideable methods is
- * not specified. See <i>Effective Java</i> Item 17, "Design and Document or inheritance or else
+ * <p>Instances of this class are not thread safe. Although this class is
+ * nonfinal, it was not designed for inheritance and should not be subclassed.
+ * In particular, self-use by overrideable methods is not specified. See
+ * <i>Effective Java</i> Item 17, "Design and Document or inheritance or else
  * prohibit it" for further information.
  */
 public class JSONObject {
@@ -88,8 +92,8 @@ public class JSONObject {
   public static ThreadLocal<Boolean> cyclicDepChkEnabled = new ThreadLocal();
 
   /**
-   * A sentinel value used to explicitly define a name with no value. Unlike {@code null}, names
-   * with this value:
+   * A sentinel value used to explicitly define a name with no value. Unlike
+   * {@code null}, names with this value:
    * <ul>
    * <li>show up in the {@link #names} array
    * <li>show up in the {@link #keys} iterator
@@ -98,9 +102,9 @@ public class JSONObject {
    * <li>are included in the encoded JSON string.
    * </ul>
    *
-   * <p>
-   * This value violates the general contract of {@link Object#equals} by returning true when
-   * compared to {@code null}. Its {@link #toString} method returns "null".
+   * <p>This value violates the general contract of {@link Object#equals} by
+   * returning true when compared to {@code null}. Its {@link #toString}
+   * method returns "null".
    */
   public static final Object NULL = new Object() {
     @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@@ -131,21 +135,21 @@ public class JSONObject {
   }
 
   /**
-   * Creates a new {@code JSONObject} by copying all name/value mappings from the given map.
-   * 
+   * Creates a new {@code JSONObject} by copying all name/value mappings from
+   * the given map.
    * @param copyFrom a map whose keys are of type {@link String} and whose values are of supported
-   *        types.
+   * types.
    * @throws NullPointerException if any of the map's keys are null.
    */
-  /* (accept a raw type for API compatibility) */
+    /* (accept a raw type for API compatibility) */
   public JSONObject(Map copyFrom) {
     this();
     Map<?, ?> contentsTyped = (Map<?, ?>) copyFrom;
     for (Map.Entry<?, ?> entry : contentsTyped.entrySet()) {
-      /*
-       * Deviate from the original by checking that keys are non-null and of the proper type. (We
-       * still defer validating the values).
-       */
+            /*
+             * Deviate from the original by checking that keys are non-null and
+             * of the proper type. (We still defer validating the values).
+             */
       String key = (String) entry.getKey();
       if (key == null) {
         throw new NullPointerException("key == null");
@@ -155,16 +159,16 @@ public class JSONObject {
   }
 
   /**
-   * Creates a new {@code JSONObject} with name/value mappings from the next object in the tokener.
-   * 
+   * Creates a new {@code JSONObject} with name/value mappings from the next
+   * object in the tokener.
    * @param readFrom a tokener whose nextValue() method will yield a {@code JSONObject}.
    * @throws JSONException if the parse fails or doesn't yield a {@code JSONObject}.
    */
   public JSONObject(JSONTokener readFrom) throws JSONException {
-    /*
-     * Getting the parser to populate this could get tricky. Instead, just parse to temporary
-     * JSONObject and then steal the data from that.
-     */
+        /*
+         * Getting the parser to populate this could get tricky. Instead, just
+         * parse to temporary JSONObject and then steal the data from that.
+         */
     Object object = readFrom.nextValue();
     if (object instanceof JSONObject) {
       this.nameValuePairs = ((JSONObject) object).nameValuePairs;
@@ -174,8 +178,8 @@ public class JSONObject {
   }
 
   /**
-   * Creates a new {@code JSONObject} with name/value mappings from the JSON string.
-   * 
+   * Creates a new {@code JSONObject} with name/value mappings from the JSON
+   * string.
    * @param json a JSON-encoded string containing an object.
    * @throws JSONException if the parse fails or doesn't yield a {@code JSONObject}.
    */
@@ -184,9 +188,9 @@ public class JSONObject {
   }
 
   /**
-   * Creates a new {@code JSONObject} by copying mappings for the listed names from the given
-   * object. Names that aren't present in {@code copyFrom} will be skipped.
-   * 
+   * Creates a new {@code JSONObject} by copying mappings for the listed names
+   * from the given object. Names that aren't present in {@code copyFrom} will
+   * be skipped.
    * @param copyFrom The source object.
    * @param names The names of the fields to copy.
    * @throws JSONException On internal errors. Shouldn't happen.
@@ -203,7 +207,6 @@ public class JSONObject {
 
   /**
    * Creates a json object from a bean
-   * 
    * @param bean the bean to create the json object from
    * @throws JSONException If there is an exception while reading the bean
    */
@@ -211,7 +214,7 @@ public class JSONObject {
     this(propertiesAsMap(bean));
   }
 
-  // This is custom properties mapping specific for GEODE
+  //This is custom properties mapping specific for GEODE
   private static Map<String, Object> propertiesAsMap(Object bean) {
     Map<String, Object> props = new TreeMap();
     Class klass = bean.getClass();
@@ -270,7 +273,6 @@ public class JSONObject {
 
   /**
    * Returns the number of name/value mappings in this object.
-   * 
    * @return the length of this.
    */
   public int length() {
@@ -278,9 +280,8 @@ public class JSONObject {
   }
 
   /**
-   * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same
-   * name.
-   * 
+   * Maps {@code name} to {@code value}, clobbering any existing name/value
+   * mapping with the same name.
    * @param name The name of the value to insert.
    * @param value The value to insert.
    * @return this object.
@@ -292,12 +293,11 @@ public class JSONObject {
   }
 
   /**
-   * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same
-   * name.
-   * 
+   * Maps {@code name} to {@code value}, clobbering any existing name/value
+   * mapping with the same name.
    * @param name The name for the new value.
-   * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
-   *        {@link Double#isInfinite() infinities}.
+   * @param value a finite value. May not be {@link Double#isNaN() NaNs} or {@link
+   * Double#isInfinite() infinities}.
    * @return this object.
    * @throws JSONException if value is NaN or infinite.
    */
@@ -307,9 +307,8 @@ public class JSONObject {
   }
 
   /**
-   * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same
-   * name.
-   * 
+   * Maps {@code name} to {@code value}, clobbering any existing name/value
+   * mapping with the same name.
    * @param name The name for the new value.
    * @param value The new value.
    * @return this object.
@@ -321,9 +320,8 @@ public class JSONObject {
   }
 
   /**
-   * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same
-   * name.
-   * 
+   * Maps {@code name} to {@code value}, clobbering any existing name/value
+   * mapping with the same name.
    * @param name The name of the new value.
    * @param value The new value to insert.
    * @return this object.
@@ -335,13 +333,13 @@ public class JSONObject {
   }
 
   /**
-   * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same
-   * name. If the value is {@code null}, any existing mapping for {@code name} is removed.
-   * 
+   * Maps {@code name} to {@code value}, clobbering any existing name/value
+   * mapping with the same name. If the value is {@code null}, any existing
+   * mapping for {@code name} is removed.
    * @param name The name of the new value.
    * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double,
-   *        {@link #NULL}, or {@code null}. May not be {@link Double#isNaN() NaNs} or
-   *        {@link Double#isInfinite() infinities}.
+   * {@link #NULL}, or {@code null}. May not be {@link Double#isNaN() NaNs} or {@link
+   * Double#isInfinite() infinities}.
    * @return this object.
    * @throws JSONException if the value is an invalid double (infinite or NaN).
    */
@@ -373,9 +371,8 @@ public class JSONObject {
   }
 
   /**
-   * Equivalent to {@code put(name, value)} when both parameters are non-null; does nothing
-   * otherwise.
-   * 
+   * Equivalent to {@code put(name, value)} when both parameters are non-null;
+   * does nothing otherwise.
    * @param name The name of the value to insert.
    * @param value The value to insert.
    * @return this object.
@@ -389,21 +386,22 @@ public class JSONObject {
   }
 
   /**
-   * Appends {@code value} to the array already mapped to {@code name}. If this object has no
-   * mapping for {@code name}, this inserts a new mapping. If the mapping exists but its value is
-   * not an array, the existing and new values are inserted in order into a new array which is
-   * itself mapped to {@code name}. In aggregate, this allows values to be added to a mapping one at
-   * a time.
+   * Appends {@code value} to the array already mapped to {@code name}. If
+   * this object has no mapping for {@code name}, this inserts a new mapping.
+   * If the mapping exists but its value is not an array, the existing
+   * and new values are inserted in order into a new array which is itself
+   * mapped to {@code name}. In aggregate, this allows values to be added to a
+   * mapping one at a time.
    *
-   * Note that {@code append(String, Object)} provides better semantics. In particular, the mapping
-   * for {@code name} will <b>always</b> be a {@link JSONArray}. Using {@code accumulate} will
-   * result in either a {@link JSONArray} or a mapping whose type is the type of {@code value}
+   * Note that {@code append(String, Object)} provides better semantics.
+   * In particular, the mapping for {@code name} will <b>always</b> be a
+   * {@link JSONArray}. Using {@code accumulate} will result in either a
+   * {@link JSONArray} or a mapping whose type is the type of {@code value}
    * depending on the number of calls to it.
-   * 
    * @param name The name of the field to change.
    * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double,
-   *        {@link #NULL} or null. May not be {@link Double#isNaN() NaNs} or
-   *        {@link Double#isInfinite() infinities}.
+   * {@link #NULL} or null. May not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
+   * infinities}.
    * @return this object after mutation.
    * @throws JSONException If the object being added is an invalid number.
    */
@@ -428,15 +426,15 @@ public class JSONObject {
   }
 
   /**
-   * Appends values to the array mapped to {@code name}. A new {@link JSONArray} mapping for
-   * {@code name} will be inserted if no mapping exists. If the existing mapping for {@code name} is
-   * not a {@link JSONArray}, a {@link JSONException} will be thrown.
-   * 
+   * Appends values to the array mapped to {@code name}. A new {@link JSONArray}
+   * mapping for {@code name} will be inserted if no mapping exists. If the existing
+   * mapping for {@code name} is not a {@link JSONArray}, a {@link JSONException}
+   * will be thrown.
    * @param name The name of the array to which the value should be appended.
    * @param value The value to append.
    * @return this object.
    * @throws JSONException if {@code name} is {@code null} or if the mapping for {@code name} is
-   *         non-null and is not a {@link JSONArray}.
+   * non-null and is not a {@link JSONArray}.
    */
   public JSONObject append(String name, Object value) throws JSONException {
     Object current = nameValuePairs.get(checkName(name));
@@ -466,7 +464,6 @@ public class JSONObject {
 
   /**
    * Removes the named mapping if it exists; does nothing otherwise.
-   * 
    * @param name The name of the mapping to remove.
    * @return the value previously mapped by {@code name}, or null if there was no such mapping.
    */
@@ -475,9 +472,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns true if this object has no mapping for {@code name} or if it has a mapping whose value
-   * is {@link #NULL}.
-   * 
+   * Returns true if this object has no mapping for {@code name} or if it has
+   * a mapping whose value is {@link #NULL}.
    * @param name The name of the value to check on.
    * @return true if the field doesn't exist or is null.
    */
@@ -487,8 +483,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns true if this object has a mapping for {@code name}. The mapping may be {@link #NULL}.
-   * 
+   * Returns true if this object has a mapping for {@code name}. The mapping
+   * may be {@link #NULL}.
    * @param name The name of the value to check on.
    * @return true if this object has a field named {@code name}
    */
@@ -498,7 +494,6 @@ public class JSONObject {
 
   /**
    * Returns the value mapped by {@code name}, or throws if no such mapping exists.
-   * 
    * @param name The name of the value to get.
    * @return The value.
    * @throws JSONException if no such mapping exists.
@@ -512,8 +507,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name}, or null if no such mapping exists.
-   * 
+   * Returns the value mapped by {@code name}, or null if no such mapping
+   * exists.
    * @param name The name of the value to get.
    * @return The value.
    */
@@ -522,9 +517,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a boolean or can be coerced to a
-   * boolean, or throws otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a boolean or
+   * can be coerced to a boolean, or throws otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    * @throws JSONException if the mapping doesn't exist or cannot be coerced to a boolean.
@@ -539,9 +533,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a boolean or can be coerced to a
-   * boolean, or false otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a boolean or
+   * can be coerced to a boolean, or false otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    */
@@ -550,9 +543,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a boolean or can be coerced to a
-   * boolean, or {@code fallback} otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a boolean or
+   * can be coerced to a boolean, or {@code fallback} otherwise.
    * @param name The name of the field we want.
    * @param fallback The value to return if the field isn't there.
    * @return The selected value or the fallback.
@@ -564,9 +556,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a double or can be coerced to a
-   * double, or throws otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a double or
+   * can be coerced to a double, or throws otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    * @throws JSONException if the mapping doesn't exist or cannot be coerced to a double.
@@ -581,9 +572,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a double or can be coerced to a
-   * double, or {@code NaN} otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a double or
+   * can be coerced to a double, or {@code NaN} otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    */
@@ -592,9 +582,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a double or can be coerced to a
-   * double, or {@code fallback} otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a double or
+   * can be coerced to a double, or {@code fallback} otherwise.
    * @param name The name of the field we want.
    * @param fallback The value to return if the field isn't there.
    * @return The selected value or the fallback.
@@ -606,9 +595,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is an int or can be coerced to an
-   * int, or throws otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is an int or
+   * can be coerced to an int, or throws otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    * @throws JSONException if the mapping doesn't exist or cannot be coerced to an int.
@@ -623,9 +611,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is an int or can be coerced to an
-   * int, or 0 otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is an int or
+   * can be coerced to an int, or 0 otherwise.
    * @param name The name of the field we want.
    * @return The selected value if it exists.
    */
@@ -634,9 +621,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is an int or can be coerced to an
-   * int, or {@code fallback} otherwise.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is an int or
+   * can be coerced to an int, or {@code fallback} otherwise.
    * @param name The name of the field we want.
    * @param fallback The value to return if the field isn't there.
    * @return The selected value or the fallback.
@@ -648,11 +634,12 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a long or can be coerced to a
-   * long, or throws otherwise. Note that JSON represents numbers as doubles,
+   * Returns the value mapped by {@code name} if it exists and is a long or
+   * can be coerced to a long, or throws otherwise.
+   * Note that JSON represents numbers as doubles,
    *
-   * so this is <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON without loss.
-   * 
+   * so this is <a href="#lossy">lossy</a>; use strings to transfer numbers
+   * via JSON without loss.
    * @param name The name of the field that we want.
    * @return The value of the field.
    * @throws JSONException if the mapping doesn't exist or cannot be coerced to a long.
@@ -667,10 +654,9 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a long or can be coerced to a
-   * long, or 0 otherwise. Note that JSON represents numbers as doubles, so this is
-   * <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a long or
+   * can be coerced to a long, or 0 otherwise. Note that JSON represents numbers as doubles,
+   * so this is <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON.
    * @param name The name of the field we want.
    * @return The selected value.
    */
@@ -679,10 +665,10 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists and is a long or can be coerced to a
-   * long, or {@code fallback} otherwise. Note that JSON represents numbers as doubles, so this is
-   * <a href="#lossy">lossy</a>; use strings to transfer numbers via JSON.
-   * 
+   * Returns the value mapped by {@code name} if it exists and is a long or
+   * can be coerced to a long, or {@code fallback} otherwise. Note that JSON represents
+   * numbers as doubles, so this is <a href="#lossy">lossy</a>; use strings to transfer
+   * numbers via JSON.
    * @param name The name of the field we want.
    * @param fallback The value to return if the field isn't there.
    * @return The selected value or the fallback.
@@ -694,9 +680,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists, coercing it if necessary, or throws if
-   * no such mapping exists.
-   * 
+   * Returns the value mapped by {@code name} if it exists, coercing it if
+   * necessary, or throws if no such mapping exists.
    * @param name The name of the field we want.
    * @return The value of the field.
    * @throws JSONException if no such mapping exists.
@@ -711,9 +696,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists, coercing it if necessary, or the empty
-   * string if no such mapping exists.
-   * 
+   * Returns the value mapped by {@code name} if it exists, coercing it if
+   * necessary, or the empty string if no such mapping exists.
    * @param name The name of the field we want.
    * @return The value of the field.
    */
@@ -722,9 +706,8 @@ public class JSONObject {
   }
 
   /**
-   * Returns the value mapped by {@code name} if it exists, coercing it if necessary, or
-   * {@code fallback} if no such mapping exists.
-   * 
+   * Returns the value mapped by {@code name} if it exists, coercing it if
+   * necessary, or {@code fallback} if no such mapping exists.
    * @param name The name of the field that we want.
    * @param fallback The value to return if the field doesn't exist.
    * @return The value of the field or fallback.
@@ -738,7 +721,6 @@ public class JSONObject {
   /**
    * Returns the value mapped by {@code name} if it exists and is a {@code
    * JSONArray}, or throws otherwise.
-   * 
    * @param name The field we want to get.
    * @return The value of the field (if it is a JSONArray.
    * @throws JSONException if the mapping doesn't exist or is not a {@code JSONArray}.
@@ -755,7 +737,6 @@ public class JSONObject {
   /**
    * Returns the value mapped by {@code name} if it exists and is a {@code
    * JSONArray}, or null otherwise.
-   * 
    * @param name The name of the field we want.
    * @return The value of the specified field (assuming it is a JSNOArray
    */
@@ -767,7 +748,6 @@ public class JSONObject {
   /**
    * Returns the value mapped by {@code name} if it exists and is a {@code
    * JSONObject}, or throws otherwise.
-   * 
    * @param name The name of the field that we want.
    * @return a specified field value (if it is a JSONObject)
    * @throws JSONException if the mapping doesn't exist or is not a {@code JSONObject}.
@@ -784,7 +764,6 @@ public class JSONObject {
   /**
    * Returns the value mapped by {@code name} if it exists and is a {@code
    * JSONObject}, or null otherwise.
-   * 
    * @param name The name of the value we want.
    * @return The specified value.
    */
@@ -794,9 +773,9 @@ public class JSONObject {
   }
 
   /**
-   * Returns an array with the values corresponding to {@code names}. The array contains null for
-   * names that aren't mapped. This method returns null if {@code names} is either null or empty.
-   * 
+   * Returns an array with the values corresponding to {@code names}. The
+   * array contains null for names that aren't mapped. This method returns
+   * null if {@code names} is either null or empty.
    * @param names The names of the fields that we want the values for.
    * @return The selected values.
    * @throws JSONException On internal errors. Shouldn't happen.
@@ -818,11 +797,11 @@ public class JSONObject {
   }
 
   /**
-   * Returns an iterator of the {@code String} names in this object. The returned iterator supports
-   * {@link Iterator#remove() remove}, which will remove the corresponding mapping from this object.
-   * If this object is modified after the iterator is returned, the iterator's behavior is
+   * Returns an iterator of the {@code String} names in this object. The
+   * returned iterator supports {@link Iterator#remove() remove}, which will
+   * remove the corresponding mapping from this object. If this object is
+   * modified after the iterator is returned, the iterator's behavior is
    * undefined. The order of the keys is undefined.
-   * 
    * @return an iterator over the keys.
    */
   public Iterator<String> keys() {
@@ -830,12 +809,12 @@ public class JSONObject {
   }
 
   /**
-   * Returns the set of {@code String} names in this object. The returned set is a view of the keys
-   * in this object. {@link Set#remove(Object)} will remove the corresponding mapping from this
-   * object and set iterator behaviour is undefined if this object is modified after it is returned.
+   * Returns the set of {@code String} names in this object. The returned set
+   * is a view of the keys in this object. {@link Set#remove(Object)} will remove
+   * the corresponding mapping from this object and set iterator behaviour
+   * is undefined if this object is modified after it is returned.
    *
    * See {@link #keys()}.
-   * 
    * @return The names in this object.
    */
   public Set<String> keySet() {
@@ -843,22 +822,19 @@ public class JSONObject {
   }
 
   /**
-   * Returns an array containing the string names in this object. This method returns null if this
-   * object contains no mappings.
-   * 
+   * Returns an array containing the string names in this object. This method
+   * returns null if this object contains no mappings.
    * @return the names.
    */
   public JSONArray names() {
-    return nameValuePairs.isEmpty() ? null
+    return nameValuePairs.isEmpty()
+        ? null
         : new JSONArray(new ArrayList<String>(nameValuePairs.keySet()));
   }
 
   /**
    * Encodes this object as a compact JSON string, such as:
-   * 
-   * <pre>
-   * {"query":"Pizza","locations":[94043,90210]}
-   * </pre>
+   * <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
    */
   @Override
   public String toString() {
@@ -872,8 +848,8 @@ public class JSONObject {
   }
 
   /**
-   * Encodes this object as a human readable JSON string for debugging, such as:
-   * 
+   * Encodes this object as a human readable JSON string for debugging, such
+   * as:
    * <pre>
    * {
    *     "query": "Pizza",
@@ -881,9 +857,7 @@ public class JSONObject {
    *         94043,
    *         90210
    *     ]
-   * }
-   * </pre>
-   * 
+   * }</pre>
    * @param indentSpaces the number of spaces to indent for each level of nesting.
    * @return The string containing the pretty form of this.
    * @throws JSONException On internal errors. Shouldn't happen.
@@ -904,9 +878,8 @@ public class JSONObject {
 
   /**
    * Encodes the number as a JSON string.
-   * 
-   * @param number a finite value. May not be {@link Double#isNaN() NaNs} or
-   *        {@link Double#isInfinite() infinities}.
+   * @param number a finite value. May not be {@link Double#isNaN() NaNs} or {@link
+   * Double#isInfinite() infinities}.
    * @return The encoded number in string form.
    * @throws JSONException On internal errors. Shouldn't happen.
    */
@@ -932,9 +905,8 @@ public class JSONObject {
   }
 
   /**
-   * Encodes {@code data} as a JSON string. This applies quotes and any necessary character
-   * escaping.
-   * 
+   * Encodes {@code data} as a JSON string. This applies quotes and any
+   * necessary character escaping.
    * @param data the string to encode. Null will be interpreted as an empty string.
    * @return the quoted string.
    */
@@ -956,8 +928,7 @@ public class JSONObject {
   /**
    * Wraps the given object if necessary.
    *
-   * <p>
-   * If the object is null or , returns {@link #NULL}. If the object is a {@code JSONArray} or
+   * <p>If the object is null or , returns {@link #NULL}. If the object is a {@code JSONArray} or
    * {@code JSONObject}, no wrapping is necessary. If the object is {@code NULL}, no wrapping is
    * necessary. If the object is an array or {@code Collection}, returns an equivalent {@code
    * JSONArray}. If the object is a {@code Map}, returns an equivalent {@code JSONObject}. If the
@@ -965,7 +936,6 @@ public class JSONObject {
    * a {@code java} package, returns the result of {@code toString}. If the object is some other
    * kind of object then it is assumed to be a bean and is converted to a JSONObject. If wrapping
    * fails, returns null.
-   * 
    * @param o The object to wrap.
    * @return The wrapped (if necessary) form of the object {$code o}
    */
@@ -988,28 +958,34 @@ public class JSONObject {
       if (o instanceof Map) {
         return new JSONObject((Map) o);
       }
-      if (o instanceof Boolean || o instanceof Byte || o instanceof Character || o instanceof Double
-          || o instanceof Float || o instanceof Integer || o instanceof Long || o instanceof Short
-          || o instanceof String) {
+      if (o instanceof Boolean ||
+          o instanceof Byte ||
+          o instanceof Character ||
+          o instanceof Double ||
+          o instanceof Float ||
+          o instanceof Integer ||
+          o instanceof Long ||
+          o instanceof Short ||
+          o instanceof String) {
         return o;
       }
       // GEODE-2142: Added check to ignore GemFireCacheImpl
-      // if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?>) {
-      // return o.toString();
-      // }
+//      if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?>) {
+//        return o.toString();
+//      }
       Package objectPackage = o.getClass().getPackage();
       String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
-      if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.")
-          || o instanceof Enum<?> || o.getClass().getClassLoader() == null
+      if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || o instanceof Enum<?>
+          || o.getClass().getClassLoader() == null
           || o.getClass().getName().contains("GemFireCacheImpl")) {
         return o.toString();
       }
-      // if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?> ||
-      // || objectPackageName.startsWith("javax.")
-      // || o.getClass().getClassLoader() == null
-      // o.getClass().getName().contains("GemFireCacheImpl")) {
-      // return o.toString();
-      // }
+//      if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?> ||
+//          || objectPackageName.startsWith("javax.")
+//          || o.getClass().getClassLoader() == null
+//          o.getClass().getName().contains("GemFireCacheImpl")) {
+//        return o.toString();
+//      }
       // GEODE-2142: Added the cyclicalDepCheck
       if (cyclicDepChkEnabled.get() != null && cyclicDependencySet.get() != null) {
         if (cyclicDepChkEnabled.get() && cyclicDependencySet.get().contains(o)) {
@@ -1026,4 +1002,4 @@ public class JSONObject {
     }
     return null;
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/1253d780/geode-json/src/main/java/org/json/JSONString.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONString.java b/geode-json/src/main/java/org/json/JSONString.java
index 4a09d89..34815a8 100755
--- a/geode-json/src/main/java/org/json/JSONString.java
+++ b/geode-json/src/main/java/org/json/JSONString.java
@@ -1,17 +1,18 @@
 package org.json;
-
 /**
- * The <code>JSONString</code> interface allows a <code>toJSONString()</code> method so that a class
- * can change the behavior of <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>,
- * and <code>JSONWriter.value(</code>Object<code>)</code>. The <code>toJSONString</code> method will
- * be used instead of the default behavior of using the Object's <code>toString()</code> method and
- * quoting the result.
+ * The <code>JSONString</code> interface allows a <code>toJSONString()</code> 
+ * method so that a class can change the behavior of 
+ * <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>,
+ * and <code>JSONWriter.value(</code>Object<code>)</code>. The 
+ * <code>toJSONString</code> method will be used instead of the default behavior 
+ * of using the Object's <code>toString()</code> method and quoting the result.
  */
 public interface JSONString {
   /**
-   * The <code>toJSONString</code> method allows a class to produce its own JSON serialization.
+   * The <code>toJSONString</code> method allows a class to produce its own JSON 
+   * serialization. 
    * 
    * @return A strictly syntactically correct JSON text.
    */
   public String toJSONString();
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/1253d780/geode-json/src/main/java/org/json/JSONStringer.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONStringer.java b/geode-json/src/main/java/org/json/JSONStringer.java
index 43224a5..db1121e 100755
--- a/geode-json/src/main/java/org/json/JSONStringer.java
+++ b/geode-json/src/main/java/org/json/JSONStringer.java
@@ -1,15 +1,17 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
  *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 package org.json;
@@ -21,439 +23,448 @@ import java.util.List;
 // Note: this class was written without inspecting the non-free org.json sourcecode.
 
 /**
- * Implements {@link JSONObject#toString} and {@link JSONArray#toString}. Most application
- * developers should use those methods directly and disregard this API. For example:
- * 
- * <pre>
+ * Implements {@link JSONObject#toString} and {@link JSONArray#toString}. Most
+ * application developers should use those methods directly and disregard this
+ * API. For example:<pre>
  * JSONObject object = ...
- * String json = object.toString();
- * </pre>
+ * String json = object.toString();</pre>
  *
- * <p>
- * Stringers only encode well-formed JSON strings. In particular:
+ * <p>Stringers only encode well-formed JSON strings. In particular:
  * <ul>
  * <li>The stringer must have exactly one top-level array or object.
- * <li>Lexical scopes must be balanced: every call to {@link #array} must have a matching call to
- * {@link #endArray} and every call to {@link #object} must have a matching call to
- * {@link #endObject}.
+ * <li>Lexical scopes must be balanced: every call to {@link #array} must
+ * have a matching call to {@link #endArray} and every call to {@link
+ * #object} must have a matching call to {@link #endObject}.
  * <li>Arrays may not contain keys (property names).
  * <li>Objects must alternate keys (property names) and values.
- * <li>Values are inserted with either literal {@link #value(Object) value} calls, or by nesting
- * arrays or objects.
+ * <li>Values are inserted with either literal {@link #value(Object) value}
+ * calls, or by nesting arrays or objects.
  * </ul>
- * Calls that would result in a malformed JSON string will fail with a {@link JSONException}.
+ * Calls that would result in a malformed JSON string will fail with a
+ * {@link JSONException}.
  *
- * <p>
- * This class provides no facility for pretty-printing (ie. indenting) output. To encode indented
- * output, use {@link JSONObject#toString(int)} or {@link JSONArray#toString(int)}.
+ * <p>This class provides no facility for pretty-printing (ie. indenting)
+ * output. To encode indented output, use {@link JSONObject#toString(int)} or
+ * {@link JSONArray#toString(int)}.
  *
- * <p>
- * Some implementations of the API support at most 20 levels of nesting. Attempts to create more
- * than 20 levels of nesting may fail with a {@link JSONException}.
+ * <p>Some implementations of the API support at most 20 levels of nesting.
+ * Attempts to create more than 20 levels of nesting may fail with a {@link
+ * JSONException}.
  *
- * <p>
- * Each stringer may be used to encode a single top level value. Instances of this class are not
- * thread safe. Although this class is nonfinal, it was not designed for inheritance and should not
- * be subclassed. In particular, self-use by overrideable methods is not specified. See <i>Effective
- * Java</i> Item 17, "Design and Document or inheritance or else prohibit it" for further
+ * <p>Each stringer may be used to encode a single top level value. Instances of
+ * this class are not thread safe. Although this class is nonfinal, it was not
+ * designed for inheritance and should not be subclassed. In particular,
+ * self-use by overrideable methods is not specified. See <i>Effective Java</i>
+ * Item 17, "Design and Document or inheritance or else prohibit it" for further
  * information.
  */
 public class JSONStringer {
 
-  /**
-   * The output data, containing at most one top-level array or object.
-   */
-  final StringBuilder out = new StringBuilder();
-
-  /**
-   * Lexical scoping elements within this stringer, necessary to insert the appropriate separator
-   * characters (ie. commas and colons) and to detect nesting errors.
-   */
-  enum Scope {
-
     /**
-     * An array with no elements requires no separators or newlines before it is closed.
+     * The output data, containing at most one top-level array or object.
      */
-    EMPTY_ARRAY,
+    final StringBuilder out = new StringBuilder();
 
     /**
-     * A array with at least one value requires a comma and newline before the next element.
+     * Lexical scoping elements within this stringer, necessary to insert the
+     * appropriate separator characters (ie. commas and colons) and to detect
+     * nesting errors.
      */
-    NONEMPTY_ARRAY,
+    enum Scope {
+
+        /**
+         * An array with no elements requires no separators or newlines before
+         * it is closed.
+         */
+        EMPTY_ARRAY,
+
+        /**
+         * A array with at least one value requires a comma and newline before
+         * the next element.
+         */
+        NONEMPTY_ARRAY,
+
+        /**
+         * An object with no keys or values requires no separators or newlines
+         * before it is closed.
+         */
+        EMPTY_OBJECT,
+
+        /**
+         * An object whose most recent element is a key. The next element must
+         * be a value.
+         */
+        DANGLING_KEY,
+
+        /**
+         * An object with at least one name/value pair requires a comma and
+         * newline before the next element.
+         */
+        NONEMPTY_OBJECT,
+
+        /**
+         * A special bracketless array needed by JSONStringer.join() and
+         * JSONObject.quote() only. Not used for JSON encoding.
+         */
+        NULL,
+    }
 
     /**
-     * An object with no keys or values requires no separators or newlines before it is closed.
+     * Unlike the original implementation, this stack isn't limited to 20
+     * levels of nesting.
      */
-    EMPTY_OBJECT,
+    private final List<Scope> stack = new ArrayList<Scope>();
 
     /**
-     * An object whose most recent element is a key. The next element must be a value.
+     * A string containing a full set of spaces for a single level of
+     * indentation, or null for no pretty printing.
      */
-    DANGLING_KEY,
+    private final String indent;
+
+    public JSONStringer() {
+        indent = null;
+    }
+
+    JSONStringer(int indentSpaces) {
+        char[] indentChars = new char[indentSpaces];
+        Arrays.fill(indentChars, ' ');
+        indent = new String(indentChars);
+    }
 
     /**
-     * An object with at least one name/value pair requires a comma and newline before the next
-     * element.
+     * Begins encoding a new array. Each call to this method must be paired with
+     * a call to {@link #endArray}.
+     *
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
      */
-    NONEMPTY_OBJECT,
+    public JSONStringer array() throws JSONException {
+        return open(Scope.EMPTY_ARRAY, "[");
+    }
 
     /**
-     * A special bracketless array needed by JSONStringer.join() and JSONObject.quote() only. Not
-     * used for JSON encoding.
+     * Ends encoding the current array.
+     *
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
      */
-    NULL,
-  }
-
-  /**
-   * Unlike the original implementation, this stack isn't limited to 20 levels of nesting.
-   */
-  private final List<Scope> stack = new ArrayList<Scope>();
-
-  /**
-   * A string containing a full set of spaces for a single level of indentation, or null for no
-   * pretty printing.
-   */
-  private final String indent;
-
-  public JSONStringer() {
-    indent = null;
-  }
-
-  JSONStringer(int indentSpaces) {
-    char[] indentChars = new char[indentSpaces];
-    Arrays.fill(indentChars, ' ');
-    indent = new String(indentChars);
-  }
-
-  /**
-   * Begins encoding a new array. Each call to this method must be paired with a call to
-   * {@link #endArray}.
-   *
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer array() throws JSONException {
-    return open(Scope.EMPTY_ARRAY, "[");
-  }
-
-  /**
-   * Ends encoding the current array.
-   *
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer endArray() throws JSONException {
-    return close(Scope.EMPTY_ARRAY, Scope.NONEMPTY_ARRAY, "]");
-  }
-
-  /**
-   * Begins encoding a new object. Each call to this method must be paired with a call to
-   * {@link #endObject}.
-   *
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer object() throws JSONException {
-    return open(Scope.EMPTY_OBJECT, "{");
-  }
-
-  /**
-   * Ends encoding the current object.
-   *
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer endObject() throws JSONException {
-    return close(Scope.EMPTY_OBJECT, Scope.NONEMPTY_OBJECT, "}");
-  }
-
-  /**
-   * Enters a new scope by appending any necessary whitespace and the given bracket.
-   */
-  JSONStringer open(Scope empty, String openBracket) throws JSONException {
-    if (stack.isEmpty() && out.length() > 0) {
-      throw new JSONException("Nesting problem: multiple top-level roots");
-    }
-    beforeValue();
-    stack.add(empty);
-    out.append(openBracket);
-    return this;
-  }
-
-  /**
-   * Closes the current scope by appending any necessary whitespace and the given bracket.
-   */
-  JSONStringer close(Scope empty, Scope nonempty, String closeBracket) throws JSONException {
-    Scope context = peek();
-    if (context != nonempty && context != empty) {
-      throw new JSONException("Nesting problem");
+    public JSONStringer endArray() throws JSONException {
+        return close(Scope.EMPTY_ARRAY, Scope.NONEMPTY_ARRAY, "]");
     }
 
-    stack.remove(stack.size() - 1);
-    if (context == nonempty) {
-      newline();
-    }
-    out.append(closeBracket);
-    return this;
-  }
-
-  /**
-   * Returns the value on the top of the stack.
-   */
-  private Scope peek() throws JSONException {
-    if (stack.isEmpty()) {
-      throw new JSONException("Nesting problem");
-    }
-    return stack.get(stack.size() - 1);
-  }
-
-  /**
-   * Replace the value on the top of the stack with the given value.
-   */
-  private void replaceTop(Scope topOfStack) {
-    stack.set(stack.size() - 1, topOfStack);
-  }
-
-  /**
-   * Encodes {@code value}.
-   *
-   * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double or
-   *        null. May not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}.
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer value(Object value) throws JSONException {
-    if (stack.isEmpty()) {
-      throw new JSONException("Nesting problem");
+    /**
+     * Begins encoding a new object. Each call to this method must be paired
+     * with a call to {@link #endObject}.
+     *
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
+     */
+    public JSONStringer object() throws JSONException {
+        return open(Scope.EMPTY_OBJECT, "{");
     }
 
-    if (value instanceof JSONArray) {
-      ((JSONArray) value).writeTo(this);
-      return this;
+    /**
+     * Ends encoding the current object.
+     *
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
+     */
+    public JSONStringer endObject() throws JSONException {
+        return close(Scope.EMPTY_OBJECT, Scope.NONEMPTY_OBJECT, "}");
+    }
 
-    } else if (value instanceof JSONObject) {
-      ((JSONObject) value).writeTo(this);
-      return this;
+    /**
+     * Enters a new scope by appending any necessary whitespace and the given
+     * bracket.
+     */
+    JSONStringer open(Scope empty, String openBracket) throws JSONException {
+        if (stack.isEmpty() && out.length() > 0) {
+            throw new JSONException("Nesting problem: multiple top-level roots");
+        }
+        beforeValue();
+        stack.add(empty);
+        out.append(openBracket);
+        return this;
     }
 
-    beforeValue();
+    /**
+     * Closes the current scope by appending any necessary whitespace and the
+     * given bracket.
+     */
+    JSONStringer close(Scope empty, Scope nonempty, String closeBracket) throws JSONException {
+        Scope context = peek();
+        if (context != nonempty && context != empty) {
+            throw new JSONException("Nesting problem");
+        }
+
+        stack.remove(stack.size() - 1);
+        if (context == nonempty) {
+            newline();
+        }
+        out.append(closeBracket);
+        return this;
+    }
 
-    if (value instanceof JSONString) {
-      out.append(((JSONString) value).toJSONString());
-      return this;
+    /**
+     * Returns the value on the top of the stack.
+     */
+    private Scope peek() throws JSONException {
+        if (stack.isEmpty()) {
+            throw new JSONException("Nesting problem");
+        }
+        return stack.get(stack.size() - 1);
     }
 
-    if (value == null || value instanceof Boolean || value == JSONObject.NULL) {
-      out.append(value);
+    /**
+     * Replace the value on the top of the stack with the given value.
+     */
+    private void replaceTop(Scope topOfStack) {
+        stack.set(stack.size() - 1, topOfStack);
+    }
 
-    } else if (value instanceof Number) {
-      out.append(JSONObject.numberToString((Number) value));
+    /**
+     * Encodes {@code value}.
+     *
+     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
+     *              Integer, Long, Double or null. May not be {@link Double#isNaN() NaNs}
+     *              or {@link Double#isInfinite() infinities}.
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
+     */
+    public JSONStringer value(Object value) throws JSONException {
+        if (stack.isEmpty()) {
+            throw new JSONException("Nesting problem");
+        }
+
+        if (value instanceof JSONArray) {
+            ((JSONArray) value).writeTo(this);
+            return this;
+
+        } else if (value instanceof JSONObject) {
+            ((JSONObject) value).writeTo(this);
+            return this;
+        }
+
+        beforeValue();
+
+        if (value instanceof JSONString) {
+          out.append(((JSONString) value).toJSONString());
+          return this;
+        }
+
+        if (value == null
+              || value instanceof Boolean
+              || value == JSONObject.NULL) {
+            out.append(value);
+
+        } else if (value instanceof Number) {
+            out.append(JSONObject.numberToString((Number) value));
+
+        } else {
+            // Hack to make it possible that the value is not surrounded by quotes. (Used for JavaScript function calls)
+            // Example: { "name": "testkey", "value": window.myfunction() }
+            if (value.getClass().getSimpleName().contains("JSONFunction")) {
+                // note that no escaping of quotes (or anything else) is done in this case.
+                // that is fine because the only way to get to this point is to
+                // explicitly put a special kind of object into the JSON data structure.
+                out.append(value);
+            } else {
+                string(value.toString());
+            }
+        }
+
+        return this;
+    }
 
-    } else {
-      // Hack to make it possible that the value is not surrounded by quotes. (Used for JavaScript
-      // function calls)
-      // Example: { "name": "testkey", "value": window.myfunction() }
-      if (value.getClass().getSimpleName().contains("JSONFunction")) {
-        // note that no escaping of quotes (or anything else) is done in this case.
-        // that is fine because the only way to get to this point is to
-        // explicitly put a special kind of object into the JSON data structure.
+    /**
+     * Encodes {@code value} to this stringer.
+     *
+     * @param value The value to encode.
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
+     */
+    public JSONStringer value(boolean value) throws JSONException {
+        if (stack.isEmpty()) {
+            throw new JSONException("Nesting problem");
+        }
+        beforeValue();
         out.append(value);
-      } else {
-        string(value.toString());
-      }
+        return this;
     }
 
-    return this;
-  }
-
-  /**
-   * Encodes {@code value} to this stringer.
-   *
-   * @param value The value to encode.
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer value(boolean value) throws JSONException {
-    if (stack.isEmpty()) {
-      throw new JSONException("Nesting problem");
-    }
-    beforeValue();
-    out.append(value);
-    return this;
-  }
-
-  /**
-   * Encodes {@code value} to this stringer.
-   *
-   * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
-   *        {@link Double#isInfinite() infinities}.
-   * @return this stringer.
-   * @throws JSONException On internal errors. Shouldn't happen.
-   */
-  public JSONStringer value(double value) throws JSONException {
-    if (stack.isEmpty()) {
-      throw new JSONException("Nesting problem");
-    }
-    beforeValue();
-    out.append(JSONObject.numberToString(value));
-    return this;
-  }
-
-  /**
-   * Encodes {@code value} to this stringer.
-   *
-   * @param value The value to encode.
-   * @return this stringer.
-   * @throws JSONException If we have an internal error. Shouldn't happen.
-   */
-  public JSONStringer value(long value) throws JSONException {
-    if (stack.isEmpty()) {
-      throw new JSONException("Nesting problem");
+    /**
+     * Encodes {@code value} to this stringer.
+     *
+     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
+     *              {@link Double#isInfinite() infinities}.
+     * @return this stringer.
+     * @throws JSONException On internal errors. Shouldn't happen.
+     */
+    public JSONStringer value(double value) throws JSONException {
+        if (stack.isEmpty()) {
+            throw new JSONException("Nesting problem");
+        }
+        beforeValue();
+        out.append(JSONObject.numberToString(value));
+        return this;
     }
-    beforeValue();
-    out.append(value);
-    return this;
-  }
-
-  private void string(String value) {
-    out.append("\"");
-    char currentChar = 0;
-
-    for (int i = 0, length = value.length(); i < length; i++) {
-      char previousChar = currentChar;
-      currentChar = value.charAt(i);
-
-      /*
-       * From RFC 4627, "All Unicode characters may be placed within the quotation marks except for
-       * the characters that must be escaped: quotation mark, reverse solidus, and the control
-       * characters (U+0000 through U+001F)."
-       */
-      switch (currentChar) {
-        case '"':
-        case '\\':
-          out.append('\\').append(currentChar);
-          break;
-
-        case '/':
-          // it makes life easier for HTML embedding of javascript if we escape </ sequences
-          if (previousChar == '<') {
-            out.append('\\');
-          }
-          out.append(currentChar);
-          break;
-
-        case '\t':
-          out.append("\\t");
-          break;
-
-        case '\b':
-          out.append("\\b");
-          break;
-
-        case '\n':
-          out.append("\\n");
-          break;
-
-        case '\r':
-          out.append("\\r");
-          break;
-
-        case '\f':
-          out.append("\\f");
-          break;
-
-        default:
-          if (currentChar <= 0x1F) {
-            out.append(String.format("\\u%04x", (int) currentChar));
-          } else {
-            out.append(currentChar);
-          }
-          break;
-      }
 
+    /**
+     * Encodes {@code value} to this stringer.
+     *
+     * @param value The value to encode.
+     * @return this stringer.
+     * @throws JSONException If we have an internal error. Shouldn't happen.
+     */
+    public JSONStringer value(long value) throws JSONException {
+        if (stack.isEmpty()) {
+            throw new JSONException("Nesting problem");
+        }
+        beforeValue();
+        out.append(value);
+        return this;
     }
-    out.append("\"");
-  }
 
-  private void newline() {
-    if (indent == null) {
-      return;
+    private void string(String value) {
+        out.append("\"");
+        char currentChar = 0;
+
+        for (int i = 0, length = value.length(); i < length; i++) {
+            char previousChar = currentChar;
+            currentChar = value.charAt(i);
+
+            /*
+             * From RFC 4627, "All Unicode characters may be placed within the
+             * quotation marks except for the characters that must be escaped:
+             * quotation mark, reverse solidus, and the control characters
+             * (U+0000 through U+001F)."
+             */
+            switch (currentChar) {
+                case '"':
+                case '\\':
+                    out.append('\\').append(currentChar);
+                    break;
+
+                case '/':
+                    // it makes life easier for HTML embedding of javascript if we escape </ sequences
+                    if (previousChar == '<') {
+                        out.append('\\');
+                    }
+                    out.append(currentChar);
+                    break;
+
+                case '\t':
+                    out.append("\\t");
+                    break;
+
+                case '\b':
+                    out.append("\\b");
+                    break;
+
+                case '\n':
+                    out.append("\\n");
+                    break;
+
+                case '\r':
+                    out.append("\\r");
+                    break;
+
+                case '\f':
+                    out.append("\\f");
+                    break;
+
+                default:
+                    if (currentChar <= 0x1F) {
+                        out.append(String.format("\\u%04x", (int) currentChar));
+                    } else {
+                        out.append(currentChar);
+                    }
+                    break;
+            }
+
+        }
+        out.append("\"");
     }
 
-    out.append("\n");
-    for (int i = 0; i < stack.size(); i++) {
-      out.append(indent);
+    private void newline() {
+        if (indent == null) {
+            return;
+        }
+
+        out.append("\n");
+        for (int i = 0; i < stack.size(); i++) {
+            out.append(indent);
+        }
     }
-  }
-
-  /**
-   * Encodes the key (property name) to this stringer.
-   *
-   * @param name the name of the forthcoming value. May not be null.
-   * @return this stringer.
-   * @throws JSONException on internal errors, shouldn't happen.
-   */
-  public JSONStringer key(String name) throws JSONException {
-    if (name == null) {
-      throw new JSONException("Names must be non-null");
+
+    /**
+     * Encodes the key (property name) to this stringer.
+     *
+     * @param name the name of the forthcoming value. May not be null.
+     * @return this stringer.
+     * @throws JSONException on internal errors, shouldn't happen.
+     */
+    public JSONStringer key(String name) throws JSONException {
+        if (name == null) {
+            throw new JSONException("Names must be non-null");
+        }
+        beforeKey();
+        string(name);
+        return this;
     }
-    beforeKey();
-    string(name);
-    return this;
-  }
-
-  /**
-   * Inserts any necessary separators and whitespace before a name. Also adjusts the stack to expect
-   * the key's value.
-   */
-  private void beforeKey() throws JSONException {
-    Scope context = peek();
-    if (context == Scope.NONEMPTY_OBJECT) { // first in object
-      out.append(',');
-    } else if (context != Scope.EMPTY_OBJECT) { // not in an object!
-      throw new JSONException("Nesting problem");
+
+    /**
+     * Inserts any necessary separators and whitespace before a name. Also
+     * adjusts the stack to expect the key's value.
+     */
+    private void beforeKey() throws JSONException {
+        Scope context = peek();
+        if (context == Scope.NONEMPTY_OBJECT) { // first in object
+            out.append(',');
+        } else if (context != Scope.EMPTY_OBJECT) { // not in an object!
+            throw new JSONException("Nesting problem");
+        }
+        newline();
+        replaceTop(Scope.DANGLING_KEY);
     }
-    newline();
-    replaceTop(Scope.DANGLING_KEY);
-  }
-
-  /**
-   * Inserts any necessary separators and whitespace before a literal value, inline array, or inline
-   * object. Also adjusts the stack to expect either a closing bracket or another element.
-   */
-  private void beforeValue() throws JSONException {
-    if (stack.isEmpty()) {
-      return;
+
+    /**
+     * Inserts any necessary separators and whitespace before a literal value,
+     * inline array, or inline object. Also adjusts the stack to expect either a
+     * closing bracket or another element.
+     */
+    private void beforeValue() throws JSONException {
+        if (stack.isEmpty()) {
+            return;
+        }
+
+        Scope context = peek();
+        if (context == Scope.EMPTY_ARRAY) { // first in array
+            replaceTop(Scope.NONEMPTY_ARRAY);
+            newline();
+        } else if (context == Scope.NONEMPTY_ARRAY) { // another in array
+            out.append(',');
+            newline();
+        } else if (context == Scope.DANGLING_KEY) { // value for key
+            out.append(indent == null ? ":" : ": ");
+            replaceTop(Scope.NONEMPTY_OBJECT);
+        } else if (context != Scope.NULL) {
+            throw new JSONException("Nesting problem");
+        }
     }
 
-    Scope context = peek();
-    if (context == Scope.EMPTY_ARRAY) { // first in array
-      replaceTop(Scope.NONEMPTY_ARRAY);
-      newline();
-    } else if (context == Scope.NONEMPTY_ARRAY) { // another in array
-      out.append(',');
-      newline();
-    } else if (context == Scope.DANGLING_KEY) { // value for key
-      out.append(indent == null ? ":" : ": ");
-      replaceTop(Scope.NONEMPTY_OBJECT);
-    } else if (context != Scope.NULL) {
-      throw new JSONException("Nesting problem");
+    /**
+     * Returns the encoded JSON string.
+     *
+     * <p>If invoked with unterminated arrays or unclosed objects, this method's
+     * return value is undefined.
+     *
+     * <p><strong>Warning:</strong> although it contradicts the general contract
+     * of {@link Object#toString}, this method returns null if the stringer
+     * contains no data.
+     */
+    @Override
+    public String toString() {
+        return out.length() == 0 ? null : out.toString();
     }
-  }
-
-  /**
-   * Returns the encoded JSON string.
-   *
-   * <p>
-   * If invoked with unterminated arrays or unclosed objects, this method's return value is
-   * undefined.
-   *
-   * <p>
-   * <strong>Warning:</strong> although it contradicts the general contract of
-   * {@link Object#toString}, this method returns null if the stringer contains no data.
-   */
-  @Override
-  public String toString() {
-    return out.length() == 0 ? null : out.toString();
-  }
 }


Mime
View raw message