You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/03/01 00:14:00 UTC

[01/34] geode git commit: GEODE-2275: add FlakyTest category to flickering test [Forced Update!]

Repository: geode
Updated Branches:
  refs/heads/GEODE-4160-mockito 51e430623 -> 5b3cbca10 (forced update)


GEODE-2275: add FlakyTest category to flickering test


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/af2328a7
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/af2328a7
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/af2328a7

Branch: refs/heads/GEODE-4160-mockito
Commit: af2328a79dad6f323350be44b68c33e31b4c3fbf
Parents: 2f25625
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Feb 24 21:25:29 2017 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Feb 24 21:25:29 2017 -0800

----------------------------------------------------------------------
 .../org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java  | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/af2328a7/geode-core/src/test/java/org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java
index 615ed97..1b97cc4 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearTXLockingDUnitTest.java
@@ -42,6 +42,8 @@ import org.apache.geode.test.dunit.SerializableRunnableIF;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
 import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+
 import org.apache.logging.log4j.Logger;
 import org.assertj.core.api.JUnitSoftAssertions;
 import org.junit.Ignore;
@@ -107,6 +109,7 @@ public class ClearTXLockingDUnitTest extends JUnit4CacheTestCase {
     performTestAndCheckResults(putOperationsTest);
   }
 
+  @Category(FlakyTest.class) // GEODE-2275
   @Test
   public void testPutWithClearDifferentVM() throws InterruptedException {
     getVMs();


[17/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
GEODE-2142: spotless


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/eac0bb8c
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/eac0bb8c
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/eac0bb8c

Branch: refs/heads/GEODE-4160-mockito
Commit: eac0bb8c8e20cae892680a3a39b790c0e05bf4cf
Parents: 7c8794c
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 15:43:49 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 .../internal/cli/result/AbstractResultData.java |    7 +-
 geode-json/src/main/java/org/json/JSON.java     |  176 +-
 .../src/main/java/org/json/JSONArray.java       | 1458 ++++++-----
 .../src/main/java/org/json/JSONException.java   |   59 +-
 .../src/main/java/org/json/JSONObject.java      |  378 +--
 .../src/main/java/org/json/JSONString.java      |   17 +-
 .../src/main/java/org/json/JSONStringer.java    |  779 +++---
 .../src/main/java/org/json/JSONTokener.java     | 1149 +++++----
 geode-json/src/test/java/org/json/FileTest.java |  407 ++-
 .../src/test/java/org/json/JSONArrayTest.java   | 1171 +++++----
 .../java/org/json/JSONFunctionTestObject.java   |   18 +-
 .../src/test/java/org/json/JSONObjectTest.java  | 2314 +++++++++---------
 .../test/java/org/json/JSONStringerTest.java    |  735 +++---
 .../src/test/java/org/json/JSONTokenerTest.java | 1199 +++++----
 .../src/test/java/org/json/ParsingTest.java     |  535 ++--
 .../src/test/java/org/json/SelfUseTest.java     |  465 ++--
 16 files changed, 5350 insertions(+), 5517 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
index 81ab511..f453ec6 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
@@ -175,8 +175,9 @@ public abstract class AbstractResultData implements ResultData {
       sectionData.put(FILE_TYPE_FIELD, fileType);
       sectionData.put(FILE_MESSAGE, message);
       DeflaterInflaterData deflaterInflaterData = CliUtil.compressBytes(data);
-      sectionData.put(FILE_DATA_FIELD, Base64.getEncoder().encodeToString(deflaterInflaterData.getData()));
-      sectionData.put(DATA_LENGTH_FIELD,deflaterInflaterData.getDataLength());
+      sectionData.put(FILE_DATA_FIELD,
+          Base64.getEncoder().encodeToString(deflaterInflaterData.getData()));
+      sectionData.put(DATA_LENGTH_FIELD, deflaterInflaterData.getDataLength());
     } catch (GfJsonException e) {
       throw new ResultDataException(e.getMessage());
     }
@@ -231,7 +232,7 @@ public abstract class AbstractResultData implements ResultData {
       String fileDataString = (String) object.get(FILE_DATA_FIELD);
       int fileDataLength = (int) object.get(DATA_LENGTH_FIELD);
       byte[] byteArray = Base64.getDecoder().decode(fileDataString);
-      byte[] uncompressBytes = CliUtil.uncompressBytes(byteArray,fileDataLength).getData();
+      byte[] uncompressBytes = CliUtil.uncompressBytes(byteArray, fileDataLength).getData();
 
       boolean isGfshVM = CliUtil.isGfshVM();
       File fileToDumpData = new File(fileName);

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/main/java/org/json/JSON.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSON.java b/geode-json/src/main/java/org/json/JSON.java
index 1b32e69..7105cab 100755
--- a/geode-json/src/main/java/org/json/JSON.java
+++ b/geode-json/src/main/java/org/json/JSON.java
@@ -1,116 +1,112 @@
 /*
  * 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;
 
 class JSON {
-    /**
-     * Returns the input if it is a JSON-permissible value; throws otherwise.
-     */
-    static double checkDouble(double d) throws JSONException {
-        if (Double.isInfinite(d) || Double.isNaN(d)) {
-            throw new JSONException("Forbidden numeric value: " + d);
-        }
-        return d;
+  /**
+   * Returns the input if it is a JSON-permissible value; throws otherwise.
+   */
+  static double checkDouble(double d) throws JSONException {
+    if (Double.isInfinite(d) || Double.isNaN(d)) {
+      throw new JSONException("Forbidden numeric value: " + d);
     }
+    return d;
+  }
 
-    static Boolean toBoolean(Object value) {
-        if (value instanceof Boolean) {
-            return (Boolean) value;
-        } else if (value instanceof String) {
-            String stringValue = (String) value;
-            if ("true".equalsIgnoreCase(stringValue)) {
-                return true;
-            } else if ("false".equalsIgnoreCase(stringValue)) {
-                return false;
-            }
-        }
-        return null;
+  static Boolean toBoolean(Object value) {
+    if (value instanceof Boolean) {
+      return (Boolean) value;
+    } else if (value instanceof String) {
+      String stringValue = (String) value;
+      if ("true".equalsIgnoreCase(stringValue)) {
+        return true;
+      } else if ("false".equalsIgnoreCase(stringValue)) {
+        return false;
+      }
     }
+    return null;
+  }
 
-    static Double toDouble(Object value) {
-        if (value instanceof Double) {
-            return (Double) value;
-        } else if (value instanceof Number) {
-            return ((Number) value).doubleValue();
-        } else if (value instanceof String) {
-            try {
-                return Double.valueOf((String) value);
-            } catch (NumberFormatException ignored) {
-            }
-        }
-        return null;
+  static Double toDouble(Object value) {
+    if (value instanceof Double) {
+      return (Double) value;
+    } else if (value instanceof Number) {
+      return ((Number) value).doubleValue();
+    } else if (value instanceof String) {
+      try {
+        return Double.valueOf((String) value);
+      } catch (NumberFormatException ignored) {
+      }
     }
+    return null;
+  }
 
-    static Integer toInteger(Object value) {
-        if (value instanceof Integer) {
-            return (Integer) value;
-        } else if (value instanceof Number) {
-            return ((Number) value).intValue();
-        } else if (value instanceof String) {
-            try {
-                return (int) Double.parseDouble((String) value);
-            } catch (NumberFormatException ignored) {
-            }
-        }
-        return null;
+  static Integer toInteger(Object value) {
+    if (value instanceof Integer) {
+      return (Integer) value;
+    } else if (value instanceof Number) {
+      return ((Number) value).intValue();
+    } else if (value instanceof String) {
+      try {
+        return (int) Double.parseDouble((String) value);
+      } catch (NumberFormatException ignored) {
+      }
     }
+    return null;
+  }
 
-    static Long toLong(Object value) {
-        if (value instanceof Long) {
-            return (Long) value;
-        } else if (value instanceof Number) {
-            return ((Number) value).longValue();
-        } else if (value instanceof String) {
-            try {
-                return (long) Double.parseDouble((String) value);
-            } catch (NumberFormatException ignored) {
-            }
-        }
-        return null;
+  static Long toLong(Object value) {
+    if (value instanceof Long) {
+      return (Long) value;
+    } else if (value instanceof Number) {
+      return ((Number) value).longValue();
+    } else if (value instanceof String) {
+      try {
+        return (long) Double.parseDouble((String) value);
+      } catch (NumberFormatException ignored) {
+      }
     }
+    return null;
+  }
 
-    static String toString(Object value) {
-        if (value instanceof String) {
-            return (String) value;
-        } else if (value != null) {
-            return String.valueOf(value);
-        }
-        return null;
+  static String toString(Object value) {
+    if (value instanceof String) {
+      return (String) value;
+    } else if (value != null) {
+      return String.valueOf(value);
     }
+    return null;
+  }
 
-    public static JSONException typeMismatch(Object indexOrName, Object actual,
-            String requiredType) throws JSONException {
-        if (actual == null) {
-            throw new JSONException("Value at " + indexOrName + " is null.");
-        } else {
-            throw new JSONException("Value " + actual + " at " + indexOrName
-                    + " of type " + actual.getClass().getName()
-                    + " cannot be converted to " + requiredType);
-        }
+  public static JSONException typeMismatch(Object indexOrName, Object actual, String requiredType)
+      throws JSONException {
+    if (actual == null) {
+      throw new JSONException("Value at " + indexOrName + " is null.");
+    } else {
+      throw new JSONException("Value " + actual + " at " + indexOrName + " of type "
+          + actual.getClass().getName() + " cannot be converted to " + requiredType);
     }
+  }
 
-    public static JSONException typeMismatch(Object actual, String requiredType)
-            throws JSONException {
-        if (actual == null) {
-            throw new JSONException("Value is null.");
-        } else {
-            throw new JSONException("Value " + actual
-                    + " of type " + actual.getClass().getName()
-                    + " cannot be converted to " + requiredType);
-        }
+  public static JSONException typeMismatch(Object actual, String requiredType)
+      throws JSONException {
+    if (actual == null) {
+      throw new JSONException("Value is null.");
+    } else {
+      throw new JSONException("Value " + actual + " of type " + actual.getClass().getName()
+          + " cannot be converted to " + requiredType);
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/main/java/org/json/JSONArray.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONArray.java b/geode-json/src/main/java/org/json/JSONArray.java
index 074624d..c961139 100755
--- a/geode-json/src/main/java/org/json/JSONArray.java
+++ b/geode-json/src/main/java/org/json/JSONArray.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -24,736 +22,726 @@ import java.util.List;
 // Note: this class was written without inspecting the non-free org.json sourcecode.
 
 /**
- * A dense indexed sequence of values. Values may be any mix of
- * {@link JSONObject JSONObjects}, other {@link JSONArray JSONArrays}, Strings,
- * Booleans, Integers, Longs, Doubles, {@code null} or {@link JSONObject#NULL}.
- * Values may not be {@link Double#isNaN() NaNs}, {@link Double#isInfinite()
- * infinities}, or of any type not listed here.
+ * A dense indexed sequence of values. Values may be any mix of {@link JSONObject JSONObjects},
+ * other {@link JSONArray JSONArrays}, Strings, Booleans, Integers, Longs, Doubles, {@code null} or
+ * {@link JSONObject#NULL}. Values may not be {@link Double#isNaN() NaNs},
+ * {@link Double#isInfinite() infinities}, or of any type not listed here.
  *
- * {@code JSONArray} has the same type coercion behavior and
- * optional/mandatory accessors as {@link JSONObject}. See that class'
- * documentation for details.
+ * {@code JSONArray} has the same type coercion behavior and optional/mandatory accessors as
+ * {@link JSONObject}. See that class' documentation for details.
  *
- * <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, {@code get} fails if the requested index
- * holds the null reference, but succeeds if it holds {@code JSONObject.NULL}.
+ * <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,
+ * {@code get} fails if the requested index holds the null reference, but succeeds if it holds
+ * {@code JSONObject.NULL}.
  *
- * Instances of this class are not thread safe. Although this class is
- * non-final, it was not designed for inheritance and should not be subclassed.
- * In particular, self-use by overridable methods is not specified. See
- * <i>Effective Java</i> Item 17, "Design and Document or inheritance or else
- * prohibit it" for further information.
+ * Instances of this class are not thread safe. Although this class is non-final, it was not
+ * designed for inheritance and should not be subclassed. In particular, self-use by overridable
+ * 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 JSONArray {
 
-    private final List<Object> values;
-
-    /**
-     * Creates a {@code JSONArray} with no values.
-     */
-    public JSONArray() {
-        values = new ArrayList<Object>();
-    }
-
-    /**
-     * Creates a new {@code JSONArray} by copying all values from the given
-     * collection.
-     *
-     * @param copyFrom a collection whose values are of supported types.
-     *                 Unsupported values are not permitted and will yield an array in an
-     *                 inconsistent state.
-     */
-    /* Accept a raw type for API compatibility */
-    public JSONArray(Collection<?> copyFrom) {
-        this();
-        if (copyFrom != null) {
-            for (Object aCopyFrom : copyFrom) {
-                put(JSONObject.wrap(aCopyFrom));
-            }
-        }
-    }
-
-    /**
-     * Creates a new {@code JSONArray} with values from the next array in the
-     * tokener.
-     *
-     * @param readFrom a tokener whose nextValue() method will yield a
-     *                 {@code JSONArray}.
-     * @throws JSONException if the parse fails or doesn't yield a
-     *                       {@code JSONArray}.
-     */
-    public JSONArray(JSONTokener readFrom) throws JSONException {
-        /*
-         * Getting the parser to populate this could get tricky. Instead, just
-         * parse to temporary JSONArray and then steal the data from that.
-         */
-        Object object = readFrom.nextValue();
-        if (object instanceof JSONArray) {
-            values = ((JSONArray) object).values;
-        } else {
-            throw JSON.typeMismatch(object, "JSONArray");
-        }
-    }
-
-    /**
-     * Creates a new {@code JSONArray} with values from the JSON string.
-     *
-     * @param json a JSON-encoded string containing an array.
-     * @throws JSONException if the parse fails or doesn't yield a {@code
-     *                       JSONArray}.
-     */
-    public JSONArray(String json) throws JSONException {
-        this(new JSONTokener(json));
-    }
-
-    /**
-     * Creates a new {@code JSONArray} with values from the given primitive array.
-     *
-     * @param array The values to use.
-     * @throws JSONException if any of the values are non-finite double values (i.e. NaN or infinite)
-     */
-    public JSONArray(Object array) throws JSONException {
-        if (!array.getClass().isArray()) {
-            throw new JSONException("Not a primitive array: " + array.getClass());
-        }
-        final int length = Array.getLength(array);
-        values = new ArrayList<Object>(length);
-        for (int i = 0; i < length; ++i) {
-            put(JSONObject.wrap(Array.get(array, i)));
-        }
-    }
-
-    /**
-     * @return Returns the number of values in this array.
-     */
-    public int length() {
-        return values.size();
-    }
-
-    /**
-     * Appends {@code value} to the end of this array.
-     *
-     * @param value The value to append.
-     * @return this array.
-     */
-    public JSONArray put(boolean value) {
-        values.add(value);
-        return this;
-    }
-
-    /**
-     * Appends {@code value} to the end of this array.
-     *
-     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
-     *              {@link Double#isInfinite() infinities}.
-     * @return this array.
-     * @throws JSONException If the value is unacceptable.
-     */
-    public JSONArray put(double value) throws JSONException {
-        values.add(JSON.checkDouble(value));
-        return this;
-    }
-
-    /**
-     * Appends {@code value} to the end of this array.
-     *
-     * @param value The value to append.
-     * @return this array.
-     */
-    public JSONArray put(int value) {
-        values.add(value);
-        return this;
-    }
-
-    /**
-     * Appends {@code value} to the end of this array.
-     *
-     * @param value The value to append.
-     * @return this array.
-     */
-    public JSONArray put(long value) {
-        values.add(value);
-        return this;
-    }
-
-    /**
-     * Appends {@code value} wrapped by {@link JSONArray} to the end of this array.
-     *
-     * @param value any collection.
-     * @return this array.
-     */
-    public JSONArray put(Collection<?> value) {
-        if (value == null) {
-            return put((Object)null);
-        }
-        values.add(new JSONArray(value));
-        return this;
-    }
-
-    /**
-     * Appends {@code value} to the end of this array.
-     *
-     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
-     *              Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May
-     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
-     *              infinities}. Unsupported values are not permitted and will cause the
-     *              array to be in an inconsistent state.
-     * @return this array.
-     */
-    public JSONArray put(Object value) {
-        values.add(value);
-        return this;
-    }
-
-    /**
-     * Same as {@link #put}, with added validity checks.
-     *
-     * @param value The value to append.
-     */
-    void checkedPut(Object value) throws JSONException {
-        if (value instanceof Number) {
-            JSON.checkDouble(((Number) value).doubleValue());
-        }
-
-        put(value);
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value}, null padding this array
-     * to the required length if necessary. If a value already exists at {@code
-     * index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value The value to set.
-     * @return this array.
-     * @throws JSONException This should never happen.
-     */
-    public JSONArray put(int index, boolean value) throws JSONException {
-        return put(index, (Boolean) value);
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value}, null padding this array
-     * to the required length if necessary. If a value already exists at {@code
-     * index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
-     *              {@link Double#isInfinite() infinities}.
-     * @return this array.
-     * @throws JSONException If the value is not a finite value.
-     */
-    public JSONArray put(int index, double value) throws JSONException {
-        return put(index, (Double) value);
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value}, null padding this array
-     * to the required length if necessary. If a value already exists at {@code
-     * index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value The value to set.
-     * @return this array.
-     * @throws JSONException Should never actually happen.
-     */
-    public JSONArray put(int index, int value) throws JSONException {
-        return put(index, (Integer) value);
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value}, null padding this array
-     * to the required length if necessary. If a value already exists at {@code
-     * index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value The value to set.
-     * @return this array.
-     * @throws JSONException Should never actually happen.
-     */
-    public JSONArray put(int index, long value) throws JSONException {
-        return put(index, (Long) value);
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value} wrapped into {@link JSONArray},
-     * null padding this array to the required length if necessary. If a value already
-     * exists at {@code index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value The value to set.
-     * @return this array.
-     * @throws JSONException Should never actually happen.
-     */
-    public JSONArray put(int index, Collection<?> value) throws JSONException {
-        if (value == null) {
-            return put(index, (Object)null);
-        }
-        return put(index, new JSONArray(value));
-    }
-
-    /**
-     * Sets the value at {@code index} to {@code value}, null padding this array
-     * to the required length if necessary. If a value already exists at {@code
-     * index}, it will be replaced.
-     *
-     * @param index Where to put the value.
-     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
-     *              Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May
-     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
-     *              infinities}.
-     * @return this array.
-     * @throws JSONException If the value cannot be represented as a finite double value.
-     */
-    public JSONArray put(int index, Object value) throws JSONException {
-        if (value instanceof Number) {
-            // deviate from the original by checking all Numbers, not just floats & doubles
-            JSON.checkDouble(((Number) value).doubleValue());
-        }
-        while (values.size() <= index) {
-            values.add(null);
-        }
-        values.set(index, value);
-        return this;
-    }
-
-    /**
-     * Returns true if this array has no value at {@code index}, or if its value
-     * is the {@code null} reference or {@link JSONObject#NULL}.
-     *
-     * @param index Which value to check.
-     * @return true if the value is null.
-     */
-    public boolean isNull(int index) {
-        Object value = opt(index);
-        return value == null || value == JSONObject.NULL;
-    }
-
-    /**
-     * Returns the value at {@code index}.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if this array has no value at {@code index}, or if
-     *                       that value is the {@code null} reference. This method returns
-     *                       normally if the value is {@code JSONObject#NULL}.
-     */
-    public Object get(int index) throws JSONException {
-        try {
-            Object value = values.get(index);
-            if (value == null) {
-                throw new JSONException("Value at " + index + " is null.");
-            }
-            return value;
-        } catch (IndexOutOfBoundsException e) {
-            throw new JSONException("Index " + index + " out of range [0.." + values.size() + ")");
-        }
-    }
-
-    /**
-     * Returns the value at {@code index}, or null if the array has no value
-     * at {@code index}.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public Object opt(int index) {
-        if (index < 0 || index >= values.size()) {
-            return null;
-        }
-        return values.get(index);
-    }
-
-    /**
-     * Removes and returns the value at {@code index}, or null if the array has no value
-     * at {@code index}.
-     *
-     * @param index Which value to remove.
-     * @return The value previously at the specified location.
-     */
-    public Object remove(int index) {
-        if (index < 0 || index >= values.size()) {
-            return null;
-        }
-        return values.remove(index);
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a boolean or can
-     * be coerced to a boolean.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value at {@code index} doesn't exist or
-     *                       cannot be coerced to a boolean.
-     */
-    public boolean getBoolean(int index) throws JSONException {
-        Object object = get(index);
-        Boolean result = JSON.toBoolean(object);
-        if (result == null) {
-            throw JSON.typeMismatch(index, object, "boolean");
-        }
-        return result;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a boolean or can
-     * be coerced to a boolean. Returns false otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public boolean optBoolean(int index) {
-        return optBoolean(index, false);
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a boolean or can
-     * be coerced to a boolean. Returns {@code fallback} otherwise.
-     *
-     * @param index    Which value to get.
-     * @param fallback the fallback value to return if no value exists.
-     * @return the value at the specified location or the fallback value.
-     */
-    public boolean optBoolean(int index, boolean fallback) {
-        Object object = opt(index);
-        Boolean result = JSON.toBoolean(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a double or can
-     * be coerced to a double.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value at {@code index} doesn't exist or
-     *                       cannot be coerced to a double.
-     */
-    public double getDouble(int index) throws JSONException {
-        Object object = get(index);
-        Double result = JSON.toDouble(object);
-        if (result == null) {
-            throw JSON.typeMismatch(index, object, "double");
-        }
-        return result;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a double or can
-     * be coerced to a double. Returns {@code NaN} otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public double optDouble(int index) {
-        return optDouble(index, Double.NaN);
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a double or can
-     * be coerced to a double. Returns {@code fallback} otherwise.
-     *
-     * @param index    Which value to get.
-     * @param fallback The fallback value to use if no value is at the specified location.
-     * @return the value at the specified location or the fallback value.
-     */
-    public double optDouble(int index, double fallback) {
-        Object object = opt(index);
-        Double result = JSON.toDouble(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is an int or
-     * can be coerced to an int.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value at {@code index} doesn't exist or
-     *                       cannot be coerced to a int.
-     */
-    public int getInt(int index) throws JSONException {
-        Object object = get(index);
-        Integer result = JSON.toInteger(object);
-        if (result == null) {
-            throw JSON.typeMismatch(index, object, "int");
-        }
-        return result;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is an int or
-     * can be coerced to an int. Returns 0 otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public int optInt(int index) {
-        return optInt(index, 0);
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is an int or
-     * can be coerced to an int. Returns {@code fallback} otherwise.
-     *
-     * @param index    Which value to get.
-     * @param fallback The fallback value to use if no value is at the specified location.
-     * @return the value at the specified location or the fallback value.
-     */
-    public int optInt(int index, int fallback) {
-        Object object = opt(index);
-        Integer result = JSON.toInteger(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a long or
-     * can be coerced to a long.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value at {@code index} doesn't exist or
-     *                       cannot be coerced to a long.
-     */
-    public long getLong(int index) throws JSONException {
-        Object object = get(index);
-        Long result = JSON.toLong(object);
-        if (result == null) {
-            throw JSON.typeMismatch(index, object, "long");
-        }
-        return result;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a long or
-     * can be coerced to a long. Returns 0 otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public long optLong(int index) {
-        return optLong(index, 0L);
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a long or
-     * can be coerced to a long. Returns {@code fallback} otherwise.
-     *
-     * @param index    Which value to get.
-     * @param fallback The fallback value to use if no value is at the specified location.
-     * @return the value at the specified location or the fallback value.
-     */
-    public long optLong(int index, long fallback) {
-        Object object = opt(index);
-        Long result = JSON.toLong(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists, coercing it if
-     * necessary.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if no such value exists.
-     */
-    public String getString(int index) throws JSONException {
-        Object object = get(index);
-        String result = JSON.toString(object);
-        if (result == null) {
-            throw JSON.typeMismatch(index, object, "String");
-        }
-        return result;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists, coercing it if
-     * necessary. Returns the empty string if no such value exists.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public String optString(int index) {
-        return optString(index, "");
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists, coercing it if
-     * necessary. Returns {@code fallback} if no such value exists.
-     *
-     * @param index    Which value to get.
-     * @param fallback The fallback value to use if no value is at the specified location.
-     * @return the value at the specified location or the fallback value.
-     */
-    public String optString(int index, String fallback) {
-        Object object = opt(index);
-        String result = JSON.toString(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a {@code
-     * JSONArray}.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value doesn't exist or is not a {@code
-     *                       JSONArray}.
-     */
-    public JSONArray getJSONArray(int index) throws JSONException {
-        Object object = get(index);
-        if (object instanceof JSONArray) {
-            return (JSONArray) object;
-        } else {
-            throw JSON.typeMismatch(index, object, "JSONArray");
-        }
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a {@code
-     * JSONArray}. Returns null otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public JSONArray optJSONArray(int index) {
-        Object object = opt(index);
-        return object instanceof JSONArray ? (JSONArray) object : null;
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a {@code
-     * JSONObject}.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     * @throws JSONException if the value doesn't exist or is not a {@code
-     *                       JSONObject}.
-     */
-    public JSONObject getJSONObject(int index) throws JSONException {
-        Object object = get(index);
-        if (object instanceof JSONObject) {
-            return (JSONObject) object;
-        } else {
-            throw JSON.typeMismatch(index, object, "JSONObject");
-        }
-    }
-
-    /**
-     * Returns the value at {@code index} if it exists and is a {@code
-     * JSONObject}. Returns null otherwise.
-     *
-     * @param index Which value to get.
-     * @return the value at the specified location.
-     */
-    public JSONObject optJSONObject(int index) {
-        Object object = opt(index);
-        return object instanceof JSONObject ? (JSONObject) object : null;
-    }
-
-    /**
-     * Returns a new object whose values are the values in this array, and whose
-     * names are the values in {@code names}. Names and values are paired up by
-     * index from 0 through to the shorter array's length. Names that are not
-     * strings will be coerced to strings. This method returns null if either
-     * array is empty.
-     *
-     * @param names The names to apply to the returned values.
-     * @return the newly constructed object.
-     * @throws JSONException Should not be possible.
-     */
-    public JSONObject toJSONObject(JSONArray names) throws JSONException {
-        JSONObject result = new JSONObject();
-        int length = Math.min(names.length(), values.size());
-        if (length == 0) {
-            return null;
-        }
-        for (int i = 0; i < length; i++) {
-            String name = JSON.toString(names.opt(i));
-            result.put(name, opt(i));
-        }
-        return result;
-    }
-
-    /**
-     * Returns a new string by alternating this array's values with {@code
-     * separator}. This array's string values are quoted and have their special
-     * characters escaped. For example, the array containing the strings '12"
-     * pizza', 'taco' and 'soda' joined on '+' returns this:
-     * <pre>"12\" pizza"+"taco"+"soda"</pre>
-     *
-     * @param separator The string used to separate the returned values.
-     * @return the conjoined values.
-     * @throws JSONException Only if there is a coding error.
-     */
-    public String join(String separator) throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.open(JSONStringer.Scope.NULL, "");
-        for (int i = 0, size = values.size(); i < size; i++) {
-            if (i > 0) {
-                stringer.out.append(separator);
-            }
-            stringer.value(values.get(i));
-        }
-        stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
-        return stringer.out.toString();
-    }
-
-    /**
-     * Encodes this array as a compact JSON string, such as:
-     * <pre>[94043,90210]</pre>
-     *
-     * @return The string form of this array.
-     */
-    @Override
-    public String toString() {
-        try {
-            JSONStringer stringer = new JSONStringer();
-            writeTo(stringer);
-            return stringer.toString();
-        } catch (JSONException e) {
-            return null;
-        }
-    }
-
-    /**
-     * Encodes this array as a human readable JSON string for debugging, such
-     * as:
-     * <pre>
-     * [
-     *     94043,
-     *     90210
-     * ]</pre>
-     *
-     * @param indentSpaces the number of spaces to indent for each level of
-     *                     nesting.
-     * @return The string form of this array.
-     * @throws JSONException Only if there is a coding error.
-     */
-    public String toString(int indentSpaces) throws JSONException {
-        JSONStringer stringer = new JSONStringer(indentSpaces);
-        writeTo(stringer);
-        return stringer.toString();
-    }
-
-    void writeTo(JSONStringer stringer) throws JSONException {
-        stringer.array();
-        for (Object value : values) {
-            stringer.value(value);
-        }
-        stringer.endArray();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return o instanceof JSONArray && ((JSONArray) o).values.equals(values);
-    }
-
-    @Override
-    public int hashCode() {
-        // diverge from the original, which doesn't implement hashCode
-        return values.hashCode();
-    }
+  private final List<Object> values;
+
+  /**
+   * Creates a {@code JSONArray} with no values.
+   */
+  public JSONArray() {
+    values = new ArrayList<Object>();
+  }
+
+  /**
+   * Creates a new {@code JSONArray} by copying all values from the given collection.
+   *
+   * @param copyFrom a collection whose values are of supported types. Unsupported values are not
+   *        permitted and will yield an array in an inconsistent state.
+   */
+  /* Accept a raw type for API compatibility */
+  public JSONArray(Collection<?> copyFrom) {
+    this();
+    if (copyFrom != null) {
+      for (Object aCopyFrom : copyFrom) {
+        put(JSONObject.wrap(aCopyFrom));
+      }
+    }
+  }
+
+  /**
+   * Creates a new {@code JSONArray} with values from the next array in the tokener.
+   *
+   * @param readFrom a tokener whose nextValue() method will yield a {@code JSONArray}.
+   * @throws JSONException if the parse fails or doesn't yield a {@code JSONArray}.
+   */
+  public JSONArray(JSONTokener readFrom) throws JSONException {
+    /*
+     * Getting the parser to populate this could get tricky. Instead, just parse to temporary
+     * JSONArray and then steal the data from that.
+     */
+    Object object = readFrom.nextValue();
+    if (object instanceof JSONArray) {
+      values = ((JSONArray) object).values;
+    } else {
+      throw JSON.typeMismatch(object, "JSONArray");
+    }
+  }
+
+  /**
+   * Creates a new {@code JSONArray} with values from the JSON string.
+   *
+   * @param json a JSON-encoded string containing an array.
+   * @throws JSONException if the parse fails or doesn't yield a {@code
+   *                       JSONArray}.
+   */
+  public JSONArray(String json) throws JSONException {
+    this(new JSONTokener(json));
+  }
+
+  /**
+   * Creates a new {@code JSONArray} with values from the given primitive array.
+   *
+   * @param array The values to use.
+   * @throws JSONException if any of the values are non-finite double values (i.e. NaN or infinite)
+   */
+  public JSONArray(Object array) throws JSONException {
+    if (!array.getClass().isArray()) {
+      throw new JSONException("Not a primitive array: " + array.getClass());
+    }
+    final int length = Array.getLength(array);
+    values = new ArrayList<Object>(length);
+    for (int i = 0; i < length; ++i) {
+      put(JSONObject.wrap(Array.get(array, i)));
+    }
+  }
+
+  /**
+   * @return Returns the number of values in this array.
+   */
+  public int length() {
+    return values.size();
+  }
+
+  /**
+   * Appends {@code value} to the end of this array.
+   *
+   * @param value The value to append.
+   * @return this array.
+   */
+  public JSONArray put(boolean value) {
+    values.add(value);
+    return this;
+  }
+
+  /**
+   * Appends {@code value} to the end of this array.
+   *
+   * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
+   *        {@link Double#isInfinite() infinities}.
+   * @return this array.
+   * @throws JSONException If the value is unacceptable.
+   */
+  public JSONArray put(double value) throws JSONException {
+    values.add(JSON.checkDouble(value));
+    return this;
+  }
+
+  /**
+   * Appends {@code value} to the end of this array.
+   *
+   * @param value The value to append.
+   * @return this array.
+   */
+  public JSONArray put(int value) {
+    values.add(value);
+    return this;
+  }
+
+  /**
+   * Appends {@code value} to the end of this array.
+   *
+   * @param value The value to append.
+   * @return this array.
+   */
+  public JSONArray put(long value) {
+    values.add(value);
+    return this;
+  }
+
+  /**
+   * Appends {@code value} wrapped by {@link JSONArray} to the end of this array.
+   *
+   * @param value any collection.
+   * @return this array.
+   */
+  public JSONArray put(Collection<?> value) {
+    if (value == null) {
+      return put((Object) null);
+    }
+    values.add(new JSONArray(value));
+    return this;
+  }
+
+  /**
+   * Appends {@code value} to the end of this array.
+   *
+   * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double,
+   *        {@link JSONObject#NULL}, or {@code null}. May not be {@link Double#isNaN() NaNs} or
+   *        {@link Double#isInfinite() infinities}. Unsupported values are not permitted and will
+   *        cause the array to be in an inconsistent state.
+   * @return this array.
+   */
+  public JSONArray put(Object value) {
+    values.add(value);
+    return this;
+  }
+
+  /**
+   * Same as {@link #put}, with added validity checks.
+   *
+   * @param value The value to append.
+   */
+  void checkedPut(Object value) throws JSONException {
+    if (value instanceof Number) {
+      JSON.checkDouble(((Number) value).doubleValue());
+    }
+
+    put(value);
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value}, null padding this array to the required
+   * length if necessary. If a value already exists at {@code
+   * index}, it will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value The value to set.
+   * @return this array.
+   * @throws JSONException This should never happen.
+   */
+  public JSONArray put(int index, boolean value) throws JSONException {
+    return put(index, (Boolean) value);
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value}, null padding this array to the required
+   * length if necessary. If a value already exists at {@code
+   * index}, it will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
+   *        {@link Double#isInfinite() infinities}.
+   * @return this array.
+   * @throws JSONException If the value is not a finite value.
+   */
+  public JSONArray put(int index, double value) throws JSONException {
+    return put(index, (Double) value);
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value}, null padding this array to the required
+   * length if necessary. If a value already exists at {@code
+   * index}, it will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value The value to set.
+   * @return this array.
+   * @throws JSONException Should never actually happen.
+   */
+  public JSONArray put(int index, int value) throws JSONException {
+    return put(index, (Integer) value);
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value}, null padding this array to the required
+   * length if necessary. If a value already exists at {@code
+   * index}, it will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value The value to set.
+   * @return this array.
+   * @throws JSONException Should never actually happen.
+   */
+  public JSONArray put(int index, long value) throws JSONException {
+    return put(index, (Long) value);
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value} wrapped into {@link JSONArray}, null padding
+   * this array to the required length if necessary. If a value already exists at {@code index}, it
+   * will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value The value to set.
+   * @return this array.
+   * @throws JSONException Should never actually happen.
+   */
+  public JSONArray put(int index, Collection<?> value) throws JSONException {
+    if (value == null) {
+      return put(index, (Object) null);
+    }
+    return put(index, new JSONArray(value));
+  }
+
+  /**
+   * Sets the value at {@code index} to {@code value}, null padding this array to the required
+   * length if necessary. If a value already exists at {@code
+   * index}, it will be replaced.
+   *
+   * @param index Where to put the value.
+   * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double,
+   *        {@link JSONObject#NULL}, or {@code null}. May not be {@link Double#isNaN() NaNs} or
+   *        {@link Double#isInfinite() infinities}.
+   * @return this array.
+   * @throws JSONException If the value cannot be represented as a finite double value.
+   */
+  public JSONArray put(int index, Object value) throws JSONException {
+    if (value instanceof Number) {
+      // deviate from the original by checking all Numbers, not just floats & doubles
+      JSON.checkDouble(((Number) value).doubleValue());
+    }
+    while (values.size() <= index) {
+      values.add(null);
+    }
+    values.set(index, value);
+    return this;
+  }
+
+  /**
+   * Returns true if this array has no value at {@code index}, or if its value is the {@code null}
+   * reference or {@link JSONObject#NULL}.
+   *
+   * @param index Which value to check.
+   * @return true if the value is null.
+   */
+  public boolean isNull(int index) {
+    Object value = opt(index);
+    return value == null || value == JSONObject.NULL;
+  }
+
+  /**
+   * Returns the value at {@code index}.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if this array has no value at {@code index}, or if that value is the
+   *         {@code null} reference. This method returns normally if the value is
+   *         {@code JSONObject#NULL}.
+   */
+  public Object get(int index) throws JSONException {
+    try {
+      Object value = values.get(index);
+      if (value == null) {
+        throw new JSONException("Value at " + index + " is null.");
+      }
+      return value;
+    } catch (IndexOutOfBoundsException e) {
+      throw new JSONException("Index " + index + " out of range [0.." + values.size() + ")");
+    }
+  }
+
+  /**
+   * Returns the value at {@code index}, or null if the array has no value at {@code index}.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public Object opt(int index) {
+    if (index < 0 || index >= values.size()) {
+      return null;
+    }
+    return values.get(index);
+  }
+
+  /**
+   * Removes and returns the value at {@code index}, or null if the array has no value at
+   * {@code index}.
+   *
+   * @param index Which value to remove.
+   * @return The value previously at the specified location.
+   */
+  public Object remove(int index) {
+    if (index < 0 || index >= values.size()) {
+      return null;
+    }
+    return values.remove(index);
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a boolean or can be coerced to a
+   * boolean.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value at {@code index} doesn't exist or cannot be coerced to a
+   *         boolean.
+   */
+  public boolean getBoolean(int index) throws JSONException {
+    Object object = get(index);
+    Boolean result = JSON.toBoolean(object);
+    if (result == null) {
+      throw JSON.typeMismatch(index, object, "boolean");
+    }
+    return result;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a boolean or can be coerced to a
+   * boolean. Returns false otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public boolean optBoolean(int index) {
+    return optBoolean(index, false);
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a boolean or can be coerced to a
+   * boolean. Returns {@code fallback} otherwise.
+   *
+   * @param index Which value to get.
+   * @param fallback the fallback value to return if no value exists.
+   * @return the value at the specified location or the fallback value.
+   */
+  public boolean optBoolean(int index, boolean fallback) {
+    Object object = opt(index);
+    Boolean result = JSON.toBoolean(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a double or can be coerced to a double.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value at {@code index} doesn't exist or cannot be coerced to a
+   *         double.
+   */
+  public double getDouble(int index) throws JSONException {
+    Object object = get(index);
+    Double result = JSON.toDouble(object);
+    if (result == null) {
+      throw JSON.typeMismatch(index, object, "double");
+    }
+    return result;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a double or can be coerced to a double.
+   * Returns {@code NaN} otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public double optDouble(int index) {
+    return optDouble(index, Double.NaN);
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a double or can be coerced to a double.
+   * Returns {@code fallback} otherwise.
+   *
+   * @param index Which value to get.
+   * @param fallback The fallback value to use if no value is at the specified location.
+   * @return the value at the specified location or the fallback value.
+   */
+  public double optDouble(int index, double fallback) {
+    Object object = opt(index);
+    Double result = JSON.toDouble(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is an int or can be coerced to an int.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value at {@code index} doesn't exist or cannot be coerced to a
+   *         int.
+   */
+  public int getInt(int index) throws JSONException {
+    Object object = get(index);
+    Integer result = JSON.toInteger(object);
+    if (result == null) {
+      throw JSON.typeMismatch(index, object, "int");
+    }
+    return result;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is an int or can be coerced to an int.
+   * Returns 0 otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public int optInt(int index) {
+    return optInt(index, 0);
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is an int or can be coerced to an int.
+   * Returns {@code fallback} otherwise.
+   *
+   * @param index Which value to get.
+   * @param fallback The fallback value to use if no value is at the specified location.
+   * @return the value at the specified location or the fallback value.
+   */
+  public int optInt(int index, int fallback) {
+    Object object = opt(index);
+    Integer result = JSON.toInteger(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a long or can be coerced to a long.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value at {@code index} doesn't exist or cannot be coerced to a
+   *         long.
+   */
+  public long getLong(int index) throws JSONException {
+    Object object = get(index);
+    Long result = JSON.toLong(object);
+    if (result == null) {
+      throw JSON.typeMismatch(index, object, "long");
+    }
+    return result;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a long or can be coerced to a long.
+   * Returns 0 otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public long optLong(int index) {
+    return optLong(index, 0L);
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a long or can be coerced to a long.
+   * Returns {@code fallback} otherwise.
+   *
+   * @param index Which value to get.
+   * @param fallback The fallback value to use if no value is at the specified location.
+   * @return the value at the specified location or the fallback value.
+   */
+  public long optLong(int index, long fallback) {
+    Object object = opt(index);
+    Long result = JSON.toLong(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists, coercing it if necessary.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if no such value exists.
+   */
+  public String getString(int index) throws JSONException {
+    Object object = get(index);
+    String result = JSON.toString(object);
+    if (result == null) {
+      throw JSON.typeMismatch(index, object, "String");
+    }
+    return result;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists, coercing it if necessary. Returns the empty
+   * string if no such value exists.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public String optString(int index) {
+    return optString(index, "");
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists, coercing it if necessary. Returns
+   * {@code fallback} if no such value exists.
+   *
+   * @param index Which value to get.
+   * @param fallback The fallback value to use if no value is at the specified location.
+   * @return the value at the specified location or the fallback value.
+   */
+  public String optString(int index, String fallback) {
+    Object object = opt(index);
+    String result = JSON.toString(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a {@code
+   * JSONArray}.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value doesn't exist or is not a {@code
+   *                       JSONArray}.
+   */
+  public JSONArray getJSONArray(int index) throws JSONException {
+    Object object = get(index);
+    if (object instanceof JSONArray) {
+      return (JSONArray) object;
+    } else {
+      throw JSON.typeMismatch(index, object, "JSONArray");
+    }
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a {@code
+   * JSONArray}. Returns null otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public JSONArray optJSONArray(int index) {
+    Object object = opt(index);
+    return object instanceof JSONArray ? (JSONArray) object : null;
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a {@code
+   * JSONObject}.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   * @throws JSONException if the value doesn't exist or is not a {@code
+   *                       JSONObject}.
+   */
+  public JSONObject getJSONObject(int index) throws JSONException {
+    Object object = get(index);
+    if (object instanceof JSONObject) {
+      return (JSONObject) object;
+    } else {
+      throw JSON.typeMismatch(index, object, "JSONObject");
+    }
+  }
+
+  /**
+   * Returns the value at {@code index} if it exists and is a {@code
+   * JSONObject}. Returns null otherwise.
+   *
+   * @param index Which value to get.
+   * @return the value at the specified location.
+   */
+  public JSONObject optJSONObject(int index) {
+    Object object = opt(index);
+    return object instanceof JSONObject ? (JSONObject) object : null;
+  }
+
+  /**
+   * Returns a new object whose values are the values in this array, and whose names are the values
+   * in {@code names}. Names and values are paired up by index from 0 through to the shorter array's
+   * length. Names that are not strings will be coerced to strings. This method returns null if
+   * either array is empty.
+   *
+   * @param names The names to apply to the returned values.
+   * @return the newly constructed object.
+   * @throws JSONException Should not be possible.
+   */
+  public JSONObject toJSONObject(JSONArray names) throws JSONException {
+    JSONObject result = new JSONObject();
+    int length = Math.min(names.length(), values.size());
+    if (length == 0) {
+      return null;
+    }
+    for (int i = 0; i < length; i++) {
+      String name = JSON.toString(names.opt(i));
+      result.put(name, opt(i));
+    }
+    return result;
+  }
+
+  /**
+   * Returns a new string by alternating this array's values with {@code
+   * separator}. This array's string values are quoted and have their special characters escaped.
+   * For example, the array containing the strings '12" pizza', 'taco' and 'soda' joined on '+'
+   * returns this:
+   * 
+   * <pre>
+   * "12\" pizza" + "taco" + "soda"
+   * </pre>
+   *
+   * @param separator The string used to separate the returned values.
+   * @return the conjoined values.
+   * @throws JSONException Only if there is a coding error.
+   */
+  public String join(String separator) throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.open(JSONStringer.Scope.NULL, "");
+    for (int i = 0, size = values.size(); i < size; i++) {
+      if (i > 0) {
+        stringer.out.append(separator);
+      }
+      stringer.value(values.get(i));
+    }
+    stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
+    return stringer.out.toString();
+  }
+
+  /**
+   * Encodes this array as a compact JSON string, such as:
+   * 
+   * <pre>
+   * [94043,90210]
+   * </pre>
+   *
+   * @return The string form of this array.
+   */
+  @Override
+  public String toString() {
+    try {
+      JSONStringer stringer = new JSONStringer();
+      writeTo(stringer);
+      return stringer.toString();
+    } catch (JSONException e) {
+      return null;
+    }
+  }
+
+  /**
+   * Encodes this array as a human readable JSON string for debugging, such as:
+   * 
+   * <pre>
+   * [
+   *     94043,
+   *     90210
+   * ]
+   * </pre>
+   *
+   * @param indentSpaces the number of spaces to indent for each level of nesting.
+   * @return The string form of this array.
+   * @throws JSONException Only if there is a coding error.
+   */
+  public String toString(int indentSpaces) throws JSONException {
+    JSONStringer stringer = new JSONStringer(indentSpaces);
+    writeTo(stringer);
+    return stringer.toString();
+  }
+
+  void writeTo(JSONStringer stringer) throws JSONException {
+    stringer.array();
+    for (Object value : values) {
+      stringer.value(value);
+    }
+    stringer.endArray();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    return o instanceof JSONArray && ((JSONArray) o).values.equals(values);
+  }
+
+  @Override
+  public int hashCode() {
+    // diverge from the original, which doesn't implement hashCode
+    return values.hashCode();
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/main/java/org/json/JSONException.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONException.java b/geode-json/src/main/java/org/json/JSONException.java
index 1292e86..83fb4b8 100755
--- a/geode-json/src/main/java/org/json/JSONException.java
+++ b/geode-json/src/main/java/org/json/JSONException.java
@@ -1,17 +1,15 @@
 /*
  * 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,37 +19,40 @@ package org.json;
 /**
  * Thrown to indicate a problem with the JSON API. Such problems include:
  * <ul>
- *   <li>Attempts to parse or construct malformed documents
- *   <li>Use of null as a name
- *   <li>Use of numeric types not available to JSON, such as {@link
- *       Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}.
- *   <li>Lookups using an out of range index or nonexistent name
- *   <li>Type mismatches on lookups
+ * <li>Attempts to parse or construct malformed documents
+ * <li>Use of null as a name
+ * <li>Use of numeric types not available to JSON, such as {@link Double#isNaN() NaNs} or
+ * {@link Double#isInfinite() infinities}.
+ * <li>Lookups using an out of range index or nonexistent name
+ * <li>Type mismatches on lookups
  * </ul>
  *
- * <p>Although this is a checked exception, it is rarely recoverable. Most
- * callers should simply wrap this exception in an unchecked exception and
- * rethrow:
- * <pre>  public JSONArray toJSONObject() {
+ * <p>
+ * Although this is a checked exception, it is rarely recoverable. Most callers should simply wrap
+ * this exception in an unchecked exception and rethrow:
+ * 
+ * <pre>
+ *   public JSONArray toJSONObject() {
  *     try {
  *         JSONObject result = new JSONObject();
  *         ...
  *     } catch (JSONException e) {
  *         throw new RuntimeException(e);
  *     }
- * }</pre>
+ * }
+ * </pre>
  */
 public class JSONException extends RuntimeException {
 
-    public JSONException(String s) {
-        super(s);
-    }
+  public JSONException(String s) {
+    super(s);
+  }
 
-    public JSONException(Throwable cause) {
-        super(cause);
-    }
+  public JSONException(Throwable cause) {
+    super(cause);
+  }
 
-    public JSONException(String message, Throwable cause) {
-        super(message, cause);
-    }
+  public JSONException(String message, Throwable cause) {
+    super(message, cause);
+  }
 }


[10/34] geode git commit: GEODE-2142: Removal of offending JSON.ORG code and license information

Posted by kl...@apache.org.
GEODE-2142: Removal of offending JSON.ORG code and license information


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/76ea6c3c
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/76ea6c3c
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/76ea6c3c

Branch: refs/heads/GEODE-4160-mockito
Commit: 76ea6c3cae06442fed9ca680d5aacedaf6a4f2dd
Parents: f2721dc
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 14:14:50 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 LICENSE                                         |   29 -
 geode-json/src/main/java/org/json/CDL.java      |  272 ----
 geode-json/src/main/java/org/json/Cookie.java   |  162 --
 .../src/main/java/org/json/CookieList.java      |   87 -
 geode-json/src/main/java/org/json/HTTP.java     |  185 ---
 .../src/main/java/org/json/HTTPTokener.java     |   77 -
 .../src/main/java/org/json/JSONArray.java       |  868 ----------
 .../src/main/java/org/json/JSONException.java   |   30 -
 geode-json/src/main/java/org/json/JSONML.java   |  454 ------
 .../src/main/java/org/json/JSONObject.java      | 1525 ------------------
 .../src/main/java/org/json/JSONString.java      |   17 -
 .../src/main/java/org/json/JSONStringer.java    |   75 -
 .../src/main/java/org/json/JSONTokener.java     |  437 -----
 .../src/main/java/org/json/JSONWriter.java      |  321 ----
 geode-json/src/main/java/org/json/XML.java      |  504 ------
 .../src/main/java/org/json/XMLTokener.java      |  362 -----
 16 files changed, 5405 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 4d22d30..e5f1557 100644
--- a/LICENSE
+++ b/LICENSE
@@ -275,35 +275,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 ---------------------------------------------------------------------------
-The JSON License (http://www.json.org/license.html)
----------------------------------------------------------------------------
-
-Apache Geode bundles the following file under the JSON license:
-
-  - JSON (http://www.json.org), Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-
----------------------------------------------------------------------------
 The MIT License (http://opensource.org/licenses/mit-license.html)
 ---------------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/CDL.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/CDL.java b/geode-json/src/main/java/org/json/CDL.java
deleted file mode 100755
index d78935b..0000000
--- a/geode-json/src/main/java/org/json/CDL.java
+++ /dev/null
@@ -1,272 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * This provides static methods to convert comma delimited text into a JSONArray, and to covert a
- * JSONArray into comma delimited text. Comma delimited text is a very popular format for data
- * interchange. It is understood by most database, spreadsheet, and organizer programs.
- * <p>
- * Each row of text represents a row in a table or a data record. Each row ends with a NEWLINE
- * character. Each row contains one or more values. Values are separated by commas. A value can
- * contain any character except for comma, unless is is wrapped in single quotes or double quotes.
- * <p>
- * The first row usually contains the names of the columns.
- * <p>
- * A comma delimited list can be converted into a JSONArray of JSONObjects. The names for the
- * elements in the JSONObjects can be taken from the names in the first row.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class CDL {
-
-  /**
-   * Get the next value. The value can be wrapped in quotes. The value can be empty.
-   * 
-   * @param x A JSONTokener of the source text.
-   * @return The value string, or null if empty.
-   * @throws JSONException if the quoted string is badly formed.
-   */
-  private static String getValue(JSONTokener x) throws JSONException {
-    char c;
-    char q;
-    StringBuffer sb;
-    do {
-      c = x.next();
-    } while (c == ' ' || c == '\t');
-    switch (c) {
-      case 0:
-        return null;
-      case '"':
-      case '\'':
-        q = c;
-        sb = new StringBuffer();
-        for (;;) {
-          c = x.next();
-          if (c == q) {
-            break;
-          }
-          if (c == 0 || c == '\n' || c == '\r') {
-            throw x.syntaxError("Missing close quote '" + q + "'.");
-          }
-          sb.append(c);
-        }
-        return sb.toString();
-      case ',':
-        x.back();
-        return "";
-      default:
-        x.back();
-        return x.nextTo(',');
-    }
-  }
-
-  /**
-   * Produce a JSONArray of strings from a row of comma delimited values.
-   * 
-   * @param x A JSONTokener of the source text.
-   * @return A JSONArray of strings.
-   * @throws JSONException
-   */
-  public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
-    JSONArray ja = new JSONArray();
-    for (;;) {
-      String value = getValue(x);
-      char c = x.next();
-      if (value == null || (ja.length() == 0 && value.length() == 0 && c != ',')) {
-        return null;
-      }
-      ja.put(value);
-      for (;;) {
-        if (c == ',') {
-          break;
-        }
-        if (c != ' ') {
-          if (c == '\n' || c == '\r' || c == 0) {
-            return ja;
-          }
-          throw x.syntaxError("Bad character '" + c + "' (" + (int) c + ").");
-        }
-        c = x.next();
-      }
-    }
-  }
-
-  /**
-   * Produce a JSONObject from a row of comma delimited text, using a parallel JSONArray of strings
-   * to provides the names of the elements.
-   * 
-   * @param names A JSONArray of names. This is commonly obtained from the first row of a comma
-   *        delimited text file using the rowToJSONArray method.
-   * @param x A JSONTokener of the source text.
-   * @return A JSONObject combining the names and values.
-   * @throws JSONException
-   */
-  public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws JSONException {
-    JSONArray ja = rowToJSONArray(x);
-    return ja != null ? ja.toJSONObject(names) : null;
-  }
-
-  /**
-   * Produce a comma delimited text row from a JSONArray. Values containing the comma character will
-   * be quoted. Troublesome characters may be removed.
-   * 
-   * @param ja A JSONArray of strings.
-   * @return A string ending in NEWLINE.
-   */
-  public static String rowToString(JSONArray ja) {
-    StringBuffer sb = new StringBuffer();
-    for (int i = 0; i < ja.length(); i += 1) {
-      if (i > 0) {
-        sb.append(',');
-      }
-      Object object = ja.opt(i);
-      if (object != null) {
-        String string = object.toString();
-        if (string.length() > 0 && (string.indexOf(',') >= 0 || string.indexOf('\n') >= 0
-            || string.indexOf('\r') >= 0 || string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
-          sb.append('"');
-          int length = string.length();
-          for (int j = 0; j < length; j += 1) {
-            char c = string.charAt(j);
-            if (c >= ' ' && c != '"') {
-              sb.append(c);
-            }
-          }
-          sb.append('"');
-        } else {
-          sb.append(string);
-        }
-      }
-    }
-    sb.append('\n');
-    return sb.toString();
-  }
-
-  /**
-   * Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a
-   * source of names.
-   * 
-   * @param string The comma delimited text.
-   * @return A JSONArray of JSONObjects.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(String string) throws JSONException {
-    return toJSONArray(new JSONTokener(string));
-  }
-
-  /**
-   * Produce a JSONArray of JSONObjects from a comma delimited text string, using the first row as a
-   * source of names.
-   * 
-   * @param x The JSONTokener containing the comma delimited text.
-   * @return A JSONArray of JSONObjects.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
-    return toJSONArray(rowToJSONArray(x), x);
-  }
-
-  /**
-   * Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied
-   * JSONArray as the source of element names.
-   * 
-   * @param names A JSONArray of strings.
-   * @param string The comma delimited text.
-   * @return A JSONArray of JSONObjects.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException {
-    return toJSONArray(names, new JSONTokener(string));
-  }
-
-  /**
-   * Produce a JSONArray of JSONObjects from a comma delimited text string using a supplied
-   * JSONArray as the source of element names.
-   * 
-   * @param names A JSONArray of strings.
-   * @param x A JSONTokener of the source text.
-   * @return A JSONArray of JSONObjects.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException {
-    if (names == null || names.length() == 0) {
-      return null;
-    }
-    JSONArray ja = new JSONArray();
-    for (;;) {
-      JSONObject jo = rowToJSONObject(names, x);
-      if (jo == null) {
-        break;
-      }
-      ja.put(jo);
-    }
-    if (ja.length() == 0) {
-      return null;
-    }
-    return ja;
-  }
-
-
-  /**
-   * Produce a comma delimited text from a JSONArray of JSONObjects. The first row will be a list of
-   * names obtained by inspecting the first JSONObject.
-   * 
-   * @param ja A JSONArray of JSONObjects.
-   * @return A comma delimited text.
-   * @throws JSONException
-   */
-  public static String toString(JSONArray ja) throws JSONException {
-    JSONObject jo = ja.optJSONObject(0);
-    if (jo != null) {
-      JSONArray names = jo.names();
-      if (names != null) {
-        return rowToString(names) + toString(names, ja);
-      }
-    }
-    return null;
-  }
-
-  /**
-   * Produce a comma delimited text from a JSONArray of JSONObjects using a provided list of names.
-   * The list of names is not included in the output.
-   * 
-   * @param names A JSONArray of strings.
-   * @param ja A JSONArray of JSONObjects.
-   * @return A comma delimited text.
-   * @throws JSONException
-   */
-  public static String toString(JSONArray names, JSONArray ja) throws JSONException {
-    if (names == null || names.length() == 0) {
-      return null;
-    }
-    StringBuffer sb = new StringBuffer();
-    for (int i = 0; i < ja.length(); i += 1) {
-      JSONObject jo = ja.optJSONObject(i);
-      if (jo != null) {
-        sb.append(rowToString(jo.toJSONArray(names)));
-      }
-    }
-    return sb.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/Cookie.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/Cookie.java b/geode-json/src/main/java/org/json/Cookie.java
deleted file mode 100755
index 21f88d8..0000000
--- a/geode-json/src/main/java/org/json/Cookie.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * Convert a web browser cookie specification to a JSONObject and back. JSON and Cookies are both
- * notations for name/value pairs.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class Cookie {
-
-  /**
-   * Produce a copy of a string in which the characters '+', '%', '=', ';' and control characters
-   * are replaced with "%hh". This is a gentle form of URL encoding, attempting to cause as little
-   * distortion to the string as possible. The characters '=' and ';' are meta characters in
-   * cookies. By convention, they are escaped using the URL-encoding. This is only a convention, not
-   * a standard. Often, cookies are expected to have encoded values. We encode '=' and ';' because
-   * we must. We encode '%' and '+' because they are meta characters in URL encoding.
-   * 
-   * @param string The source string.
-   * @return The escaped result.
-   */
-  public static String escape(String string) {
-    char c;
-    String s = string.trim();
-    StringBuffer sb = new StringBuffer();
-    int length = s.length();
-    for (int i = 0; i < length; i += 1) {
-      c = s.charAt(i);
-      if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
-        sb.append('%');
-        sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
-        sb.append(Character.forDigit((char) (c & 0x0f), 16));
-      } else {
-        sb.append(c);
-      }
-    }
-    return sb.toString();
-  }
-
-
-  /**
-   * Convert a cookie specification string into a JSONObject. The string will contain a name value
-   * pair separated by '='. The name and the value will be unescaped, possibly converting '+' and
-   * '%' sequences. The cookie properties may follow, separated by ';', also represented as
-   * name=value (except the secure property, which does not have a value). The name will be stored
-   * under the key "name", and the value will be stored under the key "value". This method does not
-   * do checking or validation of the parameters. It only converts the cookie string into a
-   * JSONObject.
-   * 
-   * @param string The cookie specification string.
-   * @return A JSONObject containing "name", "value", and possibly other members.
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(String string) throws JSONException {
-    String name;
-    JSONObject jo = new JSONObject();
-    Object value;
-    JSONTokener x = new JSONTokener(string);
-    jo.put("name", x.nextTo('='));
-    x.next('=');
-    jo.put("value", x.nextTo(';'));
-    x.next();
-    while (x.more()) {
-      name = unescape(x.nextTo("=;"));
-      if (x.next() != '=') {
-        if (name.equals("secure")) {
-          value = Boolean.TRUE;
-        } else {
-          throw x.syntaxError("Missing '=' in cookie parameter.");
-        }
-      } else {
-        value = unescape(x.nextTo(';'));
-        x.next();
-      }
-      jo.put(name, value);
-    }
-    return jo;
-  }
-
-
-  /**
-   * Convert a JSONObject into a cookie specification string. The JSONObject must contain "name" and
-   * "value" members. If the JSONObject contains "expires", "domain", "path", or "secure" members,
-   * they will be appended to the cookie specification string. All other members are ignored.
-   * 
-   * @param jo A JSONObject
-   * @return A cookie specification string
-   * @throws JSONException
-   */
-  public static String toString(JSONObject jo) throws JSONException {
-    StringBuffer sb = new StringBuffer();
-
-    sb.append(escape(jo.getString("name")));
-    sb.append("=");
-    sb.append(escape(jo.getString("value")));
-    if (jo.has("expires")) {
-      sb.append(";expires=");
-      sb.append(jo.getString("expires"));
-    }
-    if (jo.has("domain")) {
-      sb.append(";domain=");
-      sb.append(escape(jo.getString("domain")));
-    }
-    if (jo.has("path")) {
-      sb.append(";path=");
-      sb.append(escape(jo.getString("path")));
-    }
-    if (jo.optBoolean("secure")) {
-      sb.append(";secure");
-    }
-    return sb.toString();
-  }
-
-  /**
-   * Convert <code>%</code><i>hh</i> sequences to single characters, and convert plus to space.
-   * 
-   * @param string A string that may contain <code>+</code>&nbsp;<small>(plus)</small> and
-   *        <code>%</code><i>hh</i> sequences.
-   * @return The unescaped string.
-   */
-  public static String unescape(String string) {
-    int length = string.length();
-    StringBuffer sb = new StringBuffer();
-    for (int i = 0; i < length; ++i) {
-      char c = string.charAt(i);
-      if (c == '+') {
-        c = ' ';
-      } else if (c == '%' && i + 2 < length) {
-        int d = JSONTokener.dehexchar(string.charAt(i + 1));
-        int e = JSONTokener.dehexchar(string.charAt(i + 2));
-        if (d >= 0 && e >= 0) {
-          c = (char) (d * 16 + e);
-          i += 2;
-        }
-      }
-      sb.append(c);
-    }
-    return sb.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/CookieList.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/CookieList.java b/geode-json/src/main/java/org/json/CookieList.java
deleted file mode 100755
index 35e1a97..0000000
--- a/geode-json/src/main/java/org/json/CookieList.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.util.Iterator;
-
-/**
- * Convert a web browser cookie list string to a JSONObject and back.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class CookieList {
-
-  /**
-   * Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The
-   * names are separated from the values by '='. The pairs are separated by ';'. The names and the
-   * values will be unescaped, possibly converting '+' and '%' sequences.
-   *
-   * To add a cookie to a cooklist, cookielistJSONObject.put(cookieJSONObject.getString("name"),
-   * cookieJSONObject.getString("value"));
-   * 
-   * @param string A cookie list string
-   * @return A JSONObject
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(String string) throws JSONException {
-    JSONObject jo = new JSONObject();
-    JSONTokener x = new JSONTokener(string);
-    while (x.more()) {
-      String name = Cookie.unescape(x.nextTo('='));
-      x.next('=');
-      jo.put(name, Cookie.unescape(x.nextTo(';')));
-      x.next();
-    }
-    return jo;
-  }
-
-
-  /**
-   * Convert a JSONObject into a cookie list. A cookie list is a sequence of name/value pairs. The
-   * names are separated from the values by '='. The pairs are separated by ';'. The characters '%',
-   * '+', '=', and ';' in the names and values are replaced by "%hh".
-   * 
-   * @param jo A JSONObject
-   * @return A cookie list string
-   * @throws JSONException
-   */
-  public static String toString(JSONObject jo) throws JSONException {
-    boolean b = false;
-    Iterator keys = jo.keys();
-    String string;
-    StringBuffer sb = new StringBuffer();
-    while (keys.hasNext()) {
-      string = keys.next().toString();
-      if (!jo.isNull(string)) {
-        if (b) {
-          sb.append(';');
-        }
-        sb.append(Cookie.escape(string));
-        sb.append("=");
-        sb.append(Cookie.escape(jo.getString(string)));
-        b = true;
-      }
-    }
-    return sb.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/HTTP.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/HTTP.java b/geode-json/src/main/java/org/json/HTTP.java
deleted file mode 100755
index 1e815aa..0000000
--- a/geode-json/src/main/java/org/json/HTTP.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.util.Iterator;
-
-/**
- * Convert an HTTP header to a JSONObject and back.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class HTTP {
-
-  /** Carriage return/line feed. */
-  public static final String CRLF = "\r\n";
-
-  /**
-   * Convert an HTTP header string into a JSONObject. It can be a request header or a response
-   * header. A request header will contain
-   * 
-   * <pre>
-   * {
-   *    Method: "POST" (for example),
-   *    "Request-URI": "/" (for example),
-   *    "HTTP-Version": "HTTP/1.1" (for example)
-   * }
-   * </pre>
-   * 
-   * A response header will contain
-   * 
-   * <pre>
-   * {
-   *    "HTTP-Version": "HTTP/1.1" (for example),
-   *    "Status-Code": "200" (for example),
-   *    "Reason-Phrase": "OK" (for example)
-   * }
-   * </pre>
-   * 
-   * In addition, the other parameters in the header will be captured, using the HTTP field names as
-   * JSON names, so that
-   * 
-   * <pre>
-   *    Date: Sun, 26 May 2002 18:06:04 GMT
-   *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
-   *    Cache-Control: no-cache
-   * </pre>
-   * 
-   * become
-   * 
-   * <pre>
-   * {...
-   *    Date: "Sun, 26 May 2002 18:06:04 GMT",
-   *    Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
-   *    "Cache-Control": "no-cache",
-   * ...}
-   * </pre>
-   * 
-   * It does no further checking or conversion. It does not parse dates. It does not do '%'
-   * transforms on URLs.
-   * 
-   * @param string An HTTP header string.
-   * @return A JSONObject containing the elements and attributes of the XML string.
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(String string) throws JSONException {
-    JSONObject jo = new JSONObject();
-    HTTPTokener x = new HTTPTokener(string);
-    String token;
-
-    token = x.nextToken();
-    if (token.toUpperCase().startsWith("HTTP")) {
-
-      // Response
-
-      jo.put("HTTP-Version", token);
-      jo.put("Status-Code", x.nextToken());
-      jo.put("Reason-Phrase", x.nextTo('\0'));
-      x.next();
-
-    } else {
-
-      // Request
-
-      jo.put("Method", token);
-      jo.put("Request-URI", x.nextToken());
-      jo.put("HTTP-Version", x.nextToken());
-    }
-
-    // Fields
-
-    while (x.more()) {
-      String name = x.nextTo(':');
-      x.next(':');
-      jo.put(name, x.nextTo('\0'));
-      x.next();
-    }
-    return jo;
-  }
-
-
-  /**
-   * Convert a JSONObject into an HTTP header. A request header must contain
-   * 
-   * <pre>
-   * {
-   *    Method: "POST" (for example),
-   *    "Request-URI": "/" (for example),
-   *    "HTTP-Version": "HTTP/1.1" (for example)
-   * }
-   * </pre>
-   * 
-   * A response header must contain
-   * 
-   * <pre>
-   * {
-   *    "HTTP-Version": "HTTP/1.1" (for example),
-   *    "Status-Code": "200" (for example),
-   *    "Reason-Phrase": "OK" (for example)
-   * }
-   * </pre>
-   * 
-   * Any other members of the JSONObject will be output as HTTP fields. The result will end with two
-   * CRLF pairs.
-   * 
-   * @param jo A JSONObject
-   * @return An HTTP header string.
-   * @throws JSONException if the object does not contain enough information.
-   */
-  public static String toString(JSONObject jo) throws JSONException {
-    Iterator keys = jo.keys();
-    String string;
-    StringBuffer sb = new StringBuffer();
-    if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
-      sb.append(jo.getString("HTTP-Version"));
-      sb.append(' ');
-      sb.append(jo.getString("Status-Code"));
-      sb.append(' ');
-      sb.append(jo.getString("Reason-Phrase"));
-    } else if (jo.has("Method") && jo.has("Request-URI")) {
-      sb.append(jo.getString("Method"));
-      sb.append(' ');
-      sb.append('"');
-      sb.append(jo.getString("Request-URI"));
-      sb.append('"');
-      sb.append(' ');
-      sb.append(jo.getString("HTTP-Version"));
-    } else {
-      throw new JSONException("Not enough material for an HTTP header.");
-    }
-    sb.append(CRLF);
-    while (keys.hasNext()) {
-      string = keys.next().toString();
-      if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string)
-          && !"Reason-Phrase".equals(string) && !"Method".equals(string)
-          && !"Request-URI".equals(string) && !jo.isNull(string)) {
-        sb.append(string);
-        sb.append(": ");
-        sb.append(jo.getString(string));
-        sb.append(CRLF);
-      }
-    }
-    sb.append(CRLF);
-    return sb.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/HTTPTokener.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/HTTPTokener.java b/geode-json/src/main/java/org/json/HTTPTokener.java
deleted file mode 100755
index 72c9b88..0000000
--- a/geode-json/src/main/java/org/json/HTTPTokener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * The HTTPTokener extends the JSONTokener to provide additional methods for the parsing of HTTP
- * headers.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class HTTPTokener extends JSONTokener {
-
-  /**
-   * Construct an HTTPTokener from a string.
-   * 
-   * @param string A source string.
-   */
-  public HTTPTokener(String string) {
-    super(string);
-  }
-
-
-  /**
-   * Get the next token or string. This is used in parsing HTTP headers.
-   * 
-   * @throws JSONException
-   * @return A String.
-   */
-  public String nextToken() throws JSONException {
-    char c;
-    char q;
-    StringBuffer sb = new StringBuffer();
-    do {
-      c = next();
-    } while (Character.isWhitespace(c));
-    if (c == '"' || c == '\'') {
-      q = c;
-      for (;;) {
-        c = next();
-        if (c < ' ') {
-          throw syntaxError("Unterminated string.");
-        }
-        if (c == q) {
-          return sb.toString();
-        }
-        sb.append(c);
-      }
-    }
-    for (;;) {
-      if (c == 0 || Character.isWhitespace(c)) {
-        return sb.toString();
-      }
-      sb.append(c);
-      c = next();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/JSONArray.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONArray.java b/geode-json/src/main/java/org/json/JSONArray.java
deleted file mode 100644
index edaefa4..0000000
--- a/geode-json/src/main/java/org/json/JSONArray.java
+++ /dev/null
@@ -1,868 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in
- * square brackets with commas separating the values. The internal form is an object having
- * <code>get</code> and <code>opt</code> methods for accessing the values by index, and
- * <code>put</code> methods for adding or replacing values. The values can be any of these types:
- * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,
- * <code>String</code>, or the <code>JSONObject.NULL object</code>.
- * <p>
- * The constructor can convert a JSON text into a Java object. The <code>toString</code> method
- * converts to JSON text.
- * <p>
- * A <code>get</code> method returns a value if one can be found, and throws an exception if one
- * cannot be found. An <code>opt</code> method returns a default value instead of throwing an
- * exception, and so is useful for obtaining optional values.
- * <p>
- * The generic <code>get()</code> and <code>opt()</code> methods return an object which you can cast
- * or query for type. There are also typed <code>get</code> and <code>opt</code> methods that do
- * type checking and type coercion for you.
- * <p>
- * The texts produced by the <code>toString</code> methods strictly conform to JSON syntax rules.
- * The constructors are more forgiving in the texts they will accept:
- * <ul>
- * <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear just before the closing
- * bracket.</li>
- * <li>The <code>null</code> value will be inserted when there is <code>,</code>
- * &nbsp;<small>(comma)</small> elision.</li>
- * <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single quote)</small>.</li>
- * <li>Strings do not need to be quoted at all if they do not begin with a quote or single quote,
- * and if they do not contain leading or trailing spaces, and if they do not contain any of these
- * characters: <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and if they
- * are not the reserved words <code>true</code>, <code>false</code>, or <code>null</code>.</li>
- * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as well as by
- * <code>,</code> <small>(comma)</small>.</li>
- * </ul>
- *
- * @author JSON.org
- * @version 2012-04-20
- */
-public class JSONArray {
-
-
-  /**
-   * The arrayList where the JSONArray's properties are kept.
-   */
-  private final ArrayList myArrayList;
-
-
-  /**
-   * Construct an empty JSONArray.
-   */
-  public JSONArray() {
-    this.myArrayList = new ArrayList();
-  }
-
-  /**
-   * Construct a JSONArray from a JSONTokener.
-   * 
-   * @param x A JSONTokener
-   * @throws JSONException If there is a syntax error.
-   */
-  public JSONArray(JSONTokener x) throws JSONException {
-    this();
-    if (x.nextClean() != '[') {
-      throw x.syntaxError("A JSONArray text must start with '['");
-    }
-    if (x.nextClean() != ']') {
-      x.back();
-      for (;;) {
-        if (x.nextClean() == ',') {
-          x.back();
-          this.myArrayList.add(JSONObject.NULL);
-        } else {
-          x.back();
-          this.myArrayList.add(x.nextValue());
-        }
-        switch (x.nextClean()) {
-          case ';':
-          case ',':
-            if (x.nextClean() == ']') {
-              return;
-            }
-            x.back();
-            break;
-          case ']':
-            return;
-          default:
-            throw x.syntaxError("Expected a ',' or ']'");
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONArray from a source JSON text.
-   * 
-   * @param source A string that begins with <code>[</code>&nbsp;<small>(left bracket)</small> and
-   *        ends with <code>]</code>&nbsp;<small>(right bracket)</small>.
-   * @throws JSONException If there is a syntax error.
-   */
-  public JSONArray(String source) throws JSONException {
-    this(new JSONTokener(source));
-  }
-
-
-  /**
-   * Construct a JSONArray from a Collection.
-   * 
-   * @param collection A Collection.
-   */
-  public JSONArray(Collection collection) {
-    this.myArrayList = new ArrayList();
-    if (collection != null) {
-      Iterator iter = collection.iterator();
-      while (iter.hasNext()) {
-        this.myArrayList.add(JSONObject.wrap(iter.next()));
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONArray from an array
-   * 
-   * @throws JSONException If not an array.
-   */
-  public JSONArray(Object array) throws JSONException {
-    this();
-    if (array.getClass().isArray()) {
-      int length = Array.getLength(array);
-      for (int i = 0; i < length; i += 1) {
-        this.put(JSONObject.wrap(Array.get(array, i)));
-      }
-    } else {
-      throw new JSONException("JSONArray initial value should be a string or collection or array.");
-    }
-  }
-
-
-  /**
-   * Get the object value associated with an index.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @return An object value.
-   * @throws JSONException If there is no value for the index.
-   */
-  public Object get(int index) throws JSONException {
-    Object object = this.opt(index);
-    if (object == null) {
-      throw new JSONException("JSONArray[" + index + "] not found.");
-    }
-    return object;
-  }
-
-
-  /**
-   * Get the boolean value associated with an index. The string values "true" and "false" are
-   * converted to boolean.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The truth.
-   * @throws JSONException If there is no value for the index or if the value is not convertible to
-   *         boolean.
-   */
-  public boolean getBoolean(int index) throws JSONException {
-    Object object = this.get(index);
-    if (object.equals(Boolean.FALSE)
-        || (object instanceof String && ((String) object).equalsIgnoreCase("false"))) {
-      return false;
-    } else if (object.equals(Boolean.TRUE)
-        || (object instanceof String && ((String) object).equalsIgnoreCase("true"))) {
-      return true;
-    }
-    throw new JSONException("JSONArray[" + index + "] is not a boolean.");
-  }
-
-
-  /**
-   * Get the double value associated with an index.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   * @throws JSONException If the key is not found or if the value cannot be converted to a number.
-   */
-  public double getDouble(int index) throws JSONException {
-    Object object = this.get(index);
-    try {
-      return object instanceof Number ? ((Number) object).doubleValue()
-          : Double.parseDouble((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONArray[" + index + "] is not a number.");
-    }
-  }
-
-
-  /**
-   * Get the int value associated with an index.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   * @throws JSONException If the key is not found or if the value is not a number.
-   */
-  public int getInt(int index) throws JSONException {
-    Object object = this.get(index);
-    try {
-      return object instanceof Number ? ((Number) object).intValue()
-          : Integer.parseInt((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONArray[" + index + "] is not a number.");
-    }
-  }
-
-
-  /**
-   * Get the JSONArray associated with an index.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @return A JSONArray value.
-   * @throws JSONException If there is no value for the index. or if the value is not a JSONArray
-   */
-  public JSONArray getJSONArray(int index) throws JSONException {
-    Object object = this.get(index);
-    if (object instanceof JSONArray) {
-      return (JSONArray) object;
-    }
-    throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
-  }
-
-
-  /**
-   * Get the JSONObject associated with an index.
-   * 
-   * @param index subscript
-   * @return A JSONObject value.
-   * @throws JSONException If there is no value for the index or if the value is not a JSONObject
-   */
-  public JSONObject getJSONObject(int index) throws JSONException {
-    Object object = this.get(index);
-    if (object instanceof JSONObject) {
-      return (JSONObject) object;
-    }
-    throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
-  }
-
-
-  /**
-   * Get the long value associated with an index.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   * @throws JSONException If the key is not found or if the value cannot be converted to a number.
-   */
-  public long getLong(int index) throws JSONException {
-    Object object = this.get(index);
-    try {
-      return object instanceof Number ? ((Number) object).longValue()
-          : Long.parseLong((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONArray[" + index + "] is not a number.");
-    }
-  }
-
-
-  /**
-   * Get the string associated with an index.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @return A string value.
-   * @throws JSONException If there is no string value for the index.
-   */
-  public String getString(int index) throws JSONException {
-    Object object = this.get(index);
-    if (object instanceof String) {
-      return (String) object;
-    }
-    throw new JSONException("JSONArray[" + index + "] not a string.");
-  }
-
-
-  /**
-   * Determine if the value is null.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @return true if the value at the index is null, or if there is no value.
-   */
-  public boolean isNull(int index) {
-    return JSONObject.NULL.equals(this.opt(index));
-  }
-
-
-  /**
-   * Make a string from the contents of this JSONArray. The <code>separator</code> string is
-   * inserted between each element. Warning: This method assumes that the data structure is
-   * acyclical.
-   * 
-   * @param separator A string that will be inserted between the elements.
-   * @return a string.
-   * @throws JSONException If the array contains an invalid number.
-   */
-  public String join(String separator) throws JSONException {
-    int len = this.length();
-    StringBuffer sb = new StringBuffer();
-
-    for (int i = 0; i < len; i += 1) {
-      if (i > 0) {
-        sb.append(separator);
-      }
-      sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
-    }
-    return sb.toString();
-  }
-
-
-  /**
-   * Get the number of elements in the JSONArray, included nulls.
-   *
-   * @return The length (or size).
-   */
-  public int length() {
-    return this.myArrayList.size();
-  }
-
-
-  /**
-   * Get the optional object value associated with an index.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @return An object value, or null if there is no object at that index.
-   */
-  public Object opt(int index) {
-    return (index < 0 || index >= this.length()) ? null : this.myArrayList.get(index);
-  }
-
-
-  /**
-   * Get the optional boolean value associated with an index. It returns false if there is no value
-   * at that index, or if the value is not Boolean.TRUE or the String "true".
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The truth.
-   */
-  public boolean optBoolean(int index) {
-    return this.optBoolean(index, false);
-  }
-
-
-  /**
-   * Get the optional boolean value associated with an index. It returns the defaultValue if there
-   * is no value at that index or if it is not a Boolean or the String "true" or "false" (case
-   * insensitive).
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @param defaultValue A boolean default.
-   * @return The truth.
-   */
-  public boolean optBoolean(int index, boolean defaultValue) {
-    try {
-      return this.getBoolean(index);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get the optional double value associated with an index. NaN is returned if there is no value
-   * for the index, or if the value is not a number and cannot be converted to a number.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   */
-  public double optDouble(int index) {
-    return this.optDouble(index, Double.NaN);
-  }
-
-
-  /**
-   * Get the optional double value associated with an index. The defaultValue is returned if there
-   * is no value for the index, or if the value is not a number and cannot be converted to a number.
-   *
-   * @param index subscript
-   * @param defaultValue The default value.
-   * @return The value.
-   */
-  public double optDouble(int index, double defaultValue) {
-    try {
-      return this.getDouble(index);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get the optional int value associated with an index. Zero is returned if there is no value for
-   * the index, or if the value is not a number and cannot be converted to a number.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   */
-  public int optInt(int index) {
-    return this.optInt(index, 0);
-  }
-
-
-  /**
-   * Get the optional int value associated with an index. The defaultValue is returned if there is
-   * no value for the index, or if the value is not a number and cannot be converted to a number.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @param defaultValue The default value.
-   * @return The value.
-   */
-  public int optInt(int index, int defaultValue) {
-    try {
-      return this.getInt(index);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get the optional JSONArray associated with an index.
-   * 
-   * @param index subscript
-   * @return A JSONArray value, or null if the index has no value, or if the value is not a
-   *         JSONArray.
-   */
-  public JSONArray optJSONArray(int index) {
-    Object o = this.opt(index);
-    return o instanceof JSONArray ? (JSONArray) o : null;
-  }
-
-
-  /**
-   * Get the optional JSONObject associated with an index. Null is returned if the key is not found,
-   * or null if the index has no value, or if the value is not a JSONObject.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return A JSONObject value.
-   */
-  public JSONObject optJSONObject(int index) {
-    Object o = this.opt(index);
-    return o instanceof JSONObject ? (JSONObject) o : null;
-  }
-
-
-  /**
-   * Get the optional long value associated with an index. Zero is returned if there is no value for
-   * the index, or if the value is not a number and cannot be converted to a number.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return The value.
-   */
-  public long optLong(int index) {
-    return this.optLong(index, 0);
-  }
-
-
-  /**
-   * Get the optional long value associated with an index. The defaultValue is returned if there is
-   * no value for the index, or if the value is not a number and cannot be converted to a number.
-   * 
-   * @param index The index must be between 0 and length() - 1.
-   * @param defaultValue The default value.
-   * @return The value.
-   */
-  public long optLong(int index, long defaultValue) {
-    try {
-      return this.getLong(index);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get the optional string value associated with an index. It returns an empty string if there is
-   * no value at that index. If the value is not a string and is not null, then it is coverted to a
-   * string.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @return A String value.
-   */
-  public String optString(int index) {
-    return this.optString(index, "");
-  }
-
-
-  /**
-   * Get the optional string associated with an index. The defaultValue is returned if the key is
-   * not found.
-   *
-   * @param index The index must be between 0 and length() - 1.
-   * @param defaultValue The default value.
-   * @return A String value.
-   */
-  public String optString(int index, String defaultValue) {
-    Object object = this.opt(index);
-    return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
-  }
-
-
-  /**
-   * Append a boolean value. This increases the array's length by one.
-   *
-   * @param value A boolean value.
-   * @return this.
-   */
-  public JSONArray put(boolean value) {
-    this.put(value ? Boolean.TRUE : Boolean.FALSE);
-    return this;
-  }
-
-
-  /**
-   * Put a value in the JSONArray, where the value will be a JSONArray which is produced from a
-   * Collection.
-   * 
-   * @param value A Collection value.
-   * @return this.
-   */
-  public JSONArray put(Collection value) {
-    this.put(new JSONArray(value));
-    return this;
-  }
-
-
-  /**
-   * Append a double value. This increases the array's length by one.
-   *
-   * @param value A double value.
-   * @throws JSONException if the value is not finite.
-   * @return this.
-   */
-  public JSONArray put(double value) throws JSONException {
-    Double d = new Double(value);
-    JSONObject.testValidity(d);
-    this.put(d);
-    return this;
-  }
-
-
-  /**
-   * Append an int value. This increases the array's length by one.
-   *
-   * @param value An int value.
-   * @return this.
-   */
-  public JSONArray put(int value) {
-    this.put(new Integer(value));
-    return this;
-  }
-
-
-  /**
-   * Append an long value. This increases the array's length by one.
-   *
-   * @param value A long value.
-   * @return this.
-   */
-  public JSONArray put(long value) {
-    this.put(new Long(value));
-    return this;
-  }
-
-
-  /**
-   * Put a value in the JSONArray, where the value will be a JSONObject which is produced from a
-   * Map.
-   * 
-   * @param value A Map value.
-   * @return this.
-   */
-  public JSONArray put(Map value) {
-    this.put(new JSONObject(value));
-    return this;
-  }
-
-
-  /**
-   * Append an object value. This increases the array's length by one.
-   * 
-   * @param value An object value. The value should be a Boolean, Double, Integer, JSONArray,
-   *        JSONObject, Long, or String, or the JSONObject.NULL object.
-   * @return this.
-   */
-  public JSONArray put(Object value) {
-    this.myArrayList.add(value);
-    return this;
-  }
-
-
-  /**
-   * Put or replace a boolean value in the JSONArray. If the index is greater than the length of the
-   * JSONArray, then null elements will be added as necessary to pad it out.
-   * 
-   * @param index The subscript.
-   * @param value A boolean value.
-   * @return this.
-   * @throws JSONException If the index is negative.
-   */
-  public JSONArray put(int index, boolean value) throws JSONException {
-    this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
-    return this;
-  }
-
-
-  /**
-   * Put a value in the JSONArray, where the value will be a JSONArray which is produced from a
-   * Collection.
-   * 
-   * @param index The subscript.
-   * @param value A Collection value.
-   * @return this.
-   * @throws JSONException If the index is negative or if the value is not finite.
-   */
-  public JSONArray put(int index, Collection value) throws JSONException {
-    this.put(index, new JSONArray(value));
-    return this;
-  }
-
-
-  /**
-   * Put or replace a double value. If the index is greater than the length of the JSONArray, then
-   * null elements will be added as necessary to pad it out.
-   * 
-   * @param index The subscript.
-   * @param value A double value.
-   * @return this.
-   * @throws JSONException If the index is negative or if the value is not finite.
-   */
-  public JSONArray put(int index, double value) throws JSONException {
-    this.put(index, new Double(value));
-    return this;
-  }
-
-
-  /**
-   * Put or replace an int value. If the index is greater than the length of the JSONArray, then
-   * null elements will be added as necessary to pad it out.
-   * 
-   * @param index The subscript.
-   * @param value An int value.
-   * @return this.
-   * @throws JSONException If the index is negative.
-   */
-  public JSONArray put(int index, int value) throws JSONException {
-    this.put(index, new Integer(value));
-    return this;
-  }
-
-
-  /**
-   * Put or replace a long value. If the index is greater than the length of the JSONArray, then
-   * null elements will be added as necessary to pad it out.
-   * 
-   * @param index The subscript.
-   * @param value A long value.
-   * @return this.
-   * @throws JSONException If the index is negative.
-   */
-  public JSONArray put(int index, long value) throws JSONException {
-    this.put(index, new Long(value));
-    return this;
-  }
-
-
-  /**
-   * Put a value in the JSONArray, where the value will be a JSONObject that is produced from a Map.
-   * 
-   * @param index The subscript.
-   * @param value The Map value.
-   * @return this.
-   * @throws JSONException If the index is negative or if the the value is an invalid number.
-   */
-  public JSONArray put(int index, Map value) throws JSONException {
-    this.put(index, new JSONObject(value));
-    return this;
-  }
-
-
-  /**
-   * Put or replace an object value in the JSONArray. If the index is greater than the length of the
-   * JSONArray, then null elements will be added as necessary to pad it out.
-   * 
-   * @param index The subscript.
-   * @param value The value to put into the array. The value should be a Boolean, Double, Integer,
-   *        JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
-   * @return this.
-   * @throws JSONException If the index is negative or if the the value is an invalid number.
-   */
-  public JSONArray put(int index, Object value) throws JSONException {
-    JSONObject.testValidity(value);
-    if (index < 0) {
-      throw new JSONException("JSONArray[" + index + "] not found.");
-    }
-    if (index < this.length()) {
-      this.myArrayList.set(index, value);
-    } else {
-      while (index != this.length()) {
-        this.put(JSONObject.NULL);
-      }
-      this.put(value);
-    }
-    return this;
-  }
-
-
-  /**
-   * Remove an index and close the hole.
-   * 
-   * @param index The index of the element to be removed.
-   * @return The value that was associated with the index, or null if there was no value.
-   */
-  public Object remove(int index) {
-    Object o = this.opt(index);
-    this.myArrayList.remove(index);
-    return o;
-  }
-
-
-  /**
-   * Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
-   * 
-   * @param names A JSONArray containing a list of key strings. These will be paired with the
-   *        values.
-   * @return A JSONObject, or null if there are no names or if this JSONArray has no values.
-   * @throws JSONException If any of the names are null.
-   */
-  public JSONObject toJSONObject(JSONArray names) throws JSONException {
-    if (names == null || names.length() == 0 || this.length() == 0) {
-      return null;
-    }
-    JSONObject jo = new JSONObject();
-    for (int i = 0; i < names.length(); i += 1) {
-      jo.put(names.getString(i), this.opt(i));
-    }
-    return jo;
-  }
-
-
-  /**
-   * Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it
-   * is not possible to produce a syntactically correct JSON text then null will be returned
-   * instead. This could occur if the array contains an invalid number.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @return a printable, displayable, transmittable representation of the array.
-   */
-  public String toString() {
-    try {
-      return '[' + this.join(",") + ']';
-    } catch (Exception e) {
-      return null;
-    }
-  }
-
-
-  /**
-   * Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data
-   * structure is acyclical.
-   * 
-   * @param indentFactor The number of spaces to add to each level of indentation.
-   * @return a printable, displayable, transmittable representation of the object, beginning with
-   *         <code>[</code>&nbsp;<small>(left bracket)</small> and ending with
-   *         <code>]</code>&nbsp;<small>(right bracket)</small>.
-   * @throws JSONException
-   */
-  public String toString(int indentFactor) throws JSONException {
-    StringWriter sw = new StringWriter();
-    synchronized (sw.getBuffer()) {
-      return this.write(sw, indentFactor, 0).toString();
-    }
-  }
-
-  /**
-   * Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is
-   * added.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @return The writer.
-   * @throws JSONException
-   */
-  public Writer write(Writer writer) throws JSONException {
-    return this.write(writer, 0, 0);
-  }
-
-  /**
-   * Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is
-   * added.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @param indentFactor The number of spaces to add to each level of indentation.
-   * @param indent The indention of the top level.
-   * @return The writer.
-   * @throws JSONException
-   */
-  Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
-    try {
-      boolean commanate = false;
-      int length = this.length();
-      writer.write('[');
-
-      if (length == 1) {
-        JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
-      } else if (length != 0) {
-        final int newindent = indent + indentFactor;
-
-        for (int i = 0; i < length; i += 1) {
-          if (commanate) {
-            writer.write(',');
-          }
-          if (indentFactor > 0) {
-            writer.write('\n');
-          }
-          JSONObject.indent(writer, newindent);
-          JSONObject.writeValue(writer, this.myArrayList.get(i), indentFactor, newindent);
-          commanate = true;
-        }
-        if (indentFactor > 0) {
-          writer.write('\n');
-        }
-        JSONObject.indent(writer, indent);
-      }
-      writer.write(']');
-      return writer;
-    } catch (IOException e) {
-      throw new JSONException(e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/JSONException.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONException.java b/geode-json/src/main/java/org/json/JSONException.java
deleted file mode 100755
index b65efe2..0000000
--- a/geode-json/src/main/java/org/json/JSONException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.json;
-
-/**
- * The JSONException is thrown by the JSON.org classes when things are amiss.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class JSONException extends Exception {
-  private static final long serialVersionUID = 0;
-  private Throwable cause;
-
-  /**
-   * Constructs a JSONException with an explanatory message.
-   * 
-   * @param message Detail about the reason for the exception.
-   */
-  public JSONException(String message) {
-    super(message);
-  }
-
-  public JSONException(Throwable cause) {
-    super(cause.getMessage());
-    this.cause = cause;
-  }
-
-  public Throwable getCause() {
-    return this.cause;
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/JSONML.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONML.java b/geode-json/src/main/java/org/json/JSONML.java
deleted file mode 100755
index b535614..0000000
--- a/geode-json/src/main/java/org/json/JSONML.java
+++ /dev/null
@@ -1,454 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2008 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.util.Iterator;
-
-
-/**
- * This provides static methods to convert an XML text into a JSONArray or JSONObject, and to covert
- * a JSONArray or JSONObject into an XML text using the JsonML transform.
- * 
- * @author JSON.org
- * @version 2012-03-28
- */
-public class JSONML {
-
-  /**
-   * Parse XML values and store them in a JSONArray.
-   * 
-   * @param x The XMLTokener containing the source string.
-   * @param arrayForm true if array form, false if object form.
-   * @param ja The JSONArray that is containing the current tag or null if we are at the outermost
-   *        level.
-   * @return A JSONArray if the value is the outermost tag, otherwise null.
-   * @throws JSONException
-   */
-  private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException {
-    String attribute;
-    char c;
-    String closeTag = null;
-    int i;
-    JSONArray newja = null;
-    JSONObject newjo = null;
-    Object token;
-    String tagName = null;
-
-    // Test for and skip past these forms:
-    // <!-- ... -->
-    // <![ ... ]]>
-    // <! ... >
-    // <? ... ?>
-
-    while (true) {
-      if (!x.more()) {
-        throw x.syntaxError("Bad XML");
-      }
-      token = x.nextContent();
-      if (token == XML.LT) {
-        token = x.nextToken();
-        if (token instanceof Character) {
-          if (token == XML.SLASH) {
-
-            // Close tag </
-
-            token = x.nextToken();
-            if (!(token instanceof String)) {
-              throw new JSONException("Expected a closing name instead of '" + token + "'.");
-            }
-            if (x.nextToken() != XML.GT) {
-              throw x.syntaxError("Misshaped close tag");
-            }
-            return token;
-          } else if (token == XML.BANG) {
-
-            // <!
-
-            c = x.next();
-            if (c == '-') {
-              if (x.next() == '-') {
-                x.skipPast("-->");
-              } else {
-                x.back();
-              }
-            } else if (c == '[') {
-              token = x.nextToken();
-              if (token.equals("CDATA") && x.next() == '[') {
-                if (ja != null) {
-                  ja.put(x.nextCDATA());
-                }
-              } else {
-                throw x.syntaxError("Expected 'CDATA['");
-              }
-            } else {
-              i = 1;
-              do {
-                token = x.nextMeta();
-                if (token == null) {
-                  throw x.syntaxError("Missing '>' after '<!'.");
-                } else if (token == XML.LT) {
-                  i += 1;
-                } else if (token == XML.GT) {
-                  i -= 1;
-                }
-              } while (i > 0);
-            }
-          } else if (token == XML.QUEST) {
-
-            // <?
-
-            x.skipPast("?>");
-          } else {
-            throw x.syntaxError("Misshaped tag");
-          }
-
-          // Open tag <
-
-        } else {
-          if (!(token instanceof String)) {
-            throw x.syntaxError("Bad tagName '" + token + "'.");
-          }
-          tagName = (String) token;
-          newja = new JSONArray();
-          newjo = new JSONObject();
-          if (arrayForm) {
-            newja.put(tagName);
-            if (ja != null) {
-              ja.put(newja);
-            }
-          } else {
-            newjo.put("tagName", tagName);
-            if (ja != null) {
-              ja.put(newjo);
-            }
-          }
-          token = null;
-          for (;;) {
-            if (token == null) {
-              token = x.nextToken();
-            }
-            if (token == null) {
-              throw x.syntaxError("Misshaped tag");
-            }
-            if (!(token instanceof String)) {
-              break;
-            }
-
-            // attribute = value
-
-            attribute = (String) token;
-            if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
-              throw x.syntaxError("Reserved attribute.");
-            }
-            token = x.nextToken();
-            if (token == XML.EQ) {
-              token = x.nextToken();
-              if (!(token instanceof String)) {
-                throw x.syntaxError("Missing value");
-              }
-              newjo.accumulate(attribute, XML.stringToValue((String) token));
-              token = null;
-            } else {
-              newjo.accumulate(attribute, "");
-            }
-          }
-          if (arrayForm && newjo.length() > 0) {
-            newja.put(newjo);
-          }
-
-          // Empty tag <.../>
-
-          if (token == XML.SLASH) {
-            if (x.nextToken() != XML.GT) {
-              throw x.syntaxError("Misshaped tag");
-            }
-            if (ja == null) {
-              if (arrayForm) {
-                return newja;
-              } else {
-                return newjo;
-              }
-            }
-
-            // Content, between <...> and </...>
-
-          } else {
-            if (token != XML.GT) {
-              throw x.syntaxError("Misshaped tag");
-            }
-            closeTag = (String) parse(x, arrayForm, newja);
-            if (closeTag != null) {
-              if (!closeTag.equals(tagName)) {
-                throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
-              }
-              tagName = null;
-              if (!arrayForm && newja.length() > 0) {
-                newjo.put("childNodes", newja);
-              }
-              if (ja == null) {
-                if (arrayForm) {
-                  return newja;
-                } else {
-                  return newjo;
-                }
-              }
-            }
-          }
-        }
-      } else {
-        if (ja != null) {
-          ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML
-   * transform. Each XML tag is represented as a JSONArray in which the first element is the tag
-   * name. If the tag has attributes, then the second element will be JSONObject containing the
-   * name/value pairs. If the tag contains children, then strings and JSONArrays will represent the
-   * child tags. Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
-   * 
-   * @param string The source string.
-   * @return A JSONArray containing the structured data from the XML string.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(String string) throws JSONException {
-    return toJSONArray(new XMLTokener(string));
-  }
-
-
-  /**
-   * Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML
-   * transform. Each XML tag is represented as a JSONArray in which the first element is the tag
-   * name. If the tag has attributes, then the second element will be JSONObject containing the
-   * name/value pairs. If the tag contains children, then strings and JSONArrays will represent the
-   * child content and tags. Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
-   * 
-   * @param x An XMLTokener.
-   * @return A JSONArray containing the structured data from the XML string.
-   * @throws JSONException
-   */
-  public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
-    return (JSONArray) parse(x, true, null);
-  }
-
-
-  /**
-   * Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML
-   * transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag
-   * has attributes, then the attributes will be in the JSONObject as properties. If the tag
-   * contains children, the object will have a "childNodes" property which will be an array of
-   * strings and JsonML JSONObjects.
-   * 
-   * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
-   * 
-   * @param x An XMLTokener of the XML source text.
-   * @return A JSONObject containing the structured data from the XML string.
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
-    return (JSONObject) parse(x, false, null);
-  }
-
-
-  /**
-   * Convert a well-formed (but not necessarily valid) XML string into a JSONObject using the JsonML
-   * transform. Each XML tag is represented as a JSONObject with a "tagName" property. If the tag
-   * has attributes, then the attributes will be in the JSONObject as properties. If the tag
-   * contains children, the object will have a "childNodes" property which will be an array of
-   * strings and JsonML JSONObjects.
-   * 
-   * Comments, prologs, DTDs, and <code>&lt;[ [ ]]></code> are ignored.
-   * 
-   * @param string The XML source text.
-   * @return A JSONObject containing the structured data from the XML string.
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(String string) throws JSONException {
-    return toJSONObject(new XMLTokener(string));
-  }
-
-
-  /**
-   * Reverse the JSONML transformation, making an XML text from a JSONArray.
-   * 
-   * @param ja A JSONArray.
-   * @return An XML string.
-   * @throws JSONException
-   */
-  public static String toString(JSONArray ja) throws JSONException {
-    int i;
-    JSONObject jo;
-    String key;
-    Iterator keys;
-    int length;
-    Object object;
-    StringBuffer sb = new StringBuffer();
-    String tagName;
-    String value;
-
-    // Emit <tagName
-
-    tagName = ja.getString(0);
-    XML.noSpace(tagName);
-    tagName = XML.escape(tagName);
-    sb.append('<');
-    sb.append(tagName);
-
-    object = ja.opt(1);
-    if (object instanceof JSONObject) {
-      i = 2;
-      jo = (JSONObject) object;
-
-      // Emit the attributes
-
-      keys = jo.keys();
-      while (keys.hasNext()) {
-        key = keys.next().toString();
-        XML.noSpace(key);
-        value = jo.optString(key);
-        if (value != null) {
-          sb.append(' ');
-          sb.append(XML.escape(key));
-          sb.append('=');
-          sb.append('"');
-          sb.append(XML.escape(value));
-          sb.append('"');
-        }
-      }
-    } else {
-      i = 1;
-    }
-
-    // Emit content in body
-
-    length = ja.length();
-    if (i >= length) {
-      sb.append('/');
-      sb.append('>');
-    } else {
-      sb.append('>');
-      do {
-        object = ja.get(i);
-        i += 1;
-        if (object != null) {
-          if (object instanceof String) {
-            sb.append(XML.escape(object.toString()));
-          } else if (object instanceof JSONObject) {
-            sb.append(toString((JSONObject) object));
-          } else if (object instanceof JSONArray) {
-            sb.append(toString((JSONArray) object));
-          }
-        }
-      } while (i < length);
-      sb.append('<');
-      sb.append('/');
-      sb.append(tagName);
-      sb.append('>');
-    }
-    return sb.toString();
-  }
-
-  /**
-   * Reverse the JSONML transformation, making an XML text from a JSONObject. The JSONObject must
-   * contain a "tagName" property. If it has children, then it must have a "childNodes" property
-   * containing an array of objects. The other properties are attributes with string values.
-   * 
-   * @param jo A JSONObject.
-   * @return An XML string.
-   * @throws JSONException
-   */
-  public static String toString(JSONObject jo) throws JSONException {
-    StringBuffer sb = new StringBuffer();
-    int i;
-    JSONArray ja;
-    String key;
-    Iterator keys;
-    int length;
-    Object object;
-    String tagName;
-    String value;
-
-    // Emit <tagName
-
-    tagName = jo.optString("tagName");
-    if (tagName == null) {
-      return XML.escape(jo.toString());
-    }
-    XML.noSpace(tagName);
-    tagName = XML.escape(tagName);
-    sb.append('<');
-    sb.append(tagName);
-
-    // Emit the attributes
-
-    keys = jo.keys();
-    while (keys.hasNext()) {
-      key = keys.next().toString();
-      if (!"tagName".equals(key) && !"childNodes".equals(key)) {
-        XML.noSpace(key);
-        value = jo.optString(key);
-        if (value != null) {
-          sb.append(' ');
-          sb.append(XML.escape(key));
-          sb.append('=');
-          sb.append('"');
-          sb.append(XML.escape(value));
-          sb.append('"');
-        }
-      }
-    }
-
-    // Emit content in body
-
-    ja = jo.optJSONArray("childNodes");
-    if (ja == null) {
-      sb.append('/');
-      sb.append('>');
-    } else {
-      sb.append('>');
-      length = ja.length();
-      for (i = 0; i < length; i += 1) {
-        object = ja.get(i);
-        if (object != null) {
-          if (object instanceof String) {
-            sb.append(XML.escape(object.toString()));
-          } else if (object instanceof JSONObject) {
-            sb.append(toString((JSONObject) object));
-          } else if (object instanceof JSONArray) {
-            sb.append(toString((JSONArray) object));
-          } else {
-            sb.append(object.toString());
-          }
-        }
-      }
-      sb.append('<');
-      sb.append('/');
-      sb.append(tagName);
-      sb.append('>');
-    }
-    return sb.toString();
-  }
-}


[07/34] geode git commit: GEODE-2142: Amending JSONObject.java with cyclicalDependency management Refactoring some code in GfJsonObject.java

Posted by kl...@apache.org.
GEODE-2142: Amending JSONObject.java with cyclicalDependency management
Refactoring some code in GfJsonObject.java


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/fdde6181
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/fdde6181
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/fdde6181

Branch: refs/heads/GEODE-4160-mockito
Commit: fdde6181feaae6674173a9c5827849672e291f3b
Parents: b34e47f
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 15:11:49 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 .../internal/cli/json/GfJsonObject.java         |   36 -
 .../src/main/java/org/json/JSONObject.java      | 1765 +++++++++---------
 2 files changed, 872 insertions(+), 929 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/fdde6181/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/GfJsonObject.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/GfJsonObject.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/GfJsonObject.java
index 69666ff..66e9f79 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/GfJsonObject.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/json/GfJsonObject.java
@@ -49,22 +49,6 @@ public class GfJsonObject {
       this.jsonObject = (JSONObject) bean;
     } else {
       this.jsonObject = new JSONObject(bean);
-      // If we want to print out the values of the primitive arrays and report back
-      // Class klass = bean.getClass();
-      // if(klass.isArray() && klass.getComponentType().isPrimitive()){
-      // String str = "";
-      // int length = Array.getLength(bean);
-      // for (int i = 0; i < length; i++) {
-      // if(i==0)
-      // str += (Array.get(bean, i));
-      // else
-      // str +=(","+Array.get(bean, i));
-      // }
-      // try {
-      // this.jsonObject.put("Value", str);
-      // } catch (JSONException ignore) {
-      // }
-      // }
     }
     if (checkCyclicDep) {
       JSONObject.cyclicDepChkEnabled.set(false);
@@ -88,10 +72,6 @@ public class GfJsonObject {
     }
   }
 
-  public GfJsonObject(Object bean, String[] paramNames) {
-    this.jsonObject = new JSONObject(bean, paramNames);
-  }
-
   /**
    * 
    * @param source A string beginning with { (left brace) and ending with } (right brace).
@@ -258,22 +238,6 @@ public class GfJsonObject {
    * @param key
    * @param value
    * @return this GfJsonObject
-   * @throws GfJsonException if the key is a duplicate
-   */
-  public GfJsonObject putOnce(String key, Object value) throws GfJsonException {
-    try {
-      jsonObject.putOnce(key, value);
-    } catch (JSONException e) {
-      throw new GfJsonException(e.getMessage());
-    }
-    return this;
-  }
-
-  /**
-   * 
-   * @param key
-   * @param value
-   * @return this GfJsonObject
    * @throws GfJsonException If the value is a non-finite number.
    */
   public GfJsonObject putOpt(String key, Object value) throws GfJsonException {

http://git-wip-us.apache.org/repos/asf/geode/blob/fdde6181/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 d2bc126..ce15d1b 100755
--- a/geode-json/src/main/java/org/json/JSONObject.java
+++ b/geode-json/src/main/java/org/json/JSONObject.java
@@ -16,10 +16,8 @@
 
 package org.json;
 
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -84,910 +82,891 @@ import java.util.TreeMap;
  */
 public class JSONObject {
 
-    private static final Double NEGATIVE_ZERO = -0d;
-
-    /**
-     * 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
-     * <li>return {@code true} for {@link #has(String)}
-     * <li>do not throw on {@link #get(String)}
-     * <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".
-     */
-    public static final Object NULL = new Object() {
-        @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
-        @Override
-        public boolean equals(Object o) {
-            return o == this || o == null; // API specifies this broken equals implementation
-        }
-
-        // at least make the broken equals(null) consistent with Objects.hashCode(null).
-        @Override
-        public int hashCode() {
-            return 0;
-        }
-
-        @Override
-        public String toString() {
-            return "null";
-        }
-    };
-
-    private final LinkedHashMap<String, Object> nameValuePairs;
+  private static final Double NEGATIVE_ZERO = -0d;
+
+  public static ThreadLocal<Set> cyclicDependencySet = new ThreadLocal();
+  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:
+   * <ul>
+   * <li>show up in the {@link #names} array
+   * <li>show up in the {@link #keys} iterator
+   * <li>return {@code true} for {@link #has(String)}
+   * <li>do not throw on {@link #get(String)}
+   * <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".
+   */
+  public static final Object NULL = new Object() {
+    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+    @Override
+    public boolean equals(Object o) {
+      return o == this || o == null; // API specifies this broken equals implementation
+    }
 
-    /**
-     * Creates a {@code JSONObject} with no name/value mappings.
-     */
-    public JSONObject() {
-        nameValuePairs = new LinkedHashMap<String, Object>();
+    // at least make the broken equals(null) consistent with Objects.hashCode(null).
+    @Override
+    public int hashCode() {
+      return 0;
     }
 
-    /**
-     * 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.
-     * @throws NullPointerException if any of the map's keys are null.
-     */
+    @Override
+    public String toString() {
+      return "null";
+    }
+  };
+
+  private final LinkedHashMap<String, Object> nameValuePairs;
+
+  /**
+   * Creates a {@code JSONObject} with no name/value mappings.
+   */
+  public JSONObject() {
+    nameValuePairs = new LinkedHashMap<String, Object>();
+  }
+
+  /**
+   * 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.
+   * @throws NullPointerException if any of the map's keys are null.
+   */
     /* (accept a raw type for API compatibility) */
-    public JSONObject(Map copyFrom) {
-        this();
-        Map<?, ?> contentsTyped = (Map<?, ?>) copyFrom;
-        for (Map.Entry<?, ?> entry : contentsTyped.entrySet()) {
+  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).
              */
-            String key = (String) entry.getKey();
-            if (key == null) {
-                throw new NullPointerException("key == null");
-            }
-            nameValuePairs.put(key, wrap(entry.getValue()));
-        }
-    }
-
-    /**
-     * 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 {
+      String key = (String) entry.getKey();
+      if (key == null) {
+        throw new NullPointerException("key == null");
+      }
+      nameValuePairs.put(key, wrap(entry.getValue()));
+    }
+  }
+
+  /**
+   * 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.
          */
-        Object object = readFrom.nextValue();
-        if (object instanceof JSONObject) {
-            this.nameValuePairs = ((JSONObject) object).nameValuePairs;
-        } else {
-            throw JSON.typeMismatch(object, "JSONObject");
-        }
-    }
-
-    /**
-     * 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}.
-     */
-    public JSONObject(String json) throws JSONException {
-        this(new JSONTokener(json));
-    }
-
-    /**
-     * 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.
-     */
-    public JSONObject(JSONObject copyFrom, String[] names) throws JSONException {
-        this();
-        for (String name : names) {
-            Object value = copyFrom.opt(name);
-            if (value != null) {
-                nameValuePairs.put(name, value);
-            }
-        }
-    }
-
-    /**
-     * 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
-     */
-    public JSONObject(Object bean) throws JSONException {
-        this(propertiesAsMap(bean));
-    }
-
-    private static Map<String, Object> propertiesAsMap(Object bean) throws JSONException {
-        Map<String, Object> props = new TreeMap<String, Object>();
-        try {
-            PropertyDescriptor[] properties = Introspector.getBeanInfo(bean.getClass(), Object.class)
-                    .getPropertyDescriptors();
-            for (PropertyDescriptor prop : properties) {
-                Object v = prop.getReadMethod().invoke(bean);
-                props.put(prop.getDisplayName(), wrap(v));
-            }
-        } catch (IllegalAccessException e) {
-            throw new JSONException(e);
-        } catch (IntrospectionException e) {
-            throw new JSONException(e);
-        } catch (InvocationTargetException e) {
-            throw new JSONException(e);
-        }
-        return props;
-    }
-
-    public static String[] getNames(JSONObject x) {
-        Set<String> names = x.keySet();
-        String[] r = new String[names.size()];
-        int i = 0;
-        for (String name : names) {
-            r[i++] = name;
-        }
-        return r;
-    }
-
-    /**
-     * Returns the number of name/value mappings in this object.
-     *
-     * @return the length of this.
-     */
-    public int length() {
-        return nameValuePairs.size();
-    }
-
-    /**
-     * 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.
-     * @throws JSONException Should not be possible.
-     */
-    public JSONObject put(String name, boolean value) throws JSONException {
-        nameValuePairs.put(checkName(name), value);
-        return this;
-    }
-
-    /**
-     * 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}.
-     * @return this object.
-     * @throws JSONException if value is NaN or infinite.
-     */
-    public JSONObject put(String name, double value) throws JSONException {
-        nameValuePairs.put(checkName(name), JSON.checkDouble(value));
-        return this;
-    }
-
-    /**
-     * 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.
-     * @throws JSONException Should not be possible.
-     */
-    public JSONObject put(String name, int value) throws JSONException {
-        nameValuePairs.put(checkName(name), value);
-        return this;
-    }
-
-    /**
-     * 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.
-     * @throws JSONException Should not be possible.
-     */
-    public JSONObject put(String name, long value) throws JSONException {
-        nameValuePairs.put(checkName(name), value);
-        return this;
-    }
-
-    /**
-     * 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}.
-     * @return this object.
-     * @throws JSONException if the value is an invalid double (infinite or NaN).
-     */
-    public JSONObject put(String name, Object value) throws JSONException {
-        if (value == null) {
-            nameValuePairs.remove(name);
-            return this;
-        }
-        if (value instanceof Number) {
-            // deviate from the original by checking all Numbers, not just floats & doubles
-            JSON.checkDouble(((Number) value).doubleValue());
-        }
-        nameValuePairs.put(checkName(name), value);
-        return this;
-    }
-
-    /**
-     * 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.
-     * @throws JSONException if the value is an invalid double (infinite or NaN).
-     */
-    public JSONObject putOpt(String name, Object value) throws JSONException {
-        if (name == null || value == null) {
-            return this;
-        }
-        return put(name, value);
-    }
-
-    /**
-     * 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}
-     * 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}.
-     * @return this object after mutation.
-     * @throws JSONException If the object being added is an invalid number.
-     */
-    // TODO: Change {@code append) to {@link #append} when append is
-    // unhidden.
-    public JSONObject accumulate(String name, Object value) throws JSONException {
-        Object current = nameValuePairs.get(checkName(name));
-        if (current == null) {
-            return put(name, value);
-        }
-
-        if (current instanceof JSONArray) {
-            JSONArray array = (JSONArray) current;
-            array.checkedPut(value);
-        } else {
-            JSONArray array = new JSONArray();
-            array.checkedPut(current);
-            array.checkedPut(value);
-            nameValuePairs.put(name, array);
-        }
-        return this;
-    }
-
-    /**
-     * 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}.
-     */
-    public JSONObject append(String name, Object value) throws JSONException {
-        Object current = nameValuePairs.get(checkName(name));
-
-        final JSONArray array;
-        if (current instanceof JSONArray) {
-            array = (JSONArray) current;
-        } else if (current == null) {
-            JSONArray newArray = new JSONArray();
-            nameValuePairs.put(name, newArray);
-            array = newArray;
-        } else {
-            throw new JSONException("Key " + name + " is not a JSONArray");
-        }
-
-        array.checkedPut(value);
-
-        return this;
-    }
-
-    String checkName(String name) throws JSONException {
-        if (name == null) {
-            throw new JSONException("Names must be non-null");
-        }
-        return name;
-    }
-
-    /**
-     * 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.
-     */
-    public Object remove(String name) {
-        return nameValuePairs.remove(name);
-    }
-
-    /**
-     * 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.
-     */
-    public boolean isNull(String name) {
-        Object value = nameValuePairs.get(name);
-        return value == null || value == 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}
-     */
-    public boolean has(String name) {
-        return nameValuePairs.containsKey(name);
-    }
-
-    /**
-     * 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.
-     */
-    public Object get(String name) throws JSONException {
-        Object result = nameValuePairs.get(name);
-        if (result == null) {
-            throw new JSONException("No value for " + name);
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public Object opt(String name) {
-        return nameValuePairs.get(name);
-    }
-
-    /**
-     * 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.
-     */
-    public boolean getBoolean(String name) throws JSONException {
-        Object object = get(name);
-        Boolean result = JSON.toBoolean(object);
-        if (result == null) {
-            throw JSON.typeMismatch(name, object, "boolean");
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public boolean optBoolean(String name) {
-        return optBoolean(name, false);
-    }
-
-    /**
-     * 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.
-     */
-    public boolean optBoolean(String name, boolean fallback) {
-        Object object = opt(name);
-        Boolean result = JSON.toBoolean(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * 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.
-     */
-    public double getDouble(String name) throws JSONException {
-        Object object = get(name);
-        Double result = JSON.toDouble(object);
-        if (result == null) {
-            throw JSON.typeMismatch(name, object, "double");
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public double optDouble(String name) {
-        return optDouble(name, Double.NaN);
-    }
-
-    /**
-     * 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.
-     */
-    public double optDouble(String name, double fallback) {
-        Object object = opt(name);
-        Double result = JSON.toDouble(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * 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.
-     */
-    public int getInt(String name) throws JSONException {
-        Object object = get(name);
-        Integer result = JSON.toInteger(object);
-        if (result == null) {
-            throw JSON.typeMismatch(name, object, "int");
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public int optInt(String name) {
-        return optInt(name, 0);
-    }
-
-    /**
-     * 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.
-     */
-    public int optInt(String name, int fallback) {
-        Object object = opt(name);
-        Integer result = JSON.toInteger(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * 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.
-     *
-     * @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.
-     */
-    public long getLong(String name) throws JSONException {
-        Object object = get(name);
-        Long result = JSON.toLong(object);
-        if (result == null) {
-            throw JSON.typeMismatch(name, object, "long");
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public long optLong(String name) {
-        return optLong(name, 0L);
-    }
-
-    /**
-     * 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.
-     */
-    public long optLong(String name, long fallback) {
-        Object object = opt(name);
-        Long result = JSON.toLong(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * 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.
-     */
-    public String getString(String name) throws JSONException {
-        Object object = get(name);
-        String result = JSON.toString(object);
-        if (result == null) {
-            throw JSON.typeMismatch(name, object, "String");
-        }
-        return result;
-    }
-
-    /**
-     * 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.
-     */
-    public String optString(String name) {
-        return optString(name, "");
-    }
-
-    /**
-     * 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.
-     */
-    public String optString(String name, String fallback) {
-        Object object = opt(name);
-        String result = JSON.toString(object);
-        return result != null ? result : fallback;
-    }
-
-    /**
-     * 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}.
-     */
-    public JSONArray getJSONArray(String name) throws JSONException {
-        Object object = get(name);
-        if (object instanceof JSONArray) {
-            return (JSONArray) object;
-        } else {
-            throw JSON.typeMismatch(name, object, "JSONArray");
-        }
-    }
-
-    /**
-     * 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
-     */
-    public JSONArray optJSONArray(String name) {
-        Object object = opt(name);
-        return object instanceof JSONArray ? (JSONArray) object : null;
-    }
-
-    /**
-     * 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}.
-     */
-    public JSONObject getJSONObject(String name) throws JSONException {
-        Object object = get(name);
-        if (object instanceof JSONObject) {
-            return (JSONObject) object;
-        } else {
-            throw JSON.typeMismatch(name, object, "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.
-     */
-    public JSONObject optJSONObject(String name) {
-        Object object = opt(name);
-        return object instanceof JSONObject ? (JSONObject) object : null;
-    }
-
-    /**
-     * 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.
-     */
-    public JSONArray toJSONArray(JSONArray names) throws JSONException {
-        JSONArray result = new JSONArray();
-        if (names == null) {
-            return null;
-        }
-        int length = names.length();
-        if (length == 0) {
-            return null;
-        }
-        for (int i = 0; i < length; i++) {
-            String name = JSON.toString(names.opt(i));
-            result.put(opt(name));
-        }
-        return result;
-    }
-
-    /**
-     * 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() {
-        return nameValuePairs.keySet().iterator();
-    }
-
-    /**
-     * 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() {
-        return nameValuePairs.keySet();
-    }
-
-    /**
-     * 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
-                : new JSONArray(new ArrayList<String>(nameValuePairs.keySet()));
-    }
-
-    /**
-     * Encodes this object as a compact JSON string, such as:
-     * <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
-     */
-    @Override
-    public String toString() {
-        try {
-            JSONStringer stringer = new JSONStringer();
-            writeTo(stringer);
-            return stringer.toString();
-        } catch (JSONException e) {
-            return null;
-        }
-    }
-
-    /**
-     * Encodes this object as a human readable JSON string for debugging, such
-     * as:
-     * <pre>
-     * {
-     *     "query": "Pizza",
-     *     "locations": [
-     *         94043,
-     *         90210
-     *     ]
-     * }</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.
-     */
-    public String toString(int indentSpaces) throws JSONException {
-        JSONStringer stringer = new JSONStringer(indentSpaces);
-        writeTo(stringer);
-        return stringer.toString();
-    }
-
-    void writeTo(JSONStringer stringer) throws JSONException {
-        stringer.object();
-        for (Map.Entry<String, Object> entry : nameValuePairs.entrySet()) {
-            stringer.key(entry.getKey()).value(entry.getValue());
-        }
-        stringer.endObject();
-    }
-
-    /**
-     * Encodes the number as a JSON string.
-     *
-     * @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.
-     */
-    public static String numberToString(Number number) throws JSONException {
-        if (number == null) {
-            throw new JSONException("Number must be non-null");
-        }
-
-        double doubleValue = number.doubleValue();
-        JSON.checkDouble(doubleValue);
-
-        // the original returns "-0" instead of "-0.0" for negative zero
-        if (number.equals(NEGATIVE_ZERO)) {
-            return "-0";
-        }
-
-        long longValue = number.longValue();
-        if (doubleValue == (double) longValue) {
-            return Long.toString(longValue);
-        }
-
-        return number.toString();
-    }
-
-    /**
-     * 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.
-     */
-    public static String quote(String data) {
-        if (data == null) {
-            return "\"\"";
-        }
-        try {
-            JSONStringer stringer = new JSONStringer();
-            stringer.open(JSONStringer.Scope.NULL, "");
-            stringer.value(data);
-            stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
-            return stringer.toString();
-        } catch (JSONException e) {
-            throw new AssertionError();
-        }
-    }
-
-    /**
-     * Wraps the given object if necessary.
-     *
-     * <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 object is a primitive wrapper type or {@code String}, returns the object.
-     * If the object is from 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}
-     */
-    public static Object wrap(Object o) {
-        if (o == null) {
-            return NULL;
-        }
-        if (o instanceof JSONArray || o instanceof JSONObject) {
-            return o;
-        }
-        if (o.equals(NULL)) {
-            return o;
-        }
-        try {
-            if (o instanceof Collection) {
-                return new JSONArray((Collection) o);
-            } else if (o.getClass().isArray()) {
-                return new JSONArray(o);
+    Object object = readFrom.nextValue();
+    if (object instanceof JSONObject) {
+      this.nameValuePairs = ((JSONObject) object).nameValuePairs;
+    } else {
+      throw JSON.typeMismatch(object, "JSONObject");
+    }
+  }
+
+  /**
+   * 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}.
+   */
+  public JSONObject(String json) throws JSONException {
+    this(new JSONTokener(json));
+  }
+
+  /**
+   * 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.
+   */
+  public JSONObject(JSONObject copyFrom, String[] names) throws JSONException {
+    this();
+    for (String name : names) {
+      Object value = copyFrom.opt(name);
+      if (value != null) {
+        nameValuePairs.put(name, value);
+      }
+    }
+  }
+
+  /**
+   * 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
+   */
+  public JSONObject(Object bean) throws JSONException {
+    this(propertiesAsMap(bean));
+  }
+
+  // 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();
+
+    // If klass is a System class then set includeSuperClass to false.
+
+    boolean includeSuperClass = klass.getClassLoader() != null;
+
+    Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
+    for (int i = 0; i < methods.length; i += 1) {
+      try {
+        Method method = methods[i];
+        if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
+          String name = method.getName();
+          String key = "";
+          if (name.startsWith("get")) {
+            if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
+              key = "";
+            } else {
+              key = name.substring(3);
             }
-            if (o instanceof Map) {
-                return new JSONObject((Map) o);
+          } else if (name.startsWith("is")) {
+            key = name.substring(2);
+          }
+          if (key.length() > 0 && Character.isUpperCase(key.charAt(0))
+              && method.getParameterTypes().length == 0) {
+            if (key.length() == 1) {
+              key = key.toLowerCase();
+            } else if (!Character.isUpperCase(key.charAt(1))) {
+              key = key.substring(0, 1).toLowerCase() + key.substring(1);
             }
-            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;
+            Object result = method.invoke(bean, (Object[]) null);
+            if (result != null) {
+              props.put(key, wrap(result));
+            } else if (!method.getReturnType().isArray()) {
+              props.put(key, JSONObject.NULL);
             }
-            if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?>) {
-                return o.toString();
-            } else {
-                return new JSONObject(o);
-            }
-        } catch (Exception ignored) {
+          }
+        }
+      } catch (Exception ignore) {
+      }
+    }
+    props.put("type-class", klass.getCanonicalName());
+    return props;
+  }
+
+  public static String[] getNames(JSONObject x) {
+    Set<String> names = x.keySet();
+    String[] r = new String[names.size()];
+    int i = 0;
+    for (String name : names) {
+      r[i++] = name;
+    }
+    return r;
+  }
+
+  /**
+   * Returns the number of name/value mappings in this object.
+   * @return the length of this.
+   */
+  public int length() {
+    return nameValuePairs.size();
+  }
+
+  /**
+   * 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.
+   * @throws JSONException Should not be possible.
+   */
+  public JSONObject put(String name, boolean value) throws JSONException {
+    nameValuePairs.put(checkName(name), value);
+    return this;
+  }
+
+  /**
+   * 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}.
+   * @return this object.
+   * @throws JSONException if value is NaN or infinite.
+   */
+  public JSONObject put(String name, double value) throws JSONException {
+    nameValuePairs.put(checkName(name), JSON.checkDouble(value));
+    return this;
+  }
+
+  /**
+   * 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.
+   * @throws JSONException Should not be possible.
+   */
+  public JSONObject put(String name, int value) throws JSONException {
+    nameValuePairs.put(checkName(name), value);
+    return this;
+  }
+
+  /**
+   * 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.
+   * @throws JSONException Should not be possible.
+   */
+  public JSONObject put(String name, long value) throws JSONException {
+    nameValuePairs.put(checkName(name), value);
+    return this;
+  }
+
+  /**
+   * 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}.
+   * @return this object.
+   * @throws JSONException if the value is an invalid double (infinite or NaN).
+   */
+  public JSONObject put(String name, Object value) throws JSONException {
+    if (value == null) {
+      nameValuePairs.remove(name);
+      return this;
+    }
+    if (value instanceof Number) {
+      // deviate from the original by checking all Numbers, not just floats & doubles
+      JSON.checkDouble(((Number) value).doubleValue());
+    }
+    nameValuePairs.put(checkName(name), value);
+    return this;
+  }
+
+  /**
+   * 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.
+   * @throws JSONException if the value is an invalid double (infinite or NaN).
+   */
+  public JSONObject putOpt(String name, Object value) throws JSONException {
+    if (name == null || value == null) {
+      return this;
+    }
+    return put(name, value);
+  }
+
+  /**
+   * 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}
+   * 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}.
+   * @return this object after mutation.
+   * @throws JSONException If the object being added is an invalid number.
+   */
+  // TODO: Change {@code append) to {@link #append} when append is
+  // unhidden.
+  public JSONObject accumulate(String name, Object value) throws JSONException {
+    Object current = nameValuePairs.get(checkName(name));
+    if (current == null) {
+      return put(name, value);
+    }
+
+    if (current instanceof JSONArray) {
+      JSONArray array = (JSONArray) current;
+      array.checkedPut(value);
+    } else {
+      JSONArray array = new JSONArray();
+      array.checkedPut(current);
+      array.checkedPut(value);
+      nameValuePairs.put(name, array);
+    }
+    return this;
+  }
+
+  /**
+   * 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}.
+   */
+  public JSONObject append(String name, Object value) throws JSONException {
+    Object current = nameValuePairs.get(checkName(name));
+
+    final JSONArray array;
+    if (current instanceof JSONArray) {
+      array = (JSONArray) current;
+    } else if (current == null) {
+      JSONArray newArray = new JSONArray();
+      nameValuePairs.put(name, newArray);
+      array = newArray;
+    } else {
+      throw new JSONException("Key " + name + " is not a JSONArray");
+    }
+
+    array.checkedPut(value);
+
+    return this;
+  }
+
+  String checkName(String name) throws JSONException {
+    if (name == null) {
+      throw new JSONException("Names must be non-null");
+    }
+    return name;
+  }
+
+  /**
+   * 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.
+   */
+  public Object remove(String name) {
+    return nameValuePairs.remove(name);
+  }
+
+  /**
+   * 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.
+   */
+  public boolean isNull(String name) {
+    Object value = nameValuePairs.get(name);
+    return value == null || value == 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}
+   */
+  public boolean has(String name) {
+    return nameValuePairs.containsKey(name);
+  }
+
+  /**
+   * 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.
+   */
+  public Object get(String name) throws JSONException {
+    Object result = nameValuePairs.get(name);
+    if (result == null) {
+      throw new JSONException("No value for " + name);
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public Object opt(String name) {
+    return nameValuePairs.get(name);
+  }
+
+  /**
+   * 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.
+   */
+  public boolean getBoolean(String name) throws JSONException {
+    Object object = get(name);
+    Boolean result = JSON.toBoolean(object);
+    if (result == null) {
+      throw JSON.typeMismatch(name, object, "boolean");
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public boolean optBoolean(String name) {
+    return optBoolean(name, false);
+  }
+
+  /**
+   * 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.
+   */
+  public boolean optBoolean(String name, boolean fallback) {
+    Object object = opt(name);
+    Boolean result = JSON.toBoolean(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * 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.
+   */
+  public double getDouble(String name) throws JSONException {
+    Object object = get(name);
+    Double result = JSON.toDouble(object);
+    if (result == null) {
+      throw JSON.typeMismatch(name, object, "double");
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public double optDouble(String name) {
+    return optDouble(name, Double.NaN);
+  }
+
+  /**
+   * 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.
+   */
+  public double optDouble(String name, double fallback) {
+    Object object = opt(name);
+    Double result = JSON.toDouble(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * 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.
+   */
+  public int getInt(String name) throws JSONException {
+    Object object = get(name);
+    Integer result = JSON.toInteger(object);
+    if (result == null) {
+      throw JSON.typeMismatch(name, object, "int");
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public int optInt(String name) {
+    return optInt(name, 0);
+  }
+
+  /**
+   * 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.
+   */
+  public int optInt(String name, int fallback) {
+    Object object = opt(name);
+    Integer result = JSON.toInteger(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * 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.
+   * @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.
+   */
+  public long getLong(String name) throws JSONException {
+    Object object = get(name);
+    Long result = JSON.toLong(object);
+    if (result == null) {
+      throw JSON.typeMismatch(name, object, "long");
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public long optLong(String name) {
+    return optLong(name, 0L);
+  }
+
+  /**
+   * 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.
+   */
+  public long optLong(String name, long fallback) {
+    Object object = opt(name);
+    Long result = JSON.toLong(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * 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.
+   */
+  public String getString(String name) throws JSONException {
+    Object object = get(name);
+    String result = JSON.toString(object);
+    if (result == null) {
+      throw JSON.typeMismatch(name, object, "String");
+    }
+    return result;
+  }
+
+  /**
+   * 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.
+   */
+  public String optString(String name) {
+    return optString(name, "");
+  }
+
+  /**
+   * 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.
+   */
+  public String optString(String name, String fallback) {
+    Object object = opt(name);
+    String result = JSON.toString(object);
+    return result != null ? result : fallback;
+  }
+
+  /**
+   * 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}.
+   */
+  public JSONArray getJSONArray(String name) throws JSONException {
+    Object object = get(name);
+    if (object instanceof JSONArray) {
+      return (JSONArray) object;
+    } else {
+      throw JSON.typeMismatch(name, object, "JSONArray");
+    }
+  }
+
+  /**
+   * 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
+   */
+  public JSONArray optJSONArray(String name) {
+    Object object = opt(name);
+    return object instanceof JSONArray ? (JSONArray) object : null;
+  }
+
+  /**
+   * 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}.
+   */
+  public JSONObject getJSONObject(String name) throws JSONException {
+    Object object = get(name);
+    if (object instanceof JSONObject) {
+      return (JSONObject) object;
+    } else {
+      throw JSON.typeMismatch(name, object, "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.
+   */
+  public JSONObject optJSONObject(String name) {
+    Object object = opt(name);
+    return object instanceof JSONObject ? (JSONObject) object : null;
+  }
+
+  /**
+   * 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.
+   */
+  public JSONArray toJSONArray(JSONArray names) throws JSONException {
+    JSONArray result = new JSONArray();
+    if (names == null) {
+      return null;
+    }
+    int length = names.length();
+    if (length == 0) {
+      return null;
+    }
+    for (int i = 0; i < length; i++) {
+      String name = JSON.toString(names.opt(i));
+      result.put(opt(name));
+    }
+    return result;
+  }
+
+  /**
+   * 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() {
+    return nameValuePairs.keySet().iterator();
+  }
+
+  /**
+   * 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() {
+    return nameValuePairs.keySet();
+  }
+
+  /**
+   * 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
+        : new JSONArray(new ArrayList<String>(nameValuePairs.keySet()));
+  }
+
+  /**
+   * Encodes this object as a compact JSON string, such as:
+   * <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
+   */
+  @Override
+  public String toString() {
+    try {
+      JSONStringer stringer = new JSONStringer();
+      writeTo(stringer);
+      return stringer.toString();
+    } catch (JSONException e) {
+      return null;
+    }
+  }
+
+  /**
+   * Encodes this object as a human readable JSON string for debugging, such
+   * as:
+   * <pre>
+   * {
+   *     "query": "Pizza",
+   *     "locations": [
+   *         94043,
+   *         90210
+   *     ]
+   * }</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.
+   */
+  public String toString(int indentSpaces) throws JSONException {
+    JSONStringer stringer = new JSONStringer(indentSpaces);
+    writeTo(stringer);
+    return stringer.toString();
+  }
+
+  void writeTo(JSONStringer stringer) throws JSONException {
+    stringer.object();
+    for (Map.Entry<String, Object> entry : nameValuePairs.entrySet()) {
+      stringer.key(entry.getKey()).value(entry.getValue());
+    }
+    stringer.endObject();
+  }
+
+  /**
+   * Encodes the number as a JSON string.
+   * @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.
+   */
+  public static String numberToString(Number number) throws JSONException {
+    if (number == null) {
+      throw new JSONException("Number must be non-null");
+    }
+
+    double doubleValue = number.doubleValue();
+    JSON.checkDouble(doubleValue);
+
+    // the original returns "-0" instead of "-0.0" for negative zero
+    if (number.equals(NEGATIVE_ZERO)) {
+      return "-0";
+    }
+
+    long longValue = number.longValue();
+    if (doubleValue == (double) longValue) {
+      return Long.toString(longValue);
+    }
+
+    return number.toString();
+  }
+
+  /**
+   * 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.
+   */
+  public static String quote(String data) {
+    if (data == null) {
+      return "\"\"";
+    }
+    try {
+      JSONStringer stringer = new JSONStringer();
+      stringer.open(JSONStringer.Scope.NULL, "");
+      stringer.value(data);
+      stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
+      return stringer.toString();
+    } catch (JSONException e) {
+      throw new AssertionError();
+    }
+  }
+
+  /**
+   * Wraps the given object if necessary.
+   *
+   * <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
+   * object is a primitive wrapper type or {@code String}, returns the object. If the object is from
+   * 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}
+   */
+  public static Object wrap(Object o) {
+    if (o == null) {
+      return NULL;
+    }
+    if (o instanceof JSONArray || o instanceof JSONObject) {
+      return o;
+    }
+    if (o.equals(NULL)) {
+      return o;
+    }
+    try {
+      if (o instanceof Collection) {
+        return new JSONArray((Collection) o);
+      } else if (o.getClass().isArray()) {
+        return new JSONArray(o);
+      }
+      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) {
+        return o;
+      }
+      // GEODE-2142: Added check to ignore GemFireCacheImpl
+      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
+          || 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)) {
+          // break cyclic reference
+          return o.getClass().getCanonicalName();
+        } else {
+          cyclicDependencySet.get().add(o);
+          return new JSONObject(o);
         }
-        return null;
+      } else {
+        return new JSONObject(o);
+      }
+    } catch (Exception ignored) {
     }
+    return null;
+  }
 }


[03/34] geode git commit: GEODE-2428: Adding support of Serialization/deserialization of LinkedHashMap in DataSerializer Also added a test for the same.

Posted by kl...@apache.org.
GEODE-2428: Adding support of Serialization/deserialization of LinkedHashMap in DataSerializer
Also added a test for the same.

GEODE-2428: Addressing review comment, Fixing the wild-card import
issue.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a8757f6a
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a8757f6a
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a8757f6a

Branch: refs/heads/GEODE-4160-mockito
Commit: a8757f6a16920488d15f78174f1638c87565eacf
Parents: 64cd6fc
Author: adongre <ad...@apache.org>
Authored: Sat Feb 4 19:47:51 2017 +0530
Committer: adongre <ad...@apache.org>
Committed: Mon Feb 27 17:20:33 2017 +0530

----------------------------------------------------------------------
 .../java/org/apache/geode/DataSerializer.java   | 69 ++++++++++++++++++++
 .../internal/DataSerializableJUnitTest.java     | 64 +++++++++++++-----
 2 files changed, 117 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/a8757f6a/geode-core/src/main/java/org/apache/geode/DataSerializer.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/DataSerializer.java b/geode-core/src/main/java/org/apache/geode/DataSerializer.java
index 375ff3b..627661a 100644
--- a/geode-core/src/main/java/org/apache/geode/DataSerializer.java
+++ b/geode-core/src/main/java/org/apache/geode/DataSerializer.java
@@ -33,6 +33,7 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.IdentityHashMap;
 import java.util.LinkedHashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
@@ -2667,6 +2668,74 @@ public abstract class DataSerializer {
     }
   }
 
+
+  /**
+   * Writes a <code>LinkedHashMap</code> to a <code>DataOutput</code>. Note that even though
+   * <code>map</code> may be an instance of a subclass of <code>LinkedHashMap</code>,
+   * <code>readLinkedHashMap</code> will always return an instance of <code>LinkedHashMap</code>,
+   * <B>not</B> an instance of the subclass. To preserve the class type of <code>map</code>,
+   * {@link #writeObject(Object, DataOutput)} should be used for data serialization. This method
+   * will serialize a <code>null</code> map and not throw a <code>NullPointerException</code>.
+   *
+   * @throws IOException A problem occurs while writing to <code>out</code>
+   * @see #readLinkedHashMap
+   */
+  public static void writeLinkedHashMap(Map<?, ?> map, DataOutput out) throws IOException {
+
+    InternalDataSerializer.checkOut(out);
+
+    int size;
+    if (map == null) {
+      size = -1;
+    } else {
+      size = map.size();
+    }
+    InternalDataSerializer.writeArrayLength(size, out);
+    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
+      logger.trace(LogMarker.SERIALIZER, "Writing LinkedHashMap with {} elements: {}", size, map);
+    }
+    if (size > 0) {
+      for (Map.Entry<?, ?> entry : map.entrySet()) {
+        writeObject(entry.getKey(), out);
+        writeObject(entry.getValue(), out);
+      }
+    }
+  }
+
+  /**
+   * Reads a <code>LinkedHashMap</code> from a <code>DataInput</code>.
+   *
+   * @throws IOException A problem occurs while reading from <code>in</code>
+   * @throws ClassNotFoundException The class of one of the <Code>HashMap</code>'s elements cannot
+   *         be found.
+   * @see #writeLinkedHashMap
+   */
+  public static <K, V> LinkedHashMap<K, V> readLinkedHashMap(DataInput in)
+      throws IOException, ClassNotFoundException {
+
+    InternalDataSerializer.checkIn(in);
+
+    int size = InternalDataSerializer.readArrayLength(in);
+    if (size == -1) {
+      return null;
+    } else {
+      LinkedHashMap<K, V> map = new LinkedHashMap<>(size);
+      for (int i = 0; i < size; i++) {
+        K key = DataSerializer.<K>readObject(in);
+        V value = DataSerializer.<V>readObject(in);
+        map.put(key, value);
+      }
+
+      if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
+        logger.trace(LogMarker.SERIALIZER, "Read LinkedHashMap with {} elements: {}", size, map);
+      }
+
+      return map;
+    }
+  }
+
+
+
   /**
    * Writes a <code>TreeSet</code> to a <code>DataOutput</code>. Note that even though
    * <code>set</code> may be an instance of a subclass of <code>TreeSet</code>,

http://git-wip-us.apache.org/repos/asf/geode/blob/a8757f6a/geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java
index eec5fc2..0c5d561 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java
@@ -32,22 +32,7 @@ import java.math.BigInteger;
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Properties;
-import java.util.Random;
-import java.util.Stack;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.Vector;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Before;
@@ -1580,6 +1565,53 @@ public class DataSerializableJUnitTest implements Serializable {
   }
 
   /**
+   * Tests data serializing an {@link java.util.LinkedHashMap}
+   */
+  @Test
+  public void testLinkedHashMap() throws Exception {
+    Random random = getRandom();
+    LinkedHashMap map = new LinkedHashMap();
+    int size = random.nextInt(50);
+    for (int i = 0; i < size; i++) {
+      Object key = new Long(random.nextLong());
+      Object value = String.valueOf(random.nextLong());
+      map.put(key, value);
+    }
+
+    DataOutputStream out = getDataOutput();
+    DataSerializer.writeLinkedHashMap(map, out);
+    out.flush();
+
+    DataInput in = getDataInput();
+    LinkedHashMap map2 = DataSerializer.readLinkedHashMap(in);
+    assertEquals(map, map2);
+  }
+
+  /**
+   * Tests data serializing an {@link LinkedHashMap} using {@link DataSerializer#writeObject}.
+   */
+  @Test
+  public void testLinkedHashMapObject() throws Exception {
+    Random random = getRandom();
+    LinkedHashMap map = new LinkedHashMap();
+    int size = random.nextInt(50);
+    for (int i = 0; i < size; i++) {
+      Object key = new Long(random.nextLong());
+      Object value = String.valueOf(random.nextLong());
+      map.put(key, value);
+    }
+
+    DataOutputStream out = getDataOutput();
+    DataSerializer.writeObject(map, out);
+    out.flush();
+
+    DataInput in = getDataInput();
+    LinkedHashMap map2 = (LinkedHashMap) DataSerializer.readObject(in);
+    assertEquals(map, map2);
+  }
+
+
+  /**
    * Tests data serializing an {@link IdentityHashMap}
    */
   @Test


[25/34] geode git commit: GEODE-2142: Removal of offending JSON.ORG code and license information

Posted by kl...@apache.org.
GEODE-2142: Removal of offending JSON.ORG code and license information


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a2f47b72
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a2f47b72
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a2f47b72

Branch: refs/heads/GEODE-4160-mockito
Commit: a2f47b724d0894811d77ce92c524e3eba4ed34f2
Parents: 76ea6c3
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 14:22:55 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 NOTICE                               |  4 +---
 geode-assembly/src/main/dist/LICENSE | 30 ------------------------------
 2 files changed, 1 insertion(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/a2f47b72/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
index 13a30d3..d27ae96 100644
--- a/NOTICE
+++ b/NOTICE
@@ -18,6 +18,4 @@ Copyright 2016 AddThis
    Copyright 2014 The Apache Software Foundation
 
 This product includes software developed by the MX4J
-project (http://mx4j.sourceforge.net).
-
-This project includes software licensed under the JSON license.
+project (http://mx4j.sourceforge.net).
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/a2f47b72/geode-assembly/src/main/dist/LICENSE
----------------------------------------------------------------------
diff --git a/geode-assembly/src/main/dist/LICENSE b/geode-assembly/src/main/dist/LICENSE
index a00b0c3..2f2de95 100644
--- a/geode-assembly/src/main/dist/LICENSE
+++ b/geode-assembly/src/main/dist/LICENSE
@@ -595,36 +595,6 @@ Federal Courts of the Northern District of California and the state courts
 of the State of California, with venue lying in Santa Clara County,
 California.
 
-
----------------------------------------------------------------------------
-The JSON License (http://www.json.org/license.html)
----------------------------------------------------------------------------
-
-Apache Geode bundles the following file under the JSON license:
-
-  - JSON (http://www.json.org), Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-
 ---------------------------------------------------------------------------
 The MIT License (http://opensource.org/licenses/mit-license.html)
 ---------------------------------------------------------------------------


[05/34] geode git commit: GEODE-2142: cyclical dependency in gradle build

Posted by kl...@apache.org.
GEODE-2142: cyclical dependency in gradle build


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/cd58f1ff
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/cd58f1ff
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/cd58f1ff

Branch: refs/heads/GEODE-4160-mockito
Commit: cd58f1ffc5beca3b05c15c2dcd9ff609e6313008
Parents: eac0bb8
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 15:50:57 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 geode-json/build.gradle | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/cd58f1ff/geode-json/build.gradle
----------------------------------------------------------------------
diff --git a/geode-json/build.gradle b/geode-json/build.gradle
index 5715685..8a1727e 100644
--- a/geode-json/build.gradle
+++ b/geode-json/build.gradle
@@ -16,7 +16,4 @@
  */
 
 dependencies {
-    compile project(':geode-core')
-    compile project(':geode-common')
-    testCompile files(project(':geode-core').sourceSets.test.output)
 }
\ No newline at end of file


[31/34] geode git commit: GEODE-2550 Improve README and BUILDING

Posted by kl...@apache.org.
GEODE-2550 Improve README and BUILDING

This closes #407


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/b5fd6b50
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/b5fd6b50
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/b5fd6b50

Branch: refs/heads/GEODE-4160-mockito
Commit: b5fd6b50b18ce13cb53ef72f9fe5f363cb566ba5
Parents: 712d87f
Author: Anthony Baker <ab...@apache.org>
Authored: Sat Feb 25 08:09:48 2017 -0800
Committer: Anthony Baker <ab...@apache.org>
Committed: Mon Feb 27 20:29:55 2017 -0800

----------------------------------------------------------------------
 BUILDING.md |  68 ++++++-----------------
 README.md   | 162 +++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 144 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/b5fd6b50/BUILDING.md
----------------------------------------------------------------------
diff --git a/BUILDING.md b/BUILDING.md
index 0c7bf4d..308ef8a 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -1,64 +1,30 @@
 # Building this Release from Source
 
-Build instructions differ slightly for Unix and Windows platforms.
 All platforms require a Java installation, with JDK 1.8 or more recent version.
 
-## Build from Source on Unix
+Set the JAVA\_HOME environment variable.  For example:
 
-1. Set the JAVA\_HOME environment variable.  For example:
+| Platform | Command |
+| :---: | --- |
+|  Unix    | ``export JAVA_HOME=/usr/java/jdk1.8.0_121``            |
+|  OSX     | ``export JAVA_HOME=`/usr/libexec/java_home -v 1.8``    |
+|  Windows | ``set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_121"`` |
 
-    ```     
-    JAVA_HOME=/usr/java/jdk1.8.0_60
-    export JAVA_HOME
-    ```
-2. Download the project source from the Releases page at [Apache Geode] (http://geode.apache.org), and unpack the source code.
-3. Within the directory containing the unpacked source code, build without the tests:
-    
-    ```
-    $ ./gradlew build -Dskip.tests=true
-    ```
-Or, build with the tests:
-   
-    ```
-    $ ./gradlew build
-    ```
-The built binaries will be in `geode-assembly/build/distributions/`,
-or the `gfsh` script can be found in 
-`geode-assembly/build/install/apache-geode/bin/`.
-4. Verify the installation by invoking `gfsh` to print version information and exit:
-   
-    ```
-    $ gfsh version
-    v1.1.0
-    ```
+Download the project source from the Releases page at [Apache Geode]
+(http://geode.apache.org/releases/), and unpack the source code.
 
-## Build from Source on Windows
+Within the directory containing the unpacked source code, run the gradle build:
 
-1. Set the JAVA\_HOME environment variable.  For example:
+    $ ./gradlew build
 
-    ```
-    $ set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_60"
-    ```
-2. Install Gradle, version 2.12 or a more recent version.
-3. Download the project source from the Releases page at [Apache Geode] (http://geode.apache.org), and unpack the source code.
-4. Within the folder containing the unpacked source code, build without the tests:
+Once the build completes, the project files will be installed at
+`geode-assembly/build/install/apache-geode`. The distribution archives will be
+created in `geode-assembly/build/distributions/`.
 
-    ```
-    $ gradle build -Dskip.test=true
-    ```
-Or, build with the tests:
+Verify the installation by invoking the `gfsh` shell command to print version
+information:
 
-    ```
-    $ gradle build
-    ```
-The built binaries will be in `geode-assembly\build\distributions\`,
-or the `gfsh.bat` script can be found in 
-`geode-assembly\build\install\apache-geode\bin\`.
-4. Verify the installation by invoking `gfsh` to print version information and exit:
-   
-    ```
-    $ gfsh.bat version
+    $ ./geode-assembly/build/install/apache-geode/bin/gfsh version
     v1.1.0
-    ```
-
 
+Note: on Windows invoke the `gfsh.bat` script to print the version string.

http://git-wip-us.apache.org/repos/asf/geode/blob/b5fd6b50/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 645f420..0909364 100644
--- a/README.md
+++ b/README.md
@@ -1,73 +1,152 @@
 [<img src="https://geode.apache.org/img/apache_geode_logo.png" align="center"/>](http://geode.apache.org)
 
-[![Build Status](https://travis-ci.org/apache/geode.svg?branch=develop)](https://travis-ci.org/apache/geode) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.geode/geode-core/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.geode%22)
+[![Build Status](https://travis-ci.org/apache/geode.svg?branch=develop)](https://travis-ci.org/apache/geode) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.geode/geode-core/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.geode%22) [![homebrew](https://img.shields.io/homebrew/v/apache-geode.svg)](http://brewformulas.org/ApacheGeode) [![Docker Pulls](https://img.shields.io/docker/pulls/apachegeode/geode.svg)](https://hub.docker.com/r/apachegeode/geode/)
+
 
 ## Contents
-1. [Overview](#overview)  
+1. [Overview](#overview)
+2. [How to Get Apache Geode](#obtaining)
 2. [Main Concepts and Components](#concepts)
 3. [Location of Directions for Building from Source](#building)
 4. [Geode in 5 minutes](#started)
 5. [Application Development](#development)
 6. [Documentation](http://geode.apache.org/docs/)
 7. [Wiki](https://cwiki.apache.org/confluence/display/GEODE/Index)
-                                                                                                                       
 
-## <a name="overview"></a>Overview
-[Apache Geode](http://geode.apache.org/) is a data management platform that provides real-time, consistent access to data-intensive applications throughout widely distributed cloud architectures.
 
-Apache Geode pools memory, CPU, network resources, and optionally local disk across multiple processes to manage application objects and behavior. It uses dynamic replication and data partitioning techniques to implement high availability, improved performance, scalability, and fault tolerance. In addition to being a distributed data container, Apache Geode is an in-memory data management system that provides reliable asynchronous event notifications and guaranteed message delivery.
+## <a name="overview"></a>Overview
 
-Apache Geode is a mature, robust technology originally developed by GemStone Systems in Beaverton, Oregon. Commercially available as GemFire\u2122, the technology was first deployed in the financial sector as the transactional, low-latency data engine used in Wall Street trading platforms.  Today Apache Geode is used by over 600 enterprise customers for high-scale business applications that must meet low latency and 24x7 availability requirements. An example deployment includes [China National Railways](http://pivotal.io/big-data/case-study/scaling-online-sales-for-the-largest-railway-in-the-world-china-railway-corporation) that uses Geode to run railway ticketing for the entire country of China with a 10 node cluster that manages 2 terabytes of "hot data" in memory, and 10 backup nodes for high availability and elastic scale.
+[Apache Geode](http://geode.apache.org/) is
+a data management platform that provides real-time, consistent access to
+data-intensive applications throughout widely distributed cloud architectures.
+
+Apache Geode pools memory, CPU, network resources, and optionally local disk
+across multiple processes to manage application objects and behavior. It uses
+dynamic replication and data partitioning techniques to implement high
+availability, improved performance, scalability, and fault tolerance. In
+addition to being a distributed data container, Apache Geode is an in-memory
+data management system that provides reliable asynchronous event notifications
+and guaranteed message delivery.
+
+Apache Geode is a mature, robust technology originally developed by GemStone
+Systems. Commercially available as GemFire\u2122, it was first deployed in the
+financial sector as the transactional, low-latency data engine used in Wall
+Street trading platforms.  Today Apache Geode technology is used by hundreds of
+enterprise customers for high-scale business applications that must meet low
+latency and 24x7 availability requirements.
+
+## <a name="obtaining"></a>How to Get Apache Geode
+
+You can download Apache Geode from the
+[website](http://geode.apache.org/releases/), run a Docker
+[image](https://hub.docker.com/r/apachegeode/geode/), or install with
+[homebrew](http://brewformulas.org/ApacheGeode) on OSX. Application developers
+can load dependencies from [Maven
+Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.geode%22).
+
+Maven
+```
+<dependencies>
+    <dependency>
+        <groupId>org.apache.geode</groupId>
+        <artifactId>geode-core</artifactId>
+        <version>$VERSION</version>
+    </dependency>
+</dependencies>
+```
+
+Gradle
+```
+dependencies {
+  compile "org.apache.geode:geode-core:$VERSION"
+}
+```
 
 ## <a name="concepts"></a>Main Concepts and Components
 
-_Caches_ are an abstraction that describe a node in an Apache Geode distributed system.
+_Caches_ are an abstraction that describe a node in an Apache Geode distributed
+system.
 
-Within each cache, you define data _regions_. Data regions are analogous to tables in a relational database and manage data in a distributed fashion as name/value pairs. A _replicated_ region stores identical copies of the data on each cache member of a distributed system. A _partitioned_ region spreads the data among cache members. After the system is configured, client applications can access the distributed data in regions without knowledge of the underlying system architecture. You can define listeners to receive notifications when data has changed, and you can define expiration criteria to delete obsolete data in a region.
+Within each cache, you define data _regions_. Data regions are analogous to
+tables in a relational database and manage data in a distributed fashion as
+name/value pairs. A _replicated_ region stores identical copies of the data on
+each cache member of a distributed system. A _partitioned_ region spreads the
+data among cache members. After the system is configured, client applications
+can access the distributed data in regions without knowledge of the underlying
+system architecture. You can define listeners to receive notifications when
+data has changed, and you can define expiration criteria to delete obsolete
+data in a region.
 
-_Locators_ provide clients with both discovery and server load balancing services. Clients are configured with locator information, and the locators maintain a dynamic list of member servers. The locators provide clients with connection information to a server. 
+_Locators_ provide clients with both discovery and server load balancing
+services. Clients are configured with locator information, and the locators
+maintain a dynamic list of member servers. The locators provide clients with
+connection information to a server.
 
 Apache Geode includes the following features:
 
-* Combines redundancy, replication, and a "shared nothing" persistence architecture to deliver fail-safe reliability and performance.
-* Horizontally scalable to thousands of cache members, with multiple cache topologies to meet different enterprise needs. The cache can be distributed across multiple computers.
+* Combines redundancy, replication, and a "shared nothing" persistence
+  architecture to deliver fail-safe reliability and performance.
+* Horizontally scalable to thousands of cache members, with multiple cache
+  topologies to meet different enterprise needs. The cache can be
+  distributed across multiple computers.
 * Asynchronous and synchronous cache update propagation.
-* Delta propagation distributes only the difference between old and new versions of an object (delta) instead of the entire object, resulting in significant distribution cost savings.
-* Reliable asynchronous event notifications and guaranteed message delivery through optimized, low latency distribution layer.
-* Applications run 4 to 40 times faster with no additional hardware.
-* Data awareness and real-time business intelligence. If data changes as you retrieve it, you see the changes immediately.
-* Integration with Spring Framework to speed and simplify the development of scalable, transactional enterprise applications.
+* Delta propagation distributes only the difference between old and new
+  versions of an object (delta) instead of the entire object, resulting in
+  significant distribution cost savings.
+* Reliable asynchronous event notifications and guaranteed message delivery
+  through optimized, low latency distribution layer.
+* Data awareness and real-time business intelligence. If data changes as
+  you retrieve it, you see the changes immediately.
+* Integration with Spring Framework to speed and simplify the development
+  of scalable, transactional enterprise applications.
 * JTA compliant transaction support.
-* Cluster-wide configurations that can be persisted and exported to other clusters.
+* Cluster-wide configurations that can be persisted and exported to other
+  clusters.
 * Remote cluster management through HTTP.
 * REST APIs for REST-enabled application development.
-* Rolling upgrades may be possible, but they will be subject to any limitations imposed by new features.
+* Rolling upgrades may be possible, but they will be subject to any
+  limitations imposed by new features.
 
 ## <a name="building"></a>Building this Release from Source
 
-Directions to build Apache Geode from source are in the source distribution, file `BUILDING.md`.
+See [BUILDING.md](https://github.com/apache/geode/blob/develop/BUILDING.md) for
+instructions on how to build the project.
 
 ## <a name="started"></a>Geode in 5 minutes
 
-With a JDK version 1.8 or a more recent version installed,
+Geode requires installation of JDK version 1.8.  After installing Apache Geode,
 start a locator and server:
 
     $ gfsh
-    gfsh> start locator --name=locator
-    gfsh> start server --name=server
+    gfsh> start locator
+    gfsh> start server
 
 Create a region:
 
-    gfsh> create region --name=region --type=REPLICATE
+    gfsh> create region --name=hello --type=REPLICATE
+
+Write a client application (this example uses a [Gradle](https://gradle.org)
+build script):
+
+_build.gradle_
 
-Write a client application:
+    apply plugin: 'java'
+    apply plugin: 'application'
 
-_HelloWorld.java_
+    mainClassName = 'HelloWorld'
+
+    repositories { mavenCentral() }
+    dependencies {
+      compile 'org.apache.geode:geode-core:1.1.0'
+      runtime 'org.slf4j:slf4j-log4j12:1.7.24'
+    }
+
+_src/main/java/HelloWorld.java_
 
     import java.util.Map;
     import org.apache.geode.cache.Region;
     import org.apache.geode.cache.client.*;
-    
+
     public class HelloWorld {
       public static void main(String[] args) throws Exception {
         ClientCache cache = new ClientCacheFactory()
@@ -75,11 +154,11 @@ _HelloWorld.java_
           .create();
         Region<String, String> region = cache
           .<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
-          .create("region");
-    
+          .create("hello");
+
         region.put("1", "Hello");
         region.put("2", "World");
-    
+
         for (Map.Entry<String, String>  entry : region.entrySet()) {
           System.out.format("key = %s, value = %s\n", entry.getKey(), entry.getValue());
         }
@@ -87,16 +166,30 @@ _HelloWorld.java_
       }
     }
 
-Compile and run `HelloWorld.java`.  The classpath should include `geode-dependencies.jar`.
+Build and run the `HelloWorld` example:
+
+    $ gradle run
+
+The application will connect to the running cluster, create a local cache, put
+some data in the cache, and print the cached data to the console:
 
-    javac -cp /some/path/geode/geode-assembly/build/install/apache-geode/lib/geode-dependencies.jar HelloWorld.java
-    java -cp .:/some/path/geode/geode-assembly/build/install/apache-geode/lib/geode-dependencies.jar HelloWorld
+    key = 1, value = Hello
+    key = 2, value = World
+
+Finally, shutdown the Geode server and locator:
+
+    $ gfsh> shutdown --include-locators=true
+
+For more information see the [Geode
+Examples](https://github.com/apache/geode-examples) repository or the
+[documentation](http://geode.apache.org/docs/).
 
 ## <a name="development"></a>Application Development
 
 Apache Geode applications can be written in these client technologies:
 
-* Java [client](http://geode.apache.org/docs/guide/topologies_and_comm/cs_configuration/chapter_overview.html) or [peer](http://geode.apache.org/docs/guide/topologies_and_comm/p2p_configuration/chapter_overview.html)
+* Java [client](http://geode.apache.org/docs/guide/topologies_and_comm/cs_configuration/chapter_overview.html)
+  or [peer](http://geode.apache.org/docs/guide/topologies_and_comm/p2p_configuration/chapter_overview.html)
 * [REST](http://geode.apache.org/docs/guide/rest_apps/chapter_overview.html)
 * [Memcached](https://cwiki.apache.org/confluence/display/GEODE/Moving+from+memcached+to+gemcached)
 * [Redis](https://cwiki.apache.org/confluence/display/GEODE/Geode+Redis+Adapter)
@@ -106,4 +199,3 @@ The following libraries are available external to the Apache Geode project:
 * [Spring Data GemFire](http://projects.spring.io/spring-data-gemfire/)
 * [Spring Cache](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html)
 * [Python](https://github.com/gemfire/py-gemfire-rest)
-


[33/34] geode git commit: GEODE-2460: update dependency versions

Posted by kl...@apache.org.
GEODE-2460: update dependency versions

* com.fasterxml.jackson.core:jackson-annotation:2.8.6
* com.fasterxml.jackson.core:jackson-core:2.8.6
* com.fasterxml.jackson.core:jackson-databind:2.8.6
* com.fasterxml.jackson.module:jackson-module-scala_2.10:2.8.6
* org.eclipse.persistence:javax.persistence:2.1.1
* fix dependency versions in NOTICE files


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/bc32a76c
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/bc32a76c
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/bc32a76c

Branch: refs/heads/GEODE-4160-mockito
Commit: bc32a76c223d7a2b407fed72595af4056a78e433
Parents: 5ec0d47
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Feb 24 17:13:08 2017 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Feb 28 11:30:53 2017 -0800

----------------------------------------------------------------------
 geode-assembly/src/main/dist/NOTICE           | 10 +++++-----
 geode-pulse/src/main/webapp/META-INF/NOTICE   |  4 ++--
 geode-web-api/src/main/webapp/META-INF/NOTICE |  4 ++--
 gradle/dependency-versions.properties         |  6 +++---
 4 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/bc32a76c/geode-assembly/src/main/dist/NOTICE
----------------------------------------------------------------------
diff --git a/geode-assembly/src/main/dist/NOTICE b/geode-assembly/src/main/dist/NOTICE
index 2cdda71..0985dc2 100644
--- a/geode-assembly/src/main/dist/NOTICE
+++ b/geode-assembly/src/main/dist/NOTICE
@@ -26,7 +26,7 @@ Java ClassMate library was originally written by Tatu Saloranta (tatu.saloranta@
   
   * Brian Langel
 
-Jackson Core 2.8.2
+Jackson Core 2.8.6
 
   # Jackson JSON processor
 
@@ -131,8 +131,8 @@ Copyright (c) 2002-2017 Pivotal, Inc.
   these subcomponents is subject to the terms and conditions of the
   subcomponent's license, as noted in the license.txt file.
 
-Spring Hateoas 0.21.0
-Copyright (c) [2012-2014] Pivotal Software, Inc.
+Spring Hateoas 0.23.0.RELEASE
+Copyright (c) [2012-2017] Pivotal Software, Inc.
 
   This product is licensed to you under the Apache License, Version 2.0 (the "License").  
   You may not use this product except in compliance with the License.  
@@ -142,12 +142,12 @@ Copyright (c) [2012-2014] Pivotal Software, Inc.
   code for the these subcomponents is subject to the terms and
   conditions of the subcomponent's license, as noted in the LICENSE file.
 
-Spring LDAP Core 2.1.0
+Spring LDAP Core 2.3.1.RELEASE
 
    This product includes software developed by the Spring LDAP
    Project (http://www.springframework.org/ldap).
 
-Spring Shell 1.2.0
+Spring Shell 1.2.0.RELEASE
 
    This product includes software developed by the Spring Framework
    Project (http://www.springframework.org).

http://git-wip-us.apache.org/repos/asf/geode/blob/bc32a76c/geode-pulse/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/geode-pulse/src/main/webapp/META-INF/NOTICE b/geode-pulse/src/main/webapp/META-INF/NOTICE
index 166a9ee..1d161e9 100644
--- a/geode-pulse/src/main/webapp/META-INF/NOTICE
+++ b/geode-pulse/src/main/webapp/META-INF/NOTICE
@@ -20,7 +20,7 @@ Copyright 2016 AddThis
 This product includes software developed by the MX4J
 project (http://mx4j.sourceforge.net).
 
-Jackson Core 2.8.0
+Jackson Core 2.8.6
 
   # Jackson JSON processor
   
@@ -55,7 +55,7 @@ Copyright (c) 2002-2017 Pivotal, Inc.
   these subcomponents is subject to the terms and conditions of the
   subcomponent's license, as noted in the license.txt file.
 
-Spring LDAP Core 2.1.0.RELEASE
+Spring LDAP Core 2.3.1.RELEASE
 
    This product includes software developed by the Spring LDAP
    Project (http://www.springframework.org/ldap).

http://git-wip-us.apache.org/repos/asf/geode/blob/bc32a76c/geode-web-api/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/webapp/META-INF/NOTICE b/geode-web-api/src/main/webapp/META-INF/NOTICE
index 8e1775b..8070e9b 100644
--- a/geode-web-api/src/main/webapp/META-INF/NOTICE
+++ b/geode-web-api/src/main/webapp/META-INF/NOTICE
@@ -26,7 +26,7 @@ Java ClassMate library was originally written by Tatu Saloranta (tatu.saloranta@
   
   * Brian Langel
 
-Jackson Core 2.8.2
+Jackson Core 2.8.6
 
   # Jackson JSON processor
   
@@ -61,7 +61,7 @@ Copyright (c) 2002-2017 Pivotal, Inc.
   these subcomponents is subject to the terms and conditions of the
   subcomponent's license, as noted in the license.txt file.
 
-Spring Hateoas 0.21.0
+Spring Hateoas 0.23.0.RELEASE
 Copyright (c) [2012-2014] Pivotal Software, Inc.
 
   This product is licensed to you under the Apache License, Version 2.0 (the "License").  

http://git-wip-us.apache.org/repos/asf/geode/blob/bc32a76c/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index be828af..d4a104e 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -40,14 +40,14 @@ hamcrest-all.version = 1.3
 httpclient.version = 4.5.3
 httpcore.version = 4.4.6
 httpunit.version = 1.7.2
-jackson.version = 2.8.2
-jackson-module-scala_2.10.version = 2.8.2
+jackson.version = 2.8.6
+jackson-module-scala_2.10.version = 2.8.6
 jansi.version = 1.14
 javassist.version = 3.21.0-GA
 javax.ejb-api.version = 3.0
 javax.jsr250-api.version = 1.0
 javax.mail-api.version = 1.4.7
-javax.persistence-api.version = 2.0.0
+javax.persistence-api.version = 2.1.1
 javax.resource-api.version = 1.7
 javax.servlet-api.version = 3.1.0
 javax.transaction-api.version = 1.2


[02/34] geode git commit: GEODE-2461: remove unnecessary explicit dependencies

Posted by kl...@apache.org.
GEODE-2461: remove unnecessary explicit dependencies

* activation - transitive via javax.mail-api
* annotations - unused
* cdi-api - unused
* classmate - transitive via springfox (swagger)
* hadoop - unused
* hbase - unused
* hibernate - unused
* hibernate-commons-annotations - unused
* hsqldb - unused
* jline - transtive via spring-shell
* jsr305 - unused
* paranamer - transitive via jackson-module-paranamer
* quartz - unused
* scala - transitive via jackson-module-scala_2.10


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/64cd6fcd
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/64cd6fcd
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/64cd6fcd

Branch: refs/heads/GEODE-4160-mockito
Commit: 64cd6fcd4e1c7d9318a8f2eee44dca1efd9151f2
Parents: af2328a
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Feb 24 10:21:02 2017 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Feb 24 21:38:15 2017 -0800

----------------------------------------------------------------------
 geode-assembly/build.gradle           |  1 -
 geode-core/build.gradle               |  1 +
 geode-web-api/build.gradle            |  4 ----
 gradle/dependency-versions.properties | 14 --------------
 4 files changed, 1 insertion(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/64cd6fcd/geode-assembly/build.gradle
----------------------------------------------------------------------
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index 3452141..1c95927 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -168,7 +168,6 @@ def cp = {
         it.contains('spring-core') ||
         it.contains('spring-shell') ||
         it.contains('snappy') ||
-        it.contains('hbase') ||
         it.contains('jgroups') ||
         it.contains('netty') ||
 

http://git-wip-us.apache.org/repos/asf/geode/blob/64cd6fcd/geode-core/build.gradle
----------------------------------------------------------------------
diff --git a/geode-core/build.gradle b/geode-core/build.gradle
index 2f60752..757599a 100755
--- a/geode-core/build.gradle
+++ b/geode-core/build.gradle
@@ -122,6 +122,7 @@ dependencies {
 
   // Test Dependencies
   // External
+  testCompile 'com.google.guava:guava:' + project.'guava.version'
   testCompile 'com.jayway.jsonpath:json-path-assert:' + project.'json-path-assert.version'
   testCompile 'org.apache.bcel:bcel:' + project.'bcel.version'
   testRuntime 'org.apache.derby:derby:' + project.'derby.version'

http://git-wip-us.apache.org/repos/asf/geode/blob/64cd6fcd/geode-web-api/build.gradle
----------------------------------------------------------------------
diff --git a/geode-web-api/build.gradle b/geode-web-api/build.gradle
index 9c491a0..8b22bd8 100755
--- a/geode-web-api/build.gradle
+++ b/geode-web-api/build.gradle
@@ -23,12 +23,10 @@ dependencies {
   compile('commons-fileupload:commons-fileupload:' + project.'commons-fileupload.version') {
     exclude module: 'commons-io'
   }
-  compile 'com.fasterxml:classmate:' + project.'classmate.version'
   compile 'com.fasterxml.jackson.core:jackson-annotations:' + project.'jackson.version'
   compile 'com.fasterxml.jackson.core:jackson-core:' + project.'jackson.version'
   compile 'com.fasterxml.jackson.core:jackson-databind:' + project.'jackson.version'
   compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:' + project.'jackson-module-scala_2.10.version'
-  compile 'com.google.guava:guava:' + project.'guava.version'
   compile('io.springfox:springfox-swagger2:' + project.'springfox.version') {
     exclude module: 'slf4j-api'
   }
@@ -36,8 +34,6 @@ dependencies {
     exclude module: 'slf4j-api'
   }
   compile 'org.json4s:json4s-ast_2.10:' + project.'json4s.version'
-  compile 'org.scala-lang:scala-library:' + project.'scala.version'
-  compile 'org.scala-lang:scala-reflect:' + project.'scala.version'
   compile 'org.springframework:spring-beans:' + project.'springframework.version'
   compile 'org.springframework.security:spring-security-core:' + project.'spring-security.version'
   compile 'org.springframework.security:spring-security-web:' + project.'spring-security.version'

http://git-wip-us.apache.org/repos/asf/geode/blob/64cd6fcd/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index 5153f0b..be828af 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -14,17 +14,13 @@
 # limitations under the License.
 
 # Dependency versions
-activation.version = 1.1.1
-annotations.version = 3.0.0
 antlr.version = 2.7.7
 assertj-core.version = 3.6.2
 awaitility.version = 2.0.0
 bcel.version = 6.0
 catch-exception.version = 1.4.4
 catch-throwable.version = 1.4.4
-cdi-api.version = 1.2
 cglib.version = 3.2.4
-classmate.version = 0.9.0
 commons-collections.version = 3.2.2
 commons-configuration.version = 1.10
 commons-fileupload.version = 1.3.2
@@ -40,15 +36,10 @@ dom4j.version = 1.6.1
 fastutil.version = 7.1.0
 google-gson.version=2.8.0
 guava.version = 21.0
-hadoop.version = 2.4.1
 hamcrest-all.version = 1.3
-hbase.version = 0.94.27
-hibernate.version = 3.5.5-Final
-hibernate-commons-annotations.version = 3.2.0.Final
 httpclient.version = 4.5.3
 httpcore.version = 4.4.6
 httpunit.version = 1.7.2
-hsqldb.version = 2.3.4
 jackson.version = 2.8.2
 jackson-module-scala_2.10.version = 2.8.2
 jansi.version = 1.14
@@ -63,14 +54,12 @@ javax.transaction-api.version = 1.2
 jedis.version = 2.9.0
 jetty.version = 9.3.6.v20151106
 jgroups.version = 3.6.10.Final
-jline.version = 2.14.3
 jmock.version = 2.8.2
 jna.version = 4.0.0
 jopt-simple.version = 5.0.3
 json-path.version = 2.2.0
 json-path-assert.version = 2.2.0
 json4s.version = 3.2.4
-jsr305.version = 3.0.1
 junit.version = 4.12
 junit-quickcheck.version = 0.7
 JUnitParams.version = 1.0.6
@@ -85,11 +74,8 @@ mx4j-remote.version = 3.0.1
 mx4j-tools.version = 3.0.1
 netty-all.version = 4.1.8.Final
 open-json.version = 1.8
-paranamer.version = 2.3
 phantomjsdriver.version=1.3.0
 powermock.version = 1.6.6
-quartz.version = 2.2.1
-scala.version = 2.10.0
 selenium.version=3.0.1
 shiro.version=1.3.2
 slf4j-api.version = 1.7.23


[21/34] geode git commit: GEODE-2142: Adding JSON library from the https://github.com/tdunning/open-json project

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/ParsingTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/ParsingTest.java b/geode-json/src/test/java/org/json/ParsingTest.java
new file mode 100755
index 0000000..4a0837a
--- /dev/null
+++ b/geode-json/src/test/java/org/json/ParsingTest.java
@@ -0,0 +1,294 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import org.junit.Test;
+
+import java.util.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class ParsingTest {
+
+    @Test
+    public void testParsingNoObjects() {
+        try {
+            new JSONTokener("").nextValue();
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testParsingLiterals() throws JSONException {
+        assertParsed(Boolean.TRUE, "true");
+        assertParsed(Boolean.FALSE, "false");
+        assertParsed(JSONObject.NULL, "null");
+        assertParsed(JSONObject.NULL, "NULL");
+        assertParsed(Boolean.FALSE, "False");
+        assertParsed(Boolean.TRUE, "truE");
+    }
+
+    @Test
+    public void testParsingQuotedStrings() throws JSONException {
+        assertParsed("abc", "\"abc\"");
+        assertParsed("123", "\"123\"");
+        assertParsed("foo\nbar", "\"foo\\nbar\"");
+        assertParsed("foo bar", "\"foo\\u0020bar\"");
+        assertParsed("\"{}[]/\\:,=;#", "\"\\\"{}[]/\\\\:,=;#\"");
+    }
+
+    @Test
+    public void testParsingSingleQuotedStrings() throws JSONException {
+        assertParsed("abc", "'abc'");
+        assertParsed("123", "'123'");
+        assertParsed("foo\nbar", "'foo\\nbar'");
+        assertParsed("foo bar", "'foo\\u0020bar'");
+        assertParsed("\"{}[]/\\:,=;#", "'\\\"{}[]/\\\\:,=;#'");
+    }
+
+    @Test
+    public void testParsingUnquotedStrings() throws JSONException {
+        assertParsed("abc", "abc");
+        assertParsed("123abc", "123abc");
+        assertParsed("123e0x", "123e0x");
+        assertParsed("123e", "123e");
+        assertParsed("123ee21", "123ee21");
+        assertParsed("0xFFFFFFFFFFFFFFFFF", "0xFFFFFFFFFFFFFFFFF");
+    }
+
+    /**
+     * Unfortunately the original implementation attempts to figure out what
+     * Java number type best suits an input value.
+     */
+    @Test
+    public void testParsingNumbersThatAreBestRepresentedAsLongs() throws JSONException {
+        assertParsed(9223372036854775807L, "9223372036854775807");
+        assertParsed(9223372036854775806L, "9223372036854775806");
+        assertParsed(-9223372036854775808L, "-9223372036854775808");
+        assertParsed(-9223372036854775807L, "-9223372036854775807");
+    }
+
+    @Test
+    public void testParsingNumbersThatAreBestRepresentedAsIntegers() throws JSONException {
+        assertParsed(0, "0");
+        assertParsed(5, "5");
+        assertParsed(-2147483648, "-2147483648");
+        assertParsed(2147483647, "2147483647");
+    }
+
+    @Test
+    public void testParsingNegativeZero() throws JSONException {
+        assertParsed(0, "-0");
+    }
+
+    @Test
+    public void testParsingIntegersWithAdditionalPrecisionYieldDoubles() throws JSONException {
+        assertParsed(1d, "1.00");
+        assertParsed(1d, "1.0");
+        assertParsed(0d, "0.0");
+        assertParsed(-0d, "-0.0");
+    }
+
+    @Test
+    public void testParsingNumbersThatAreBestRepresentedAsDoubles() throws JSONException {
+        assertParsed(9.223372036854776E18, "9223372036854775808");
+        assertParsed(-9.223372036854776E18, "-9223372036854775809");
+        assertParsed(1.7976931348623157E308, "1.7976931348623157e308");
+        assertParsed(2.2250738585072014E-308, "2.2250738585072014E-308");
+        assertParsed(4.9E-324, "4.9E-324");
+        assertParsed(4.9E-324, "4.9e-324");
+    }
+
+    @Test
+    public void testParsingOctalNumbers() throws JSONException {
+        assertParsed(5, "05");
+        assertParsed(8, "010");
+        assertParsed(1046, "02026");
+    }
+
+    @Test
+    public void testParsingHexNumbers() throws JSONException {
+        assertParsed(5, "0x5");
+        assertParsed(16, "0x10");
+        assertParsed(8230, "0x2026");
+        assertParsed(180150010, "0xABCDEFA");
+        assertParsed(2077093803, "0x7BCDEFAB");
+    }
+
+    @Test
+    public void testParsingLargeHexValues() throws JSONException {
+        assertParsed(Integer.MAX_VALUE, "0x7FFFFFFF");
+        String message = "Hex values are parsed as Strings if their signed " +
+                "value is greater than Integer.MAX_VALUE.";
+        assertParsed(message, 0x80000000L, "0x80000000");
+    }
+
+    @Test
+    public void test64BitHexValues() throws JSONException {
+        // note that this is different from the same test in the original Android
+        // this is due to the fact that Long.parseLong doesn't correctly handle
+        // the value -1 expressed as unsigned hex if you use the normal JDK. Presumably
+        // the Android equivalent program does this better.
+        assertParsed("Large hex longs shouldn't yield ints or strings",
+                0xFFFFFFFFFFFFFFFL, "0xFFFFFFFFFFFFFFF");
+    }
+
+    @Test
+    public void testParsingWithCommentsAndWhitespace() throws JSONException {
+        assertParsed("baz", "  // foo bar \n baz");
+        assertParsed("baz", "  // foo bar \r baz");
+        assertParsed("baz", "  // foo bar \r\n baz");
+        assertParsed("baz", "  # foo bar \n baz");
+        assertParsed("baz", "  # foo bar \r baz");
+        assertParsed("baz", "  # foo bar \r\n baz");
+        assertParsed(5, "  /* foo bar \n baz */ 5");
+        assertParsed(5, "  /* foo bar \n baz */ 5 // quux");
+        assertParsed(5, "  5   ");
+        assertParsed(5, "  5  \r\n\t ");
+        assertParsed(5, "\r\n\t   5 ");
+    }
+
+    @Test
+    public void testParsingArrays() throws JSONException {
+        assertParsed(array(), "[]");
+        assertParsed(array(5, 6, true), "[5,6,true]");
+        assertParsed(array(5, 6, array()), "[5,6,[]]");
+        assertParsed(array(5, 6, 7), "[5;6;7]");
+        assertParsed(array(5, 6, 7), "[5  , 6 \t; \r\n 7\n]");
+        assertParsed(array(5, 6, 7, null), "[5,6,7,]");
+        assertParsed(array(null, null), "[,]");
+        assertParsed(array(5, null, null, null, 5), "[5,,,,5]");
+        assertParsed(array(null, 5), "[,5]");
+        assertParsed(array(null, null, null), "[,,]");
+        assertParsed(array(null, null, null, 5), "[,,,5]");
+    }
+
+    @Test
+    public void testParsingObjects() throws JSONException {
+        assertParsed(object("foo", 5), "{\"foo\": 5}");
+        assertParsed(object("foo", 5), "{foo: 5}");
+        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5, \"bar\": \"baz\"}");
+        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5; \"bar\": \"baz\"}");
+        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"= 5; \"bar\"= \"baz\"}");
+        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"=> 5; \"bar\"=> \"baz\"}");
+        assertParsed(object("foo", object(), "bar", array()), "{\"foo\"=> {}; \"bar\"=> []}");
+        assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\": {\"foo\": [5, 6]}}");
+        assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\":\n\t{\t \"foo\":[5,\r6]}}");
+    }
+
+    @Test
+    public void testSyntaxProblemUnterminatedObject() {
+        assertParseFail("{");
+        assertParseFail("{\"foo\"");
+        assertParseFail("{\"foo\":");
+        assertParseFail("{\"foo\":bar");
+        assertParseFail("{\"foo\":bar,");
+        assertParseFail("{\"foo\":bar,\"baz\"");
+        assertParseFail("{\"foo\":bar,\"baz\":");
+        assertParseFail("{\"foo\":bar,\"baz\":true");
+        assertParseFail("{\"foo\":bar,\"baz\":true,");
+    }
+
+    @Test
+    public void testSyntaxProblemEmptyString() {
+        assertParseFail("");
+    }
+
+    @Test
+    public void testSyntaxProblemUnterminatedArray() {
+        assertParseFail("[");
+        assertParseFail("[,");
+        assertParseFail("[,,");
+        assertParseFail("[true");
+        assertParseFail("[true,");
+        assertParseFail("[true,,");
+    }
+
+    @Test
+    public void testSyntaxProblemMalformedObject() {
+        assertParseFail("{:}");
+        assertParseFail("{\"key\":}");
+        assertParseFail("{:true}");
+        assertParseFail("{\"key\":true:}");
+        assertParseFail("{null:true}");
+        assertParseFail("{true:true}");
+        assertParseFail("{0xFF:true}");
+    }
+
+    private void assertParseFail(String malformedJson) {
+        try {
+            new JSONTokener(malformedJson).nextValue();
+            fail("Successfully parsed: \"" + malformedJson + "\"");
+        } catch (JSONException ignored) {
+        } catch (StackOverflowError e) {
+            fail("Stack overflowed on input: \"" + malformedJson + "\"");
+        }
+    }
+
+    private JSONArray array(Object... elements) {
+        return new JSONArray(Arrays.asList(elements));
+    }
+
+    private JSONObject object(Object... keyValuePairs) throws JSONException {
+        JSONObject result = new JSONObject();
+        for (int i = 0; i < keyValuePairs.length; i += 2) {
+            result.put((String) keyValuePairs[i], keyValuePairs[i + 1]);
+        }
+        return result;
+    }
+
+    private void assertParsed(String message, Object expected, String json) throws JSONException {
+        Object actual = new JSONTokener(json).nextValue();
+        actual = canonicalize(actual);
+        expected = canonicalize(expected);
+        assertEquals("For input \"" + json + "\" " + message, expected, actual);
+    }
+
+    private void assertParsed(Object expected, String json) throws JSONException {
+        assertParsed("", expected, json);
+    }
+
+    /**
+     * Since they don't implement equals or hashCode properly, this recursively
+     * replaces JSONObjects with an equivalent HashMap, and JSONArrays with the
+     * equivalent ArrayList.
+     */
+    private Object canonicalize(Object input) throws JSONException {
+        if (input instanceof JSONArray) {
+            JSONArray array = (JSONArray) input;
+            List<Object> result = new ArrayList<Object>();
+            for (int i = 0; i < array.length(); i++) {
+                result.add(canonicalize(array.opt(i)));
+            }
+            return result;
+        } else if (input instanceof JSONObject) {
+            JSONObject object = (JSONObject) input;
+            Map<String, Object> result = new HashMap<String, Object>();
+            for (Iterator<?> i = object.keys(); i.hasNext(); ) {
+                String key = (String) i.next();
+                result.put(key, canonicalize(object.get(key)));
+            }
+            return result;
+        } else if (input == null || input.equals(JSONObject.NULL)) {
+            return JSONObject.NULL;
+        } else {
+            return input;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/SelfUseTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/SelfUseTest.java b/geode-json/src/test/java/org/json/SelfUseTest.java
new file mode 100755
index 0000000..0b9fb2c
--- /dev/null
+++ b/geode-json/src/test/java/org/json/SelfUseTest.java
@@ -0,0 +1,276 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * These tests checks self use calls. For the most part we doesn't attempt to
+ * cover self-use, except in those cases where our clean room implementation
+ * does it.
+ * <p>
+ * <p>This black box test was written without inspecting the non-free org.json
+ * sourcecode.
+ */
+public class SelfUseTest {
+
+    private int objectPutCalls = 0;
+    private int objectGetCalls = 0;
+    private int objectOptCalls = 0;
+    private int objectOptTypeCalls = 0;
+    private int arrayPutCalls = 0;
+    private int arrayGetCalls = 0;
+    private int arrayOptCalls = 0;
+    private int arrayOptTypeCalls = 0;
+    private int tokenerNextCalls = 0;
+    private int tokenerNextValueCalls = 0;
+
+    private final JSONObject object = new JSONObject() {
+        @Override
+        public JSONObject put(String name, Object value) throws JSONException {
+            objectPutCalls++;
+            return super.put(name, value);
+        }
+
+        @Override
+        public Object get(String name) throws JSONException {
+            objectGetCalls++;
+            return super.get(name);
+        }
+
+        @Override
+        public Object opt(String name) {
+            objectOptCalls++;
+            return super.opt(name);
+        }
+
+        @Override
+        public boolean optBoolean(String key, boolean defaultValue) {
+            objectOptTypeCalls++;
+            return super.optBoolean(key, defaultValue);
+        }
+
+        @Override
+        public double optDouble(String key, double defaultValue) {
+            objectOptTypeCalls++;
+            return super.optDouble(key, defaultValue);
+        }
+
+        @Override
+        public int optInt(String key, int defaultValue) {
+            objectOptTypeCalls++;
+            return super.optInt(key, defaultValue);
+        }
+
+        @Override
+        public long optLong(String key, long defaultValue) {
+            objectOptTypeCalls++;
+            return super.optLong(key, defaultValue);
+        }
+
+        @Override
+        public String optString(String key, String defaultValue) {
+            objectOptTypeCalls++;
+            return super.optString(key, defaultValue);
+        }
+    };
+
+    private final JSONArray array = new JSONArray() {
+        @Override
+        public JSONArray put(int index, Object value) throws JSONException {
+            arrayPutCalls++;
+            return super.put(index, value);
+        }
+
+        @Override
+        public Object get(int index) throws JSONException {
+            arrayGetCalls++;
+            return super.get(index);
+        }
+
+        @Override
+        public Object opt(int index) {
+            arrayOptCalls++;
+            return super.opt(index);
+        }
+
+        @Override
+        public boolean optBoolean(int index, boolean fallback) {
+            arrayOptTypeCalls++;
+            return super.optBoolean(index, fallback);
+        }
+
+        @Override
+        public double optDouble(int index, double fallback) {
+            arrayOptTypeCalls++;
+            return super.optDouble(index, fallback);
+        }
+
+        @Override
+        public long optLong(int index, long fallback) {
+            arrayOptTypeCalls++;
+            return super.optLong(index, fallback);
+        }
+
+        @Override
+        public String optString(int index, String fallback) {
+            arrayOptTypeCalls++;
+            return super.optString(index, fallback);
+        }
+
+        @Override
+        public int optInt(int index, int fallback) {
+            arrayOptTypeCalls++;
+            return super.optInt(index, fallback);
+        }
+    };
+
+    private final JSONTokener tokener = new JSONTokener("{\"foo\": [true]}") {
+        @Override
+        public char next() {
+            tokenerNextCalls++;
+            return super.next();
+        }
+
+        @Override
+        public Object nextValue() throws JSONException {
+            tokenerNextValueCalls++;
+            return super.nextValue();
+        }
+    };
+
+
+    @Test
+    public void testObjectPut() throws JSONException {
+        object.putOpt("foo", "bar");
+        assertEquals(1, objectPutCalls);
+    }
+
+    @Test
+    public void testObjectAccumulate() throws JSONException {
+        object.accumulate("foo", "bar");
+        assertEquals(1, objectPutCalls);
+    }
+
+    @Test
+    public void testObjectGetBoolean() throws JSONException {
+        object.put("foo", "true");
+        object.getBoolean("foo");
+        assertEquals(1, objectGetCalls);
+    }
+
+    @Test
+    public void testObjectOptType() throws JSONException {
+        object.optBoolean("foo");
+        assertEquals(1, objectOptCalls);
+        assertEquals(1, objectOptTypeCalls);
+        object.optDouble("foo");
+        assertEquals(2, objectOptCalls);
+        assertEquals(2, objectOptTypeCalls);
+        object.optInt("foo");
+        assertEquals(3, objectOptCalls);
+        assertEquals(3, objectOptTypeCalls);
+        object.optLong("foo");
+        assertEquals(4, objectOptCalls);
+        assertEquals(4, objectOptTypeCalls);
+        object.optString("foo");
+        assertEquals(5, objectOptCalls);
+        assertEquals(5, objectOptTypeCalls);
+    }
+
+    @Test
+    public void testToJSONArray() throws JSONException {
+        object.put("foo", 5);
+        object.put("bar", 10);
+        array.put("foo");
+        array.put("baz");
+        array.put("bar");
+        object.toJSONArray(array);
+        assertEquals(3, arrayOptCalls);
+        assertEquals(0, arrayOptTypeCalls);
+        assertEquals(3, objectOptCalls);
+        assertEquals(0, objectOptTypeCalls);
+    }
+
+    @Test
+    public void testPutAtIndex() throws JSONException {
+        array.put(10, false);
+        assertEquals(1, arrayPutCalls);
+    }
+
+    @Test
+    public void testIsNull() {
+        array.isNull(5);
+        assertEquals(1, arrayOptCalls);
+    }
+
+    @Test
+    public void testArrayGetType() throws JSONException {
+        array.put(true);
+        array.getBoolean(0);
+        assertEquals(1, arrayGetCalls);
+    }
+
+    @Test
+    public void testArrayOptType() throws JSONException {
+        array.optBoolean(3);
+        assertEquals(1, arrayOptCalls);
+        assertEquals(1, arrayOptTypeCalls);
+        array.optDouble(3);
+        assertEquals(2, arrayOptCalls);
+        assertEquals(2, arrayOptTypeCalls);
+        array.optInt(3);
+        assertEquals(3, arrayOptCalls);
+        assertEquals(3, arrayOptTypeCalls);
+        array.optLong(3);
+        assertEquals(4, arrayOptCalls);
+        assertEquals(4, arrayOptTypeCalls);
+        array.optString(3);
+        assertEquals(5, arrayOptCalls);
+        assertEquals(5, arrayOptTypeCalls);
+    }
+
+    @Test
+    public void testToJSONObject() throws JSONException {
+        array.put("foo");
+        array.put("baz");
+        array.put("bar");
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        values.put(11d);
+        values.put(30);
+        values.toJSONObject(array);
+        assertEquals(3, arrayOptCalls);
+        assertEquals(0, arrayOptTypeCalls);
+    }
+
+    @Test
+    public void testNextExpecting() throws JSONException {
+        tokener.next('{');
+        assertEquals(1, tokenerNextCalls);
+        tokener.next('\"');
+        assertEquals(2, tokenerNextCalls);
+    }
+
+    @Test
+    public void testNextValue() throws JSONException {
+        tokener.nextValue();
+        assertEquals(4, tokenerNextValueCalls);
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/resources/sample-01.json
----------------------------------------------------------------------
diff --git a/geode-json/src/test/resources/sample-01.json b/geode-json/src/test/resources/sample-01.json
new file mode 100755
index 0000000..9cfef12
--- /dev/null
+++ b/geode-json/src/test/resources/sample-01.json
@@ -0,0 +1,227 @@
+[
+  {
+    "_id": "58309f3bd307b72ae49a9b23",
+    "index": 0,
+    "guid": "5764ebd8-b333-469e-8d83-4eb5658f1566",
+    "isActive": true,
+    "balance": "$1,099.93",
+    "picture": "http://placehold.it/32x32",
+    "age": 37,
+    "eyeColor": "blue",
+    "name": "Barrera Wilkerson",
+    "gender": "male",
+    "company": "VURBO",
+    "email": "barrerawilkerson@vurbo.com",
+    "phone": "+1 (817) 429-2473",
+    "address": "522 Vanderveer Street, Detroit, Wyoming, 4320",
+    "about": "Et officia aute ullamco magna adipisicing non ut cupidatat cupidatat aliquip. Tempor occaecat ex ad dolore aliquip mollit ea esse ipsum. Est incididunt sunt commodo duis est. Reprehenderit in ut reprehenderit ad culpa ea fugiat et est adipisicing aliquip. Id mollit voluptate qui pariatur officia.\r\n",
+    "registered": "2016-06-29T08:54:14 +07:00",
+    "latitude": -87.548434,
+    "longitude": 64.251242,
+    "tags": [
+      "aliqua",
+      "ex",
+      "sit",
+      "magna",
+      "dolor",
+      "laborum",
+      "non"
+    ],
+    "friends": [
+      {
+        "id": 0,
+        "name": "Byers Pratt"
+      },
+      {
+        "id": 1,
+        "name": "Kennedy Contreras"
+      },
+      {
+        "id": 2,
+        "name": "Frazier Monroe"
+      }
+    ],
+    "greeting": "Hello, Barrera Wilkerson! You have 3 unread messages.",
+    "favoriteFruit": "banana"
+  },
+  {
+    "_id": "58309f3b1f506440093a41d1",
+    "index": 1,
+    "guid": "de1a6cc9-f8b3-426e-b68a-cc30e1fff3c1",
+    "isActive": false,
+    "balance": "$3,397.60",
+    "picture": "http://placehold.it/32x32",
+    "age": 32,
+    "eyeColor": "blue",
+    "name": "Trisha Morris",
+    "gender": "female",
+    "company": "AMTAP",
+    "email": "trishamorris@amtap.com",
+    "phone": "+1 (805) 423-3375",
+    "address": "495 Tampa Court, Libertytown, New Hampshire, 5177",
+    "about": "Elit culpa Lorem dolor sit laborum ut ullamco ullamco nostrud reprehenderit adipisicing eiusmod. Aliqua quis dolor esse sint. Dolore in excepteur laborum anim ut consectetur. Nisi officia est eu ex ex id. Ipsum duis ullamco ad ut labore dolor. In amet tempor deserunt ullamco velit eu fugiat.\r\n",
+    "registered": "2015-02-08T06:14:19 +08:00",
+    "latitude": -81.956277,
+    "longitude": 143.685584,
+    "tags": [
+      "cillum",
+      "ullamco",
+      "magna",
+      "cillum",
+      "voluptate",
+      "magna",
+      "exercitation"
+    ],
+    "friends": [
+      {
+        "id": 0,
+        "name": "Fuentes Stout"
+      },
+      {
+        "id": 1,
+        "name": "Violet Vargas"
+      },
+      {
+        "id": 2,
+        "name": "Schmidt Wilder"
+      }
+    ],
+    "greeting": "Hello, Trisha Morris! You have 4 unread messages.",
+    "favoriteFruit": "strawberry"
+  },
+  {
+    "_id": "58309f3beaef2f31339b3755",
+    "index": 2,
+    "guid": "0bf387b7-abc2-4828-becc-1269928f7c3d",
+    "isActive": false,
+    "balance": "$1,520.64",
+    "picture": "http://placehold.it/32x32",
+    "age": 37,
+    "eyeColor": "blue",
+    "name": "Deanna Santiago",
+    "gender": "female",
+    "company": "MEGALL",
+    "email": "deannasantiago@megall.com",
+    "phone": "+1 (916) 511-2291",
+    "address": "919 Fayette Street, Homestead, Utah, 8669",
+    "about": "Sit amet ex quis velit irure Lorem non quis aliquip dolor pariatur nulla Lorem officia. Deserunt officia sit velit labore sint nostrud elit aliquip labore ullamco consectetur id amet. Ullamco duis commodo sit incididunt. Fugiat consectetur ad incididunt officia. Sint cillum minim laborum laboris id cillum est exercitation in eiusmod qui.\r\n",
+    "registered": "2015-11-18T08:39:28 +08:00",
+    "latitude": 79.105701,
+    "longitude": -146.901754,
+    "tags": [
+      "non",
+      "ullamco",
+      "cillum",
+      "ipsum",
+      "amet",
+      "aliqua",
+      "aliquip"
+    ],
+    "friends": [
+      {
+        "id": 0,
+        "name": "Hanson Anderson"
+      },
+      {
+        "id": 1,
+        "name": "Pollard Soto"
+      },
+      {
+        "id": 2,
+        "name": "Barlow Campbell"
+      }
+    ],
+    "greeting": "Hello, Deanna Santiago! You have 7 unread messages.",
+    "favoriteFruit": "apple"
+  },
+  {
+    "_id": "58309f3b49a68ad01346f27f",
+    "index": 3,
+    "guid": "d29c0dcc-48fb-4ca4-a63b-b47c0e6d6398",
+    "isActive": false,
+    "balance": "$2,069.96",
+    "picture": "http://placehold.it/32x32",
+    "age": 29,
+    "eyeColor": "green",
+    "name": "Brooks Gates",
+    "gender": "male",
+    "company": "TERRAGEN",
+    "email": "brooksgates@terragen.com",
+    "phone": "+1 (875) 483-2224",
+    "address": "562 Noll Street, Kipp, Louisiana, 7659",
+    "about": "Reprehenderit laboris mollit nulla commodo quis laborum commodo. Laborum aliquip laboris officia minim ipsum laborum ipsum reprehenderit quis laboris est sint culpa. Culpa magna aute mollit exercitation.\r\n",
+    "registered": "2016-05-04T10:34:38 +07:00",
+    "latitude": 72.77079,
+    "longitude": -134.291768,
+    "tags": [
+      "est",
+      "sunt",
+      "laboris",
+      "ea",
+      "proident",
+      "aute",
+      "excepteur"
+    ],
+    "friends": [
+      {
+        "id": 0,
+        "name": "Roxanne Morgan"
+      },
+      {
+        "id": 1,
+        "name": "Tamara Kelly"
+      },
+      {
+        "id": 2,
+        "name": "Cleveland Bush"
+      }
+    ],
+    "greeting": "Hello, Brooks Gates! You have 1 unread messages.",
+    "favoriteFruit": "banana"
+  },
+  {
+    "_id": "58309f3be746700e9af9a645",
+    "index": 4,
+    "guid": "54382bd6-c476-469d-9e1c-e546f959db51",
+    "isActive": true,
+    "balance": "$2,012.57",
+    "picture": "http://placehold.it/32x32",
+    "age": 40,
+    "eyeColor": "brown",
+    "name": "Jackie Thomas",
+    "gender": "female",
+    "company": "HINWAY",
+    "email": "jackiethomas@hinway.com",
+    "phone": "+1 (843) 470-2096",
+    "address": "910 Emerson Place, Gwynn, Federated States Of Micronesia, 4688",
+    "about": "Id cupidatat laboris elit est eiusmod esse nostrud. Ex commodo nisi voluptate est nisi laborum officia sint incididunt pariatur qui deserunt ullamco. Fugiat proident magna ipsum sit sint id adipisicing sit nostrud labore sit officia. Eiusmod exercitation non enim excepteur amet irure ullamco consectetur cupidatat proident Lorem reprehenderit aliquip. Veniam esse dolor Lorem incididunt proident officia enim in incididunt culpa. Mollit voluptate commodo aliquip anim ipsum nostrud ut labore enim labore qui do minim incididunt. Quis irure proident voluptate nisi qui sunt aute duis irure.\r\n",
+    "registered": "2014-08-03T09:21:43 +07:00",
+    "latitude": 84.871256,
+    "longitude": 2.043339,
+    "tags": [
+      "tempor",
+      "ut",
+      "deserunt",
+      "esse",
+      "nostrud",
+      "dolore",
+      "ex"
+    ],
+    "friends": [
+      {
+        "id": 0,
+        "name": "Lois Walters"
+      },
+      {
+        "id": 1,
+        "name": "Brewer Buchanan"
+      },
+      {
+        "id": 2,
+        "name": "Mccormick Fleming"
+      }
+    ],
+    "greeting": "Hello, Jackie Thomas! You have 2 unread messages.",
+    "favoriteFruit": "banana"
+  }
+]
\ No newline at end of file


[18/34] geode git commit: GEODE-2142: removing tests so run precheckin

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/JSONTokenerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONTokenerTest.java b/geode-json/src/test/java/org/json/JSONTokenerTest.java
deleted file mode 100755
index f68b3ce..0000000
--- a/geode-json/src/test/java/org/json/JSONTokenerTest.java
+++ /dev/null
@@ -1,616 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-/**
- * This black box test was written without inspecting the non-free org.json sourcecode.
- */
-public class JSONTokenerTest extends TestCase {
-
-  public void testNulls() throws JSONException {
-    // JSONTokener accepts null, only to fail later on almost all APIs!
-    new JSONTokener((String) null).back();
-
-    try {
-      new JSONTokener((String) null).more();
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).next();
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).next(3);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).next('A');
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).nextClean();
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).nextString('"');
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).nextTo('A');
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).nextTo("ABC");
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).nextValue();
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).skipPast("ABC");
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    try {
-      new JSONTokener((String) null).skipTo('A');
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-
-    // noinspection ThrowableResultOfMethodCallIgnored
-    assertEquals("foo! at character 0 of null",
-        new JSONTokener((String) null).syntaxError("foo!").getMessage());
-
-    assertEquals(" at character 0 of null", new JSONTokener((String) null).toString());
-  }
-
-  public void testEmptyString() throws JSONException {
-    JSONTokener backTokener = new JSONTokener("");
-    backTokener.back();
-    assertEquals(" at character 0 of ", backTokener.toString());
-    assertFalse(new JSONTokener("").more());
-    assertEquals('\0', new JSONTokener("").next());
-    try {
-      new JSONTokener("").next(3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONTokener("").next('A');
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals('\0', new JSONTokener("").nextClean());
-    try {
-      new JSONTokener("").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals("", new JSONTokener("").nextTo('A'));
-    assertEquals("", new JSONTokener("").nextTo("ABC"));
-    try {
-      new JSONTokener("").nextValue();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    new JSONTokener("").skipPast("ABC");
-    assertEquals('\0', new JSONTokener("").skipTo('A'));
-    // noinspection ThrowableResultOfMethodCallIgnored
-    assertEquals("foo! at character 0 of ", new JSONTokener("").syntaxError("foo!").getMessage());
-    assertEquals(" at character 0 of ", new JSONTokener("").toString());
-  }
-
-  public void testCharacterNavigation() throws JSONException {
-    JSONTokener abcdeTokener = new JSONTokener("ABCDE");
-    assertEquals('A', abcdeTokener.next());
-    assertEquals('B', abcdeTokener.next('B'));
-    assertEquals("CD", abcdeTokener.next(2));
-    try {
-      abcdeTokener.next(2);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals('E', abcdeTokener.nextClean());
-    assertEquals('\0', abcdeTokener.next());
-    assertFalse(abcdeTokener.more());
-    abcdeTokener.back();
-    assertTrue(abcdeTokener.more());
-    assertEquals('E', abcdeTokener.next());
-  }
-
-  public void testBackNextAndMore() throws JSONException {
-    JSONTokener abcTokener = new JSONTokener("ABC");
-    assertTrue(abcTokener.more());
-    abcTokener.next();
-    abcTokener.next();
-    assertTrue(abcTokener.more());
-    abcTokener.next();
-    assertFalse(abcTokener.more());
-    abcTokener.back();
-    assertTrue(abcTokener.more());
-    abcTokener.next();
-    assertFalse(abcTokener.more());
-    abcTokener.back();
-    abcTokener.back();
-    abcTokener.back();
-    abcTokener.back(); // you can back up before the beginning of a String!
-    assertEquals('A', abcTokener.next());
-  }
-
-  public void testNextMatching() throws JSONException {
-    JSONTokener abcdTokener = new JSONTokener("ABCD");
-    assertEquals('A', abcdTokener.next('A'));
-    try {
-      abcdTokener.next('C'); // although it failed, this op consumes a character of input
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals('C', abcdTokener.next('C'));
-    assertEquals('D', abcdTokener.next('D'));
-    try {
-      abcdTokener.next('E');
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  public void testNextN() throws JSONException {
-    JSONTokener abcdeTokener = new JSONTokener("ABCDEF");
-    assertEquals("", abcdeTokener.next(0));
-    try {
-      abcdeTokener.next(7);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals("ABC", abcdeTokener.next(3));
-    try {
-      abcdeTokener.next(4);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  public void testNextNWithAllRemaining() throws JSONException {
-    JSONTokener tokener = new JSONTokener("ABCDEF");
-    tokener.next(3);
-    try {
-      tokener.next(3);
-    } catch (JSONException e) {
-      AssertionFailedError error = new AssertionFailedError("off-by-one error?");
-      error.initCause(e);
-      throw error;
-    }
-  }
-
-  public void testNext0() throws JSONException {
-    JSONTokener tokener = new JSONTokener("ABCDEF");
-    tokener.next(5);
-    tokener.next();
-    try {
-      tokener.next(0);
-    } catch (JSONException e) {
-      Error error = new AssertionFailedError("Returning an empty string should be valid");
-      error.initCause(e);
-      throw error;
-    }
-  }
-
-  public void testNextCleanComments() throws JSONException {
-    JSONTokener tokener =
-        new JSONTokener("  A  /*XX*/B/*XX//XX\n//XX\nXX*/C//X//X//X\nD/*X*///X\n");
-    assertEquals('A', tokener.nextClean());
-    assertEquals('B', tokener.nextClean());
-    assertEquals('C', tokener.nextClean());
-    assertEquals('D', tokener.nextClean());
-    assertEquals('\0', tokener.nextClean());
-  }
-
-  public void testNextCleanNestedCStyleComments() throws JSONException {
-    JSONTokener tokener = new JSONTokener("A /* B /* C */ D */ E");
-    assertEquals('A', tokener.nextClean());
-    assertEquals('D', tokener.nextClean());
-    assertEquals('*', tokener.nextClean());
-    assertEquals('/', tokener.nextClean());
-    assertEquals('E', tokener.nextClean());
-  }
-
-  /**
-   * Some applications rely on parsing '#' to lead an end-of-line comment. http://b/2571423
-   */
-  public void testNextCleanHashComments() throws JSONException {
-    JSONTokener tokener = new JSONTokener("A # B */ /* C */ \nD #");
-    assertEquals('A', tokener.nextClean());
-    assertEquals('D', tokener.nextClean());
-    assertEquals('\0', tokener.nextClean());
-  }
-
-  public void testNextCleanCommentsTrailingSingleSlash() throws JSONException {
-    JSONTokener tokener = new JSONTokener(" / S /");
-    assertEquals('/', tokener.nextClean());
-    assertEquals('S', tokener.nextClean());
-    assertEquals('/', tokener.nextClean());
-    assertEquals("nextClean doesn't consume a trailing slash", '\0', tokener.nextClean());
-  }
-
-  public void testNextCleanTrailingOpenComment() throws JSONException {
-    try {
-      new JSONTokener("  /* ").nextClean();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals('\0', new JSONTokener("  // ").nextClean());
-  }
-
-  public void testNextCleanNewlineDelimiters() throws JSONException {
-    assertEquals('B', new JSONTokener("  // \r\n  B ").nextClean());
-    assertEquals('B', new JSONTokener("  // \n  B ").nextClean());
-    assertEquals('B', new JSONTokener("  // \r  B ").nextClean());
-  }
-
-  public void testNextCleanSkippedWhitespace() throws JSONException {
-    assertEquals("character tabulation", 'A', new JSONTokener("\tA").nextClean());
-    assertEquals("line feed", 'A', new JSONTokener("\nA").nextClean());
-    assertEquals("carriage return", 'A', new JSONTokener("\rA").nextClean());
-    assertEquals("space", 'A', new JSONTokener(" A").nextClean());
-  }
-
-  /**
-   * Tests which characters tokener treats as ignorable whitespace. See Kevin Bourrillion's
-   * <a href="https://spreadsheets.google.com/pub?key=pd8dAQyHbdewRsnE5x5GzKQ">list of whitespace
-   * characters</a>.
-   */
-  public void testNextCleanRetainedWhitespace() throws JSONException {
-    assertNotClean("null", '\u0000');
-    assertNotClean("next line", '\u0085');
-    assertNotClean("non-breaking space", '\u00a0');
-    assertNotClean("ogham space mark", '\u1680');
-    assertNotClean("mongolian vowel separator", '\u180e');
-    assertNotClean("en quad", '\u2000');
-    assertNotClean("em quad", '\u2001');
-    assertNotClean("en space", '\u2002');
-    assertNotClean("em space", '\u2003');
-    assertNotClean("three-per-em space", '\u2004');
-    assertNotClean("four-per-em space", '\u2005');
-    assertNotClean("six-per-em space", '\u2006');
-    assertNotClean("figure space", '\u2007');
-    assertNotClean("punctuation space", '\u2008');
-    assertNotClean("thin space", '\u2009');
-    assertNotClean("hair space", '\u200a');
-    assertNotClean("zero-width space", '\u200b');
-    assertNotClean("left-to-right mark", '\u200e');
-    assertNotClean("right-to-left mark", '\u200f');
-    assertNotClean("line separator", '\u2028');
-    assertNotClean("paragraph separator", '\u2029');
-    assertNotClean("narrow non-breaking space", '\u202f');
-    assertNotClean("medium mathematical space", '\u205f');
-    assertNotClean("ideographic space", '\u3000');
-    assertNotClean("line tabulation", '\u000b');
-    assertNotClean("form feed", '\u000c');
-    assertNotClean("information separator 4", '\u001c');
-    assertNotClean("information separator 3", '\u001d');
-    assertNotClean("information separator 2", '\u001e');
-    assertNotClean("information separator 1", '\u001f');
-  }
-
-  private void assertNotClean(String name, char c) throws JSONException {
-    assertEquals("The character " + name + " is not whitespace according to the JSON spec.", c,
-        new JSONTokener(new String(new char[] {c, 'A'})).nextClean());
-  }
-
-  public void testNextString() throws JSONException {
-    assertEquals("", new JSONTokener("'").nextString('\''));
-    assertEquals("", new JSONTokener("\"").nextString('\"'));
-    assertEquals("ABC", new JSONTokener("ABC'DEF").nextString('\''));
-    assertEquals("ABC", new JSONTokener("ABC'''DEF").nextString('\''));
-
-    // nextString permits slash-escaping of arbitrary characters!
-    assertEquals("ABC", new JSONTokener("A\\B\\C'DEF").nextString('\''));
-
-    JSONTokener tokener = new JSONTokener(" 'abc' 'def' \"ghi\"");
-    tokener.next();
-    assertEquals('\'', tokener.next());
-    assertEquals("abc", tokener.nextString('\''));
-    tokener.next();
-    assertEquals('\'', tokener.next());
-    assertEquals("def", tokener.nextString('\''));
-    tokener.next();
-    assertEquals('"', tokener.next());
-    assertEquals("ghi", tokener.nextString('\"'));
-    assertFalse(tokener.more());
-  }
-
-  public void testNextStringNoDelimiter() throws JSONException {
-    try {
-      new JSONTokener("").nextString('\'');
-      fail();
-    } catch (JSONException ignored) {
-    }
-
-    JSONTokener tokener = new JSONTokener(" 'abc");
-    tokener.next();
-    tokener.next();
-    try {
-      tokener.next('\'');
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  public void testNextStringEscapedQuote() throws JSONException {
-    try {
-      new JSONTokener("abc\\").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-
-    // we're mixing Java escaping like \" and JavaScript escaping like \\\"
-    // which makes these tests extra tricky to read!
-    assertEquals("abc\"def", new JSONTokener("abc\\\"def\"ghi").nextString('"'));
-    assertEquals("abc\\def", new JSONTokener("abc\\\\def\"ghi").nextString('"'));
-    assertEquals("abc/def", new JSONTokener("abc\\/def\"ghi").nextString('"'));
-    assertEquals("abc\bdef", new JSONTokener("abc\\bdef\"ghi").nextString('"'));
-    assertEquals("abc\fdef", new JSONTokener("abc\\fdef\"ghi").nextString('"'));
-    assertEquals("abc\ndef", new JSONTokener("abc\\ndef\"ghi").nextString('"'));
-    assertEquals("abc\rdef", new JSONTokener("abc\\rdef\"ghi").nextString('"'));
-    assertEquals("abc\tdef", new JSONTokener("abc\\tdef\"ghi").nextString('"'));
-  }
-
-  public void testNextStringUnicodeEscaped() throws JSONException {
-    // we're mixing Java escaping like \\ and JavaScript escaping like \\u
-    assertEquals("abc def", new JSONTokener("abc\\u0020def\"ghi").nextString('"'));
-    assertEquals("abcU0020def", new JSONTokener("abc\\U0020def\"ghi").nextString('"'));
-
-    // JSON requires 4 hex characters after a unicode escape
-    try {
-      new JSONTokener("abc\\u002\"").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONTokener("abc\\u").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONTokener("abc\\u    \"").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals("abc\"def", new JSONTokener("abc\\u0022def\"ghi").nextString('"'));
-    try {
-      new JSONTokener("abc\\u000G\"").nextString('"');
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  public void testNextStringNonQuote() throws JSONException {
-    assertEquals("AB", new JSONTokener("ABC").nextString('C'));
-    assertEquals("ABCD", new JSONTokener("AB\\CDC").nextString('C'));
-    assertEquals("AB\nC", new JSONTokener("AB\\nCn").nextString('n'));
-  }
-
-  public void testNextTo() throws JSONException {
-    assertEquals("ABC", new JSONTokener("ABCDEFG").nextTo("DHI"));
-    assertEquals("ABCDEF", new JSONTokener("ABCDEF").nextTo(""));
-
-    JSONTokener tokener = new JSONTokener("ABC\rDEF\nGHI\r\nJKL");
-    assertEquals("ABC", tokener.nextTo("M"));
-    assertEquals('\r', tokener.next());
-    assertEquals("DEF", tokener.nextTo("M"));
-    assertEquals('\n', tokener.next());
-    assertEquals("GHI", tokener.nextTo("M"));
-    assertEquals('\r', tokener.next());
-    assertEquals('\n', tokener.next());
-    assertEquals("JKL", tokener.nextTo("M"));
-
-    tokener = new JSONTokener("ABCDEFGHI");
-    assertEquals("ABC", tokener.nextTo("DEF"));
-    assertEquals("", tokener.nextTo("DEF"));
-    assertEquals('D', tokener.next());
-    assertEquals("", tokener.nextTo("DEF"));
-    assertEquals('E', tokener.next());
-    assertEquals("", tokener.nextTo("DEF"));
-    assertEquals('F', tokener.next());
-    assertEquals("GHI", tokener.nextTo("DEF"));
-    assertEquals("", tokener.nextTo("DEF"));
-
-    tokener = new JSONTokener(" \t \fABC \t DEF");
-    assertEquals("ABC", tokener.nextTo("DEF"));
-    assertEquals('D', tokener.next());
-
-    tokener = new JSONTokener(" \t \fABC \n DEF");
-    assertEquals("ABC", tokener.nextTo("\n"));
-    assertEquals("", tokener.nextTo("\n"));
-
-    tokener = new JSONTokener("");
-    try {
-      tokener.nextTo(null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  public void testNextToTrimming() {
-    assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo("DE"));
-    assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo('D'));
-  }
-
-  public void testNextToTrailing() {
-    assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo("G"));
-    assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo('G'));
-  }
-
-  public void testNextToDoesntStopOnNull() {
-    String message = "nextTo() shouldn't stop after \\0 characters";
-    JSONTokener tokener = new JSONTokener(" \0\t \fABC \n DEF");
-    assertEquals(message, "ABC", tokener.nextTo("D"));
-    assertEquals(message, '\n', tokener.next());
-    assertEquals(message, "", tokener.nextTo("D"));
-  }
-
-  public void testNextToConsumesNull() {
-    String message = "nextTo shouldn't consume \\0.";
-    JSONTokener tokener = new JSONTokener("ABC\0DEF");
-    assertEquals(message, "ABC", tokener.nextTo("\0"));
-    assertEquals(message, '\0', tokener.next());
-    assertEquals(message, "DEF", tokener.nextTo("\0"));
-  }
-
-  public void testSkipPast() {
-    JSONTokener tokener = new JSONTokener("ABCDEF");
-    tokener.skipPast("ABC");
-    assertEquals('D', tokener.next());
-    tokener.skipPast("EF");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABCDEF");
-    tokener.skipPast("ABCDEF");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABCDEF");
-    tokener.skipPast("G");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABC\0ABC");
-    tokener.skipPast("ABC");
-    assertEquals('\0', tokener.next());
-    assertEquals('A', tokener.next());
-
-    tokener = new JSONTokener("\0ABC");
-    tokener.skipPast("ABC");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABC\nDEF");
-    tokener.skipPast("DEF");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABC");
-    tokener.skipPast("ABCDEF");
-    assertEquals('\0', tokener.next());
-
-    tokener = new JSONTokener("ABCDABCDABCD");
-    tokener.skipPast("ABC");
-    assertEquals('D', tokener.next());
-    tokener.skipPast("ABC");
-    assertEquals('D', tokener.next());
-    tokener.skipPast("ABC");
-    assertEquals('D', tokener.next());
-
-    tokener = new JSONTokener("");
-    try {
-      tokener.skipPast(null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  public void testSkipTo() {
-    JSONTokener tokener = new JSONTokener("ABCDEF");
-    tokener.skipTo('A');
-    assertEquals('A', tokener.next());
-    tokener.skipTo('D');
-    assertEquals('D', tokener.next());
-    tokener.skipTo('G');
-    assertEquals('E', tokener.next());
-    tokener.skipTo('A');
-    assertEquals('F', tokener.next());
-
-    tokener = new JSONTokener("ABC\nDEF");
-    tokener.skipTo('F');
-    assertEquals('F', tokener.next());
-
-    tokener = new JSONTokener("ABCfDEF");
-    tokener.skipTo('F');
-    assertEquals('F', tokener.next());
-
-    tokener = new JSONTokener("ABC/* DEF */");
-    tokener.skipTo('D');
-    assertEquals('D', tokener.next());
-  }
-
-  public void testSkipToStopsOnNull() {
-    JSONTokener tokener = new JSONTokener("ABC\0DEF");
-    tokener.skipTo('F');
-    assertEquals("skipTo shouldn't stop when it sees '\\0'", 'F', tokener.next());
-  }
-
-  public void testBomIgnoredAsFirstCharacterOfDocument() throws JSONException {
-    JSONTokener tokener = new JSONTokener("\ufeff[]");
-    JSONArray array = (JSONArray) tokener.nextValue();
-    assertEquals(0, array.length());
-  }
-
-  public void testBomTreatedAsCharacterInRestOfDocument() throws JSONException {
-    JSONTokener tokener = new JSONTokener("[\ufeff]");
-    JSONArray array = (JSONArray) tokener.nextValue();
-    assertEquals(1, array.length());
-  }
-
-  public void testDehexchar() {
-    assertEquals(0, JSONTokener.dehexchar('0'));
-    assertEquals(1, JSONTokener.dehexchar('1'));
-    assertEquals(2, JSONTokener.dehexchar('2'));
-    assertEquals(3, JSONTokener.dehexchar('3'));
-    assertEquals(4, JSONTokener.dehexchar('4'));
-    assertEquals(5, JSONTokener.dehexchar('5'));
-    assertEquals(6, JSONTokener.dehexchar('6'));
-    assertEquals(7, JSONTokener.dehexchar('7'));
-    assertEquals(8, JSONTokener.dehexchar('8'));
-    assertEquals(9, JSONTokener.dehexchar('9'));
-    assertEquals(10, JSONTokener.dehexchar('A'));
-    assertEquals(11, JSONTokener.dehexchar('B'));
-    assertEquals(12, JSONTokener.dehexchar('C'));
-    assertEquals(13, JSONTokener.dehexchar('D'));
-    assertEquals(14, JSONTokener.dehexchar('E'));
-    assertEquals(15, JSONTokener.dehexchar('F'));
-    assertEquals(10, JSONTokener.dehexchar('a'));
-    assertEquals(11, JSONTokener.dehexchar('b'));
-    assertEquals(12, JSONTokener.dehexchar('c'));
-    assertEquals(13, JSONTokener.dehexchar('d'));
-    assertEquals(14, JSONTokener.dehexchar('e'));
-    assertEquals(15, JSONTokener.dehexchar('f'));
-
-    for (int c = 0; c <= 0xFFFF; c++) {
-      if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
-        continue;
-      }
-      assertEquals("dehexchar " + c, -1, JSONTokener.dehexchar((char) c));
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/ParsingTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/ParsingTest.java b/geode-json/src/test/java/org/json/ParsingTest.java
deleted file mode 100755
index a49aba7..0000000
--- a/geode-json/src/test/java/org/json/ParsingTest.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import org.junit.Test;
-
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-public class ParsingTest {
-
-  @Test
-  public void testParsingNoObjects() {
-    try {
-      new JSONTokener("").nextValue();
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testParsingLiterals() throws JSONException {
-    assertParsed(Boolean.TRUE, "true");
-    assertParsed(Boolean.FALSE, "false");
-    assertParsed(JSONObject.NULL, "null");
-    assertParsed(JSONObject.NULL, "NULL");
-    assertParsed(Boolean.FALSE, "False");
-    assertParsed(Boolean.TRUE, "truE");
-  }
-
-  @Test
-  public void testParsingQuotedStrings() throws JSONException {
-    assertParsed("abc", "\"abc\"");
-    assertParsed("123", "\"123\"");
-    assertParsed("foo\nbar", "\"foo\\nbar\"");
-    assertParsed("foo bar", "\"foo\\u0020bar\"");
-    assertParsed("\"{}[]/\\:,=;#", "\"\\\"{}[]/\\\\:,=;#\"");
-  }
-
-  @Test
-  public void testParsingSingleQuotedStrings() throws JSONException {
-    assertParsed("abc", "'abc'");
-    assertParsed("123", "'123'");
-    assertParsed("foo\nbar", "'foo\\nbar'");
-    assertParsed("foo bar", "'foo\\u0020bar'");
-    assertParsed("\"{}[]/\\:,=;#", "'\\\"{}[]/\\\\:,=;#'");
-  }
-
-  @Test
-  public void testParsingUnquotedStrings() throws JSONException {
-    assertParsed("abc", "abc");
-    assertParsed("123abc", "123abc");
-    assertParsed("123e0x", "123e0x");
-    assertParsed("123e", "123e");
-    assertParsed("123ee21", "123ee21");
-    assertParsed("0xFFFFFFFFFFFFFFFFF", "0xFFFFFFFFFFFFFFFFF");
-  }
-
-  /**
-   * Unfortunately the original implementation attempts to figure out what Java number type best
-   * suits an input value.
-   */
-  @Test
-  public void testParsingNumbersThatAreBestRepresentedAsLongs() throws JSONException {
-    assertParsed(9223372036854775807L, "9223372036854775807");
-    assertParsed(9223372036854775806L, "9223372036854775806");
-    assertParsed(-9223372036854775808L, "-9223372036854775808");
-    assertParsed(-9223372036854775807L, "-9223372036854775807");
-  }
-
-  @Test
-  public void testParsingNumbersThatAreBestRepresentedAsIntegers() throws JSONException {
-    assertParsed(0, "0");
-    assertParsed(5, "5");
-    assertParsed(-2147483648, "-2147483648");
-    assertParsed(2147483647, "2147483647");
-  }
-
-  @Test
-  public void testParsingNegativeZero() throws JSONException {
-    assertParsed(0, "-0");
-  }
-
-  @Test
-  public void testParsingIntegersWithAdditionalPrecisionYieldDoubles() throws JSONException {
-    assertParsed(1d, "1.00");
-    assertParsed(1d, "1.0");
-    assertParsed(0d, "0.0");
-    assertParsed(-0d, "-0.0");
-  }
-
-  @Test
-  public void testParsingNumbersThatAreBestRepresentedAsDoubles() throws JSONException {
-    assertParsed(9.223372036854776E18, "9223372036854775808");
-    assertParsed(-9.223372036854776E18, "-9223372036854775809");
-    assertParsed(1.7976931348623157E308, "1.7976931348623157e308");
-    assertParsed(2.2250738585072014E-308, "2.2250738585072014E-308");
-    assertParsed(4.9E-324, "4.9E-324");
-    assertParsed(4.9E-324, "4.9e-324");
-  }
-
-  @Test
-  public void testParsingOctalNumbers() throws JSONException {
-    assertParsed(5, "05");
-    assertParsed(8, "010");
-    assertParsed(1046, "02026");
-  }
-
-  @Test
-  public void testParsingHexNumbers() throws JSONException {
-    assertParsed(5, "0x5");
-    assertParsed(16, "0x10");
-    assertParsed(8230, "0x2026");
-    assertParsed(180150010, "0xABCDEFA");
-    assertParsed(2077093803, "0x7BCDEFAB");
-  }
-
-  @Test
-  public void testParsingLargeHexValues() throws JSONException {
-    assertParsed(Integer.MAX_VALUE, "0x7FFFFFFF");
-    String message = "Hex values are parsed as Strings if their signed "
-        + "value is greater than Integer.MAX_VALUE.";
-    assertParsed(message, 0x80000000L, "0x80000000");
-  }
-
-  @Test
-  public void test64BitHexValues() throws JSONException {
-    // note that this is different from the same test in the original Android
-    // this is due to the fact that Long.parseLong doesn't correctly handle
-    // the value -1 expressed as unsigned hex if you use the normal JDK. Presumably
-    // the Android equivalent program does this better.
-    assertParsed("Large hex longs shouldn't yield ints or strings", 0xFFFFFFFFFFFFFFFL,
-        "0xFFFFFFFFFFFFFFF");
-  }
-
-  @Test
-  public void testParsingWithCommentsAndWhitespace() throws JSONException {
-    assertParsed("baz", "  // foo bar \n baz");
-    assertParsed("baz", "  // foo bar \r baz");
-    assertParsed("baz", "  // foo bar \r\n baz");
-    assertParsed("baz", "  # foo bar \n baz");
-    assertParsed("baz", "  # foo bar \r baz");
-    assertParsed("baz", "  # foo bar \r\n baz");
-    assertParsed(5, "  /* foo bar \n baz */ 5");
-    assertParsed(5, "  /* foo bar \n baz */ 5 // quux");
-    assertParsed(5, "  5   ");
-    assertParsed(5, "  5  \r\n\t ");
-    assertParsed(5, "\r\n\t   5 ");
-  }
-
-  @Test
-  public void testParsingArrays() throws JSONException {
-    assertParsed(array(), "[]");
-    assertParsed(array(5, 6, true), "[5,6,true]");
-    assertParsed(array(5, 6, array()), "[5,6,[]]");
-    assertParsed(array(5, 6, 7), "[5;6;7]");
-    assertParsed(array(5, 6, 7), "[5  , 6 \t; \r\n 7\n]");
-    assertParsed(array(5, 6, 7, null), "[5,6,7,]");
-    assertParsed(array(null, null), "[,]");
-    assertParsed(array(5, null, null, null, 5), "[5,,,,5]");
-    assertParsed(array(null, 5), "[,5]");
-    assertParsed(array(null, null, null), "[,,]");
-    assertParsed(array(null, null, null, 5), "[,,,5]");
-  }
-
-  @Test
-  public void testParsingObjects() throws JSONException {
-    assertParsed(object("foo", 5), "{\"foo\": 5}");
-    assertParsed(object("foo", 5), "{foo: 5}");
-    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5, \"bar\": \"baz\"}");
-    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5; \"bar\": \"baz\"}");
-    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"= 5; \"bar\"= \"baz\"}");
-    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"=> 5; \"bar\"=> \"baz\"}");
-    assertParsed(object("foo", object(), "bar", array()), "{\"foo\"=> {}; \"bar\"=> []}");
-    assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\": {\"foo\": [5, 6]}}");
-    assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\":\n\t{\t \"foo\":[5,\r6]}}");
-  }
-
-  @Test
-  public void testSyntaxProblemUnterminatedObject() {
-    assertParseFail("{");
-    assertParseFail("{\"foo\"");
-    assertParseFail("{\"foo\":");
-    assertParseFail("{\"foo\":bar");
-    assertParseFail("{\"foo\":bar,");
-    assertParseFail("{\"foo\":bar,\"baz\"");
-    assertParseFail("{\"foo\":bar,\"baz\":");
-    assertParseFail("{\"foo\":bar,\"baz\":true");
-    assertParseFail("{\"foo\":bar,\"baz\":true,");
-  }
-
-  @Test
-  public void testSyntaxProblemEmptyString() {
-    assertParseFail("");
-  }
-
-  @Test
-  public void testSyntaxProblemUnterminatedArray() {
-    assertParseFail("[");
-    assertParseFail("[,");
-    assertParseFail("[,,");
-    assertParseFail("[true");
-    assertParseFail("[true,");
-    assertParseFail("[true,,");
-  }
-
-  @Test
-  public void testSyntaxProblemMalformedObject() {
-    assertParseFail("{:}");
-    assertParseFail("{\"key\":}");
-    assertParseFail("{:true}");
-    assertParseFail("{\"key\":true:}");
-    assertParseFail("{null:true}");
-    assertParseFail("{true:true}");
-    assertParseFail("{0xFF:true}");
-  }
-
-  private void assertParseFail(String malformedJson) {
-    try {
-      new JSONTokener(malformedJson).nextValue();
-      fail("Successfully parsed: \"" + malformedJson + "\"");
-    } catch (JSONException ignored) {
-    } catch (StackOverflowError e) {
-      fail("Stack overflowed on input: \"" + malformedJson + "\"");
-    }
-  }
-
-  private JSONArray array(Object... elements) {
-    return new JSONArray(Arrays.asList(elements));
-  }
-
-  private JSONObject object(Object... keyValuePairs) throws JSONException {
-    JSONObject result = new JSONObject();
-    for (int i = 0; i < keyValuePairs.length; i += 2) {
-      result.put((String) keyValuePairs[i], keyValuePairs[i + 1]);
-    }
-    return result;
-  }
-
-  private void assertParsed(String message, Object expected, String json) throws JSONException {
-    Object actual = new JSONTokener(json).nextValue();
-    actual = canonicalize(actual);
-    expected = canonicalize(expected);
-    assertEquals("For input \"" + json + "\" " + message, expected, actual);
-  }
-
-  private void assertParsed(Object expected, String json) throws JSONException {
-    assertParsed("", expected, json);
-  }
-
-  /**
-   * Since they don't implement equals or hashCode properly, this recursively replaces JSONObjects
-   * with an equivalent HashMap, and JSONArrays with the equivalent ArrayList.
-   */
-  private Object canonicalize(Object input) throws JSONException {
-    if (input instanceof JSONArray) {
-      JSONArray array = (JSONArray) input;
-      List<Object> result = new ArrayList<Object>();
-      for (int i = 0; i < array.length(); i++) {
-        result.add(canonicalize(array.opt(i)));
-      }
-      return result;
-    } else if (input instanceof JSONObject) {
-      JSONObject object = (JSONObject) input;
-      Map<String, Object> result = new HashMap<String, Object>();
-      for (Iterator<?> i = object.keys(); i.hasNext();) {
-        String key = (String) i.next();
-        result.put(key, canonicalize(object.get(key)));
-      }
-      return result;
-    } else if (input == null || input.equals(JSONObject.NULL)) {
-      return JSONObject.NULL;
-    } else {
-      return input;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/SelfUseTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/SelfUseTest.java b/geode-json/src/test/java/org/json/SelfUseTest.java
deleted file mode 100755
index 78ee678..0000000
--- a/geode-json/src/test/java/org/json/SelfUseTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * These tests checks self use calls. For the most part we doesn't attempt to cover self-use, except
- * in those cases where our clean room implementation does it.
- * <p>
- * <p>
- * This black box test was written without inspecting the non-free org.json sourcecode.
- */
-public class SelfUseTest {
-
-  private int objectPutCalls = 0;
-  private int objectGetCalls = 0;
-  private int objectOptCalls = 0;
-  private int objectOptTypeCalls = 0;
-  private int arrayPutCalls = 0;
-  private int arrayGetCalls = 0;
-  private int arrayOptCalls = 0;
-  private int arrayOptTypeCalls = 0;
-  private int tokenerNextCalls = 0;
-  private int tokenerNextValueCalls = 0;
-
-  private final JSONObject object = new JSONObject() {
-    @Override
-    public JSONObject put(String name, Object value) throws JSONException {
-      objectPutCalls++;
-      return super.put(name, value);
-    }
-
-    @Override
-    public Object get(String name) throws JSONException {
-      objectGetCalls++;
-      return super.get(name);
-    }
-
-    @Override
-    public Object opt(String name) {
-      objectOptCalls++;
-      return super.opt(name);
-    }
-
-    @Override
-    public boolean optBoolean(String key, boolean defaultValue) {
-      objectOptTypeCalls++;
-      return super.optBoolean(key, defaultValue);
-    }
-
-    @Override
-    public double optDouble(String key, double defaultValue) {
-      objectOptTypeCalls++;
-      return super.optDouble(key, defaultValue);
-    }
-
-    @Override
-    public int optInt(String key, int defaultValue) {
-      objectOptTypeCalls++;
-      return super.optInt(key, defaultValue);
-    }
-
-    @Override
-    public long optLong(String key, long defaultValue) {
-      objectOptTypeCalls++;
-      return super.optLong(key, defaultValue);
-    }
-
-    @Override
-    public String optString(String key, String defaultValue) {
-      objectOptTypeCalls++;
-      return super.optString(key, defaultValue);
-    }
-  };
-
-  private final JSONArray array = new JSONArray() {
-    @Override
-    public JSONArray put(int index, Object value) throws JSONException {
-      arrayPutCalls++;
-      return super.put(index, value);
-    }
-
-    @Override
-    public Object get(int index) throws JSONException {
-      arrayGetCalls++;
-      return super.get(index);
-    }
-
-    @Override
-    public Object opt(int index) {
-      arrayOptCalls++;
-      return super.opt(index);
-    }
-
-    @Override
-    public boolean optBoolean(int index, boolean fallback) {
-      arrayOptTypeCalls++;
-      return super.optBoolean(index, fallback);
-    }
-
-    @Override
-    public double optDouble(int index, double fallback) {
-      arrayOptTypeCalls++;
-      return super.optDouble(index, fallback);
-    }
-
-    @Override
-    public long optLong(int index, long fallback) {
-      arrayOptTypeCalls++;
-      return super.optLong(index, fallback);
-    }
-
-    @Override
-    public String optString(int index, String fallback) {
-      arrayOptTypeCalls++;
-      return super.optString(index, fallback);
-    }
-
-    @Override
-    public int optInt(int index, int fallback) {
-      arrayOptTypeCalls++;
-      return super.optInt(index, fallback);
-    }
-  };
-
-  private final JSONTokener tokener = new JSONTokener("{\"foo\": [true]}") {
-    @Override
-    public char next() {
-      tokenerNextCalls++;
-      return super.next();
-    }
-
-    @Override
-    public Object nextValue() throws JSONException {
-      tokenerNextValueCalls++;
-      return super.nextValue();
-    }
-  };
-
-
-  @Test
-  public void testObjectPut() throws JSONException {
-    object.putOpt("foo", "bar");
-    assertEquals(1, objectPutCalls);
-  }
-
-  @Test
-  public void testObjectAccumulate() throws JSONException {
-    object.accumulate("foo", "bar");
-    assertEquals(1, objectPutCalls);
-  }
-
-  @Test
-  public void testObjectGetBoolean() throws JSONException {
-    object.put("foo", "true");
-    object.getBoolean("foo");
-    assertEquals(1, objectGetCalls);
-  }
-
-  @Test
-  public void testObjectOptType() throws JSONException {
-    object.optBoolean("foo");
-    assertEquals(1, objectOptCalls);
-    assertEquals(1, objectOptTypeCalls);
-    object.optDouble("foo");
-    assertEquals(2, objectOptCalls);
-    assertEquals(2, objectOptTypeCalls);
-    object.optInt("foo");
-    assertEquals(3, objectOptCalls);
-    assertEquals(3, objectOptTypeCalls);
-    object.optLong("foo");
-    assertEquals(4, objectOptCalls);
-    assertEquals(4, objectOptTypeCalls);
-    object.optString("foo");
-    assertEquals(5, objectOptCalls);
-    assertEquals(5, objectOptTypeCalls);
-  }
-
-  @Test
-  public void testToJSONArray() throws JSONException {
-    object.put("foo", 5);
-    object.put("bar", 10);
-    array.put("foo");
-    array.put("baz");
-    array.put("bar");
-    object.toJSONArray(array);
-    assertEquals(3, arrayOptCalls);
-    assertEquals(0, arrayOptTypeCalls);
-    assertEquals(3, objectOptCalls);
-    assertEquals(0, objectOptTypeCalls);
-  }
-
-  @Test
-  public void testPutAtIndex() throws JSONException {
-    array.put(10, false);
-    assertEquals(1, arrayPutCalls);
-  }
-
-  @Test
-  public void testIsNull() {
-    array.isNull(5);
-    assertEquals(1, arrayOptCalls);
-  }
-
-  @Test
-  public void testArrayGetType() throws JSONException {
-    array.put(true);
-    array.getBoolean(0);
-    assertEquals(1, arrayGetCalls);
-  }
-
-  @Test
-  public void testArrayOptType() throws JSONException {
-    array.optBoolean(3);
-    assertEquals(1, arrayOptCalls);
-    assertEquals(1, arrayOptTypeCalls);
-    array.optDouble(3);
-    assertEquals(2, arrayOptCalls);
-    assertEquals(2, arrayOptTypeCalls);
-    array.optInt(3);
-    assertEquals(3, arrayOptCalls);
-    assertEquals(3, arrayOptTypeCalls);
-    array.optLong(3);
-    assertEquals(4, arrayOptCalls);
-    assertEquals(4, arrayOptTypeCalls);
-    array.optString(3);
-    assertEquals(5, arrayOptCalls);
-    assertEquals(5, arrayOptTypeCalls);
-  }
-
-  @Test
-  public void testToJSONObject() throws JSONException {
-    array.put("foo");
-    array.put("baz");
-    array.put("bar");
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    values.put(11d);
-    values.put(30);
-    values.toJSONObject(array);
-    assertEquals(3, arrayOptCalls);
-    assertEquals(0, arrayOptTypeCalls);
-  }
-
-  @Test
-  public void testNextExpecting() throws JSONException {
-    tokener.next('{');
-    assertEquals(1, tokenerNextCalls);
-    tokener.next('\"');
-    assertEquals(2, tokenerNextCalls);
-  }
-
-  @Test
-  public void testNextValue() throws JSONException {
-    tokener.nextValue();
-    assertEquals(4, tokenerNextValueCalls);
-  }
-}


[08/34] geode git commit: GEODE-2142: Removal of offending JSON.ORG code and license information

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/XML.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/XML.java b/geode-json/src/main/java/org/json/XML.java
deleted file mode 100755
index ae6d61a..0000000
--- a/geode-json/src/main/java/org/json/XML.java
+++ /dev/null
@@ -1,504 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.util.Iterator;
-
-
-/**
- * This provides static methods to convert an XML text into a JSONObject, and to covert a JSONObject
- * into an XML text.
- * 
- * @author JSON.org
- * @version 2011-02-11
- */
-public class XML {
-
-  /** The Character '&'. */
-  public static final Character AMP = new Character('&');
-
-  /** The Character '''. */
-  public static final Character APOS = new Character('\'');
-
-  /** The Character '!'. */
-  public static final Character BANG = new Character('!');
-
-  /** The Character '='. */
-  public static final Character EQ = new Character('=');
-
-  /** The Character '>'. */
-  public static final Character GT = new Character('>');
-
-  /** The Character '<'. */
-  public static final Character LT = new Character('<');
-
-  /** The Character '?'. */
-  public static final Character QUEST = new Character('?');
-
-  /** The Character '"'. */
-  public static final Character QUOT = new Character('"');
-
-  /** The Character '/'. */
-  public static final Character SLASH = new Character('/');
-
-  /**
-   * Replace special characters with XML escapes:
-   * 
-   * <pre>
-   * &amp; <small>(ampersand)</small> is replaced by &amp;amp;
-   * &lt; <small>(less than)</small> is replaced by &amp;lt;
-   * &gt; <small>(greater than)</small> is replaced by &amp;gt;
-   * &quot; <small>(double quote)</small> is replaced by &amp;quot;
-   * </pre>
-   * 
-   * @param string The string to be escaped.
-   * @return The escaped string.
-   */
-  public static String escape(String string) {
-    StringBuffer sb = new StringBuffer();
-    for (int i = 0, length = string.length(); i < length; i++) {
-      char c = string.charAt(i);
-      switch (c) {
-        case '&':
-          sb.append("&amp;");
-          break;
-        case '<':
-          sb.append("&lt;");
-          break;
-        case '>':
-          sb.append("&gt;");
-          break;
-        case '"':
-          sb.append("&quot;");
-          break;
-        case '\'':
-          sb.append("&apos;");
-          break;
-        default:
-          sb.append(c);
-      }
-    }
-    return sb.toString();
-  }
-
-  /**
-   * Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and
-   * attributes.
-   * 
-   * @param string
-   * @throws JSONException
-   */
-  public static void noSpace(String string) throws JSONException {
-    int i, length = string.length();
-    if (length == 0) {
-      throw new JSONException("Empty string.");
-    }
-    for (i = 0; i < length; i += 1) {
-      if (Character.isWhitespace(string.charAt(i))) {
-        throw new JSONException("'" + string + "' contains a space character.");
-      }
-    }
-  }
-
-  /**
-   * Scan the content following the named tag, attaching it to the context.
-   * 
-   * @param x The XMLTokener containing the source string.
-   * @param context The JSONObject that will include the new material.
-   * @param name The tag name.
-   * @return true if the close tag is processed.
-   * @throws JSONException
-   */
-  private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
-    char c;
-    int i;
-    JSONObject jsonobject = null;
-    String string;
-    String tagName;
-    Object token;
-
-    // Test for and skip past these forms:
-    // <!-- ... -->
-    // <! ... >
-    // <![ ... ]]>
-    // <? ... ?>
-    // Report errors for these forms:
-    // <>
-    // <=
-    // <<
-
-    token = x.nextToken();
-
-    // <!
-
-    if (token == BANG) {
-      c = x.next();
-      if (c == '-') {
-        if (x.next() == '-') {
-          x.skipPast("-->");
-          return false;
-        }
-        x.back();
-      } else if (c == '[') {
-        token = x.nextToken();
-        if ("CDATA".equals(token)) {
-          if (x.next() == '[') {
-            string = x.nextCDATA();
-            if (string.length() > 0) {
-              context.accumulate("content", string);
-            }
-            return false;
-          }
-        }
-        throw x.syntaxError("Expected 'CDATA['");
-      }
-      i = 1;
-      do {
-        token = x.nextMeta();
-        if (token == null) {
-          throw x.syntaxError("Missing '>' after '<!'.");
-        } else if (token == LT) {
-          i += 1;
-        } else if (token == GT) {
-          i -= 1;
-        }
-      } while (i > 0);
-      return false;
-    } else if (token == QUEST) {
-
-      // <?
-
-      x.skipPast("?>");
-      return false;
-    } else if (token == SLASH) {
-
-      // Close tag </
-
-      token = x.nextToken();
-      if (name == null) {
-        throw x.syntaxError("Mismatched close tag " + token);
-      }
-      if (!token.equals(name)) {
-        throw x.syntaxError("Mismatched " + name + " and " + token);
-      }
-      if (x.nextToken() != GT) {
-        throw x.syntaxError("Misshaped close tag");
-      }
-      return true;
-
-    } else if (token instanceof Character) {
-      throw x.syntaxError("Misshaped tag");
-
-      // Open tag <
-
-    } else {
-      tagName = (String) token;
-      token = null;
-      jsonobject = new JSONObject();
-      for (;;) {
-        if (token == null) {
-          token = x.nextToken();
-        }
-
-        // attribute = value
-
-        if (token instanceof String) {
-          string = (String) token;
-          token = x.nextToken();
-          if (token == EQ) {
-            token = x.nextToken();
-            if (!(token instanceof String)) {
-              throw x.syntaxError("Missing value");
-            }
-            jsonobject.accumulate(string, XML.stringToValue((String) token));
-            token = null;
-          } else {
-            jsonobject.accumulate(string, "");
-          }
-
-          // Empty tag <.../>
-
-        } else if (token == SLASH) {
-          if (x.nextToken() != GT) {
-            throw x.syntaxError("Misshaped tag");
-          }
-          if (jsonobject.length() > 0) {
-            context.accumulate(tagName, jsonobject);
-          } else {
-            context.accumulate(tagName, "");
-          }
-          return false;
-
-          // Content, between <...> and </...>
-
-        } else if (token == GT) {
-          for (;;) {
-            token = x.nextContent();
-            if (token == null) {
-              if (tagName != null) {
-                throw x.syntaxError("Unclosed tag " + tagName);
-              }
-              return false;
-            } else if (token instanceof String) {
-              string = (String) token;
-              if (string.length() > 0) {
-                jsonobject.accumulate("content", XML.stringToValue(string));
-              }
-
-              // Nested element
-
-            } else if (token == LT) {
-              if (parse(x, jsonobject, tagName)) {
-                if (jsonobject.length() == 0) {
-                  context.accumulate(tagName, "");
-                } else if (jsonobject.length() == 1 && jsonobject.opt("content") != null) {
-                  context.accumulate(tagName, jsonobject.opt("content"));
-                } else {
-                  context.accumulate(tagName, jsonobject);
-                }
-                return false;
-              }
-            }
-          }
-        } else {
-          throw x.syntaxError("Misshaped tag");
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Try to convert a string into a number, boolean, or null. If the string can't be converted,
-   * return the string. This is much less ambitious than JSONObject.stringToValue, especially
-   * because it does not attempt to convert plus forms, octal forms, hex forms, or E forms lacking
-   * decimal points.
-   * 
-   * @param string A String.
-   * @return A simple JSON value.
-   */
-  public static Object stringToValue(String string) {
-    if ("".equals(string)) {
-      return string;
-    }
-    if ("true".equalsIgnoreCase(string)) {
-      return Boolean.TRUE;
-    }
-    if ("false".equalsIgnoreCase(string)) {
-      return Boolean.FALSE;
-    }
-    if ("null".equalsIgnoreCase(string)) {
-      return JSONObject.NULL;
-    }
-    if ("0".equals(string)) {
-      return new Integer(0);
-    }
-
-    // If it might be a number, try converting it. If that doesn't work,
-    // return the string.
-
-    try {
-      char initial = string.charAt(0);
-      boolean negative = false;
-      if (initial == '-') {
-        initial = string.charAt(1);
-        negative = true;
-      }
-      if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') {
-        return string;
-      }
-      if ((initial >= '0' && initial <= '9')) {
-        if (string.indexOf('.') >= 0) {
-          return Double.valueOf(string);
-        } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {
-          Long myLong = new Long(string);
-          if (myLong.longValue() == myLong.intValue()) {
-            return new Integer(myLong.intValue());
-          } else {
-            return myLong;
-          }
-        }
-      }
-    } catch (Exception ignore) {
-    }
-    return string;
-  }
-
-
-  /**
-   * Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some
-   * information may be lost in this transformation because JSON is a data format and XML is a
-   * document format. XML uses elements, attributes, and content text, while JSON uses unordered
-   * collections of name/value pairs and arrays of values. JSON does not does not like to
-   * distinguish between elements and attributes. Sequences of similar elements are represented as
-   * JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and
-   * <code>&lt;[ [ ]]></code> are ignored.
-   * 
-   * @param string The source string.
-   * @return A JSONObject containing the structured data from the XML string.
-   * @throws JSONException
-   */
-  public static JSONObject toJSONObject(String string) throws JSONException {
-    JSONObject jo = new JSONObject();
-    XMLTokener x = new XMLTokener(string);
-    while (x.more() && x.skipPast("<")) {
-      parse(x, jo, null);
-    }
-    return jo;
-  }
-
-
-  /**
-   * Convert a JSONObject into a well-formed, element-normal XML string.
-   * 
-   * @param object A JSONObject.
-   * @return A string.
-   * @throws JSONException
-   */
-  public static String toString(Object object) throws JSONException {
-    return toString(object, null);
-  }
-
-
-  /**
-   * Convert a JSONObject into a well-formed, element-normal XML string.
-   * 
-   * @param object A JSONObject.
-   * @param tagName The optional name of the enclosing tag.
-   * @return A string.
-   * @throws JSONException
-   */
-  public static String toString(Object object, String tagName) throws JSONException {
-    StringBuffer sb = new StringBuffer();
-    int i;
-    JSONArray ja;
-    JSONObject jo;
-    String key;
-    Iterator keys;
-    int length;
-    String string;
-    Object value;
-    if (object instanceof JSONObject) {
-
-      // Emit <tagName>
-
-      if (tagName != null) {
-        sb.append('<');
-        sb.append(tagName);
-        sb.append('>');
-      }
-
-      // Loop thru the keys.
-
-      jo = (JSONObject) object;
-      keys = jo.keys();
-      while (keys.hasNext()) {
-        key = keys.next().toString();
-        value = jo.opt(key);
-        if (value == null) {
-          value = "";
-        }
-        if (value instanceof String) {
-          string = (String) value;
-        } else {
-          string = null;
-        }
-
-        // Emit content in body
-
-        if ("content".equals(key)) {
-          if (value instanceof JSONArray) {
-            ja = (JSONArray) value;
-            length = ja.length();
-            for (i = 0; i < length; i += 1) {
-              if (i > 0) {
-                sb.append('\n');
-              }
-              sb.append(escape(ja.get(i).toString()));
-            }
-          } else {
-            sb.append(escape(value.toString()));
-          }
-
-          // Emit an array of similar keys
-
-        } else if (value instanceof JSONArray) {
-          ja = (JSONArray) value;
-          length = ja.length();
-          for (i = 0; i < length; i += 1) {
-            value = ja.get(i);
-            if (value instanceof JSONArray) {
-              sb.append('<');
-              sb.append(key);
-              sb.append('>');
-              sb.append(toString(value));
-              sb.append("</");
-              sb.append(key);
-              sb.append('>');
-            } else {
-              sb.append(toString(value, key));
-            }
-          }
-        } else if ("".equals(value)) {
-          sb.append('<');
-          sb.append(key);
-          sb.append("/>");
-
-          // Emit a new tag <k>
-
-        } else {
-          sb.append(toString(value, key));
-        }
-      }
-      if (tagName != null) {
-
-        // Emit the </tagname> close tag
-
-        sb.append("</");
-        sb.append(tagName);
-        sb.append('>');
-      }
-      return sb.toString();
-
-      // XML does not have good support for arrays. If an array appears in a place
-      // where XML is lacking, synthesize an <array> element.
-
-    } else {
-      if (object.getClass().isArray()) {
-        object = new JSONArray(object);
-      }
-      if (object instanceof JSONArray) {
-        ja = (JSONArray) object;
-        length = ja.length();
-        for (i = 0; i < length; i += 1) {
-          sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
-        }
-        return sb.toString();
-      } else {
-        string = (object == null) ? "null" : escape(object.toString());
-        return (tagName == null) ? "\"" + string + "\""
-            : (string.length() == 0) ? "<" + tagName + "/>"
-                : "<" + tagName + ">" + string + "</" + tagName + ">";
-      }
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/XMLTokener.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/XMLTokener.java b/geode-json/src/main/java/org/json/XMLTokener.java
deleted file mode 100755
index f56a1f6..0000000
--- a/geode-json/src/main/java/org/json/XMLTokener.java
+++ /dev/null
@@ -1,362 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * The XMLTokener extends the JSONTokener to provide additional methods for the parsing of XML
- * texts.
- * 
- * @author JSON.org
- * @version 2010-12-24
- */
-public class XMLTokener extends JSONTokener {
-
-
-  /**
-   * The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
-   */
-  public static final java.util.HashMap entity;
-
-  static {
-    entity = new java.util.HashMap(8);
-    entity.put("amp", XML.AMP);
-    entity.put("apos", XML.APOS);
-    entity.put("gt", XML.GT);
-    entity.put("lt", XML.LT);
-    entity.put("quot", XML.QUOT);
-  }
-
-  /**
-   * Construct an XMLTokener from a string.
-   * 
-   * @param s A source string.
-   */
-  public XMLTokener(String s) {
-    super(s);
-  }
-
-  /**
-   * Get the text in the CDATA block.
-   * 
-   * @return The string up to the <code>]]&gt;</code>.
-   * @throws JSONException If the <code>]]&gt;</code> is not found.
-   */
-  public String nextCDATA() throws JSONException {
-    char c;
-    int i;
-    StringBuffer sb = new StringBuffer();
-    for (;;) {
-      c = next();
-      if (end()) {
-        throw syntaxError("Unclosed CDATA");
-      }
-      sb.append(c);
-      i = sb.length() - 3;
-      if (i >= 0 && sb.charAt(i) == ']' && sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') {
-        sb.setLength(i);
-        return sb.toString();
-      }
-    }
-  }
-
-
-  /**
-   * Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<'
-   * character which begins a markup tag, and the content text between markup tags.
-   *
-   * @return A string, or a '<' Character, or null if there is no more source text.
-   * @throws JSONException
-   */
-  public Object nextContent() throws JSONException {
-    char c;
-    StringBuffer sb;
-    do {
-      c = next();
-    } while (Character.isWhitespace(c));
-    if (c == 0) {
-      return null;
-    }
-    if (c == '<') {
-      return XML.LT;
-    }
-    sb = new StringBuffer();
-    for (;;) {
-      if (c == '<' || c == 0) {
-        back();
-        return sb.toString().trim();
-      }
-      if (c == '&') {
-        sb.append(nextEntity(c));
-      } else {
-        sb.append(c);
-      }
-      c = next();
-    }
-  }
-
-
-  /**
-   * Return the next entity. These entities are translated to Characters:
-   * <code>&amp;  &apos;  &gt;  &lt;  &quot;</code>.
-   * 
-   * @param ampersand An ampersand character.
-   * @return A Character or an entity String if the entity is not recognized.
-   * @throws JSONException If missing ';' in XML entity.
-   */
-  public Object nextEntity(char ampersand) throws JSONException {
-    StringBuffer sb = new StringBuffer();
-    for (;;) {
-      char c = next();
-      if (Character.isLetterOrDigit(c) || c == '#') {
-        sb.append(Character.toLowerCase(c));
-      } else if (c == ';') {
-        break;
-      } else {
-        throw syntaxError("Missing ';' in XML entity: &" + sb);
-      }
-    }
-    String string = sb.toString();
-    Object object = entity.get(string);
-    return object != null ? object : ampersand + string + ";";
-  }
-
-
-  /**
-   * Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.
-   * 
-   * @return Syntax characters (<code>< > / = ! ?</code>) are returned as Character, and strings and
-   *         names are returned as Boolean. We don't care what the values actually are.
-   * @throws JSONException If a string is not properly closed or if the XML is badly structured.
-   */
-  public Object nextMeta() throws JSONException {
-    char c;
-    char q;
-    do {
-      c = next();
-    } while (Character.isWhitespace(c));
-    switch (c) {
-      case 0:
-        throw syntaxError("Misshaped meta tag");
-      case '<':
-        return XML.LT;
-      case '>':
-        return XML.GT;
-      case '/':
-        return XML.SLASH;
-      case '=':
-        return XML.EQ;
-      case '!':
-        return XML.BANG;
-      case '?':
-        return XML.QUEST;
-      case '"':
-      case '\'':
-        q = c;
-        for (;;) {
-          c = next();
-          if (c == 0) {
-            throw syntaxError("Unterminated string");
-          }
-          if (c == q) {
-            return Boolean.TRUE;
-          }
-        }
-      default:
-        for (;;) {
-          c = next();
-          if (Character.isWhitespace(c)) {
-            return Boolean.TRUE;
-          }
-          switch (c) {
-            case 0:
-            case '<':
-            case '>':
-            case '/':
-            case '=':
-            case '!':
-            case '?':
-            case '"':
-            case '\'':
-              back();
-              return Boolean.TRUE;
-          }
-        }
-    }
-  }
-
-
-  /**
-   * Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these
-   * characters: <code>/ > = ! ?</code> or it may be a string wrapped in single quotes or double
-   * quotes, or it may be a name.
-   * 
-   * @return a String or a Character.
-   * @throws JSONException If the XML is not well formed.
-   */
-  public Object nextToken() throws JSONException {
-    char c;
-    char q;
-    StringBuffer sb;
-    do {
-      c = next();
-    } while (Character.isWhitespace(c));
-    switch (c) {
-      case 0:
-        throw syntaxError("Misshaped element");
-      case '<':
-        throw syntaxError("Misplaced '<'");
-      case '>':
-        return XML.GT;
-      case '/':
-        return XML.SLASH;
-      case '=':
-        return XML.EQ;
-      case '!':
-        return XML.BANG;
-      case '?':
-        return XML.QUEST;
-
-      // Quoted string
-
-      case '"':
-      case '\'':
-        q = c;
-        sb = new StringBuffer();
-        for (;;) {
-          c = next();
-          if (c == 0) {
-            throw syntaxError("Unterminated string");
-          }
-          if (c == q) {
-            return sb.toString();
-          }
-          if (c == '&') {
-            sb.append(nextEntity(c));
-          } else {
-            sb.append(c);
-          }
-        }
-      default:
-
-        // Name
-
-        sb = new StringBuffer();
-        for (;;) {
-          sb.append(c);
-          c = next();
-          if (Character.isWhitespace(c)) {
-            return sb.toString();
-          }
-          switch (c) {
-            case 0:
-              return sb.toString();
-            case '>':
-            case '/':
-            case '=':
-            case '!':
-            case '?':
-            case '[':
-            case ']':
-              back();
-              return sb.toString();
-            case '<':
-            case '"':
-            case '\'':
-              throw syntaxError("Bad character in a name");
-          }
-        }
-    }
-  }
-
-
-  /**
-   * Skip characters until past the requested string. If it is not found, we are left at the end of
-   * the source with a result of false.
-   * 
-   * @param to A string to skip past.
-   * @throws JSONException
-   */
-  public boolean skipPast(String to) throws JSONException {
-    boolean b;
-    char c;
-    int i;
-    int j;
-    int offset = 0;
-    int length = to.length();
-    char[] circle = new char[length];
-
-    /*
-     * First fill the circle buffer with as many characters as are in the to string. If we reach an
-     * early end, bail.
-     */
-
-    for (i = 0; i < length; i += 1) {
-      c = next();
-      if (c == 0) {
-        return false;
-      }
-      circle[i] = c;
-    }
-    /*
-     * We will loop, possibly for all of the remaining characters.
-     */
-    for (;;) {
-      j = offset;
-      b = true;
-      /*
-       * Compare the circle buffer with the to string.
-       */
-      for (i = 0; i < length; i += 1) {
-        if (circle[j] != to.charAt(i)) {
-          b = false;
-          break;
-        }
-        j += 1;
-        if (j >= length) {
-          j -= length;
-        }
-      }
-      /*
-       * If we exit the loop with b intact, then victory is ours.
-       */
-      if (b) {
-        return true;
-      }
-      /*
-       * Get the next character. If there isn't one, then defeat is ours.
-       */
-      c = next();
-      if (c == 0) {
-        return false;
-      }
-      /*
-       * Shove the character in the circle buffer and advance the circle offset. The offset is mod
-       * n.
-       */
-      circle[offset] = c;
-      offset += 1;
-      if (offset >= length) {
-        offset -= length;
-      }
-    }
-  }
-}


[20/34] geode git commit: GEODE-2142: final compiling build

Posted by kl...@apache.org.
GEODE-2142: final compiling build


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/e220d099
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/e220d099
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/e220d099

Branch: refs/heads/GEODE-4160-mockito
Commit: e220d0992bd18a40bf209294cf1cb02106af21d5
Parents: cd58f1f
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 16:45:21 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 .../internal/cli/result/ResultBuilder.java      | 30 --------------------
 geode-json/build.gradle                         |  1 +
 2 files changed, 1 insertion(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/e220d099/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
index 06060a4..9bd2bf9 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java
@@ -301,12 +301,6 @@ public class ResultBuilder {
         }
 
         @Override
-        public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-            boolean addTimeStampToName) throws FileNotFoundException, IOException {
-          throw new UnsupportedOperationException("This is read only result data");
-        }
-
-        @Override
         public TabularResultData accumulate(String accumulateFor, Object value) {
           throw new UnsupportedOperationException("This is read only result data");
         }
@@ -326,12 +320,6 @@ public class ResultBuilder {
         }
 
         @Override
-        public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-            boolean addTimeStampToName) throws FileNotFoundException, IOException {
-          throw new UnsupportedOperationException("This is read only result data");
-        }
-
-        @Override
         public ErrorResultData addLine(String line) {
           throw new UnsupportedOperationException("This is read only result data");
         }
@@ -351,12 +339,6 @@ public class ResultBuilder {
         }
 
         @Override
-        public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-            boolean addTimeStampToName) throws FileNotFoundException, IOException {
-          throw new UnsupportedOperationException("This is read only result data");
-        }
-
-        @Override
         public ErrorResultData addLine(String line) {
           throw new UnsupportedOperationException("This is read only result data");
         }
@@ -381,12 +363,6 @@ public class ResultBuilder {
         }
 
         @Override
-        public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-            boolean addTimeStampToName) throws FileNotFoundException, IOException {
-          throw new UnsupportedOperationException("This is read only result data");
-        }
-
-        @Override
         public SectionResultData addSection() {
           throw new UnsupportedOperationException("This is read only result data");
         }
@@ -416,12 +392,6 @@ public class ResultBuilder {
         }
 
         @Override
-        public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-            boolean addTimeStampToName) throws FileNotFoundException, IOException {
-          throw new UnsupportedOperationException("This is read only result data");
-        }
-
-        @Override
         public ObjectResultData<CliJsonSerializable> addCollection(
             Collection<CliJsonSerializable> infoBeans) {
           throw new UnsupportedOperationException("This is read only result data");

http://git-wip-us.apache.org/repos/asf/geode/blob/e220d099/geode-json/build.gradle
----------------------------------------------------------------------
diff --git a/geode-json/build.gradle b/geode-json/build.gradle
index 8a1727e..722244a 100644
--- a/geode-json/build.gradle
+++ b/geode-json/build.gradle
@@ -16,4 +16,5 @@
  */
 
 dependencies {
+    testCompile project(':geode-junit')
 }
\ No newline at end of file


[06/34] geode git commit: GEODE-2142: Refactoring of tests to work with new JSONObject class. Changing file export to use Base64 encoding.

Posted by kl...@apache.org.
GEODE-2142: Refactoring of tests to work with new JSONObject class.
Changing file export to use Base64 encoding.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/7c8794cb
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/7c8794cb
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/7c8794cb

Branch: refs/heads/GEODE-4160-mockito
Commit: 7c8794cb8889d1c2847545bfcfeaea6d6c17e515
Parents: fdde618
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 15:12:55 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 .../geode/management/internal/cli/CliUtil.java  |  5 --
 .../internal/cli/result/AbstractResultData.java | 56 ++++++++------------
 2 files changed, 21 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/7c8794cb/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
index 8525b58..8cd098d 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
@@ -440,11 +440,6 @@ public class CliUtil {
 
       compressedDataLength = compresser.deflate(buffer);
       totalCompressedDataLength += compressedDataLength;
-      // System.out.println(compressedDataLength);
-      // System.out.println("uc: b "+buffer.length);
-      // System.out.println("uc: r "+result.length);
-      // System.out.println("uc: nr "+newResult.length);
-      // System.out.println();
       System.arraycopy(buffer, 0, newResult, result.length, buffer.length);
       result = newResult;
     } while (compressedDataLength != 0);

http://git-wip-us.apache.org/repos/asf/geode/blob/7c8794cb/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
index e08d9b7..81ab511 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
@@ -20,7 +20,10 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.text.MessageFormat;
+import java.util.Base64;
 import java.util.zip.DataFormatException;
 
 import org.apache.geode.management.cli.Result.Status;
@@ -151,26 +154,10 @@ public abstract class AbstractResultData implements ResultData {
     if (addTimeStampToName) {
       fileName = addTimeStampBeforeLastDot(fileName);
     }
-    return addAsFile(fileName.getBytes(), bytes, fileType, message);
+    return addAsFile(fileName, bytes, fileType, message);
   }
 
-  public ResultData addByteDataFromFileFile(String filePath, int fileType, String message,
-      boolean addTimeStampToName) throws FileNotFoundException, IOException {
-    byte[][] filesToBytes = CliUtil.filesToBytes(new String[] {filePath});
-
-    byte[] bytes = filesToBytes[0];
-    if (addTimeStampToName) {
-      String fileName = new String(filesToBytes[0]);
-      fileName = addTimeStampBeforeLastDot(fileName);
-      bytes = fileName.getBytes();
-    }
-    return addAsFile(bytes, filesToBytes[1], fileType, message);
-  }
-
-  private ResultData addAsFile(byte[] fileName, byte[] data, int fileType, String message) {
-    // System.out.println("fileType :: "+fileType);
-    // System.out.println("FILE_TYPE_BINARY :: "+FILE_TYPE_BINARY);
-    // System.out.println("FILE_TYPE_TEXT :: "+FILE_TYPE_TEXT);
+  private ResultData addAsFile(String fileName, byte[] data, int fileType, String message) {
     if (fileType != FILE_TYPE_BINARY && fileType != FILE_TYPE_TEXT) {
       throw new IllegalArgumentException("Unsupported file type is specified.");
     }
@@ -186,14 +173,12 @@ public abstract class AbstractResultData implements ResultData {
 
       sectionData.put(FILE_NAME_FIELD, fileName);
       sectionData.put(FILE_TYPE_FIELD, fileType);
-      sectionData.put(FILE_MESSAGE, message.getBytes());
-      sectionData.putAsJSONObject(FILE_DATA_FIELD, CliUtil.compressBytes(data));
-      // System.out.println(data);
-      // sectionData.put(FILE_DATA_FIELD, Base64.encodeBytes(data, Base64.GZIP));
+      sectionData.put(FILE_MESSAGE, message);
+      DeflaterInflaterData deflaterInflaterData = CliUtil.compressBytes(data);
+      sectionData.put(FILE_DATA_FIELD, Base64.getEncoder().encodeToString(deflaterInflaterData.getData()));
+      sectionData.put(DATA_LENGTH_FIELD,deflaterInflaterData.getDataLength());
     } catch (GfJsonException e) {
       throw new ResultDataException(e.getMessage());
-      // } catch (IOException e) {
-      // e.printStackTrace();
     }
     return this;
   }
@@ -223,29 +208,30 @@ public abstract class AbstractResultData implements ResultData {
 
       // build file name
       byte[] fileNameBytes = null;
+      String fileName = null;
       GfJsonArray fileNameJsonBytes = object.getJSONArray(FILE_NAME_FIELD);
       if (fileNameJsonBytes != null) { // if in gfsh
         fileNameBytes = GfJsonArray.toByteArray(fileNameJsonBytes);
+        fileName = new String(fileNameBytes);
       } else { // if on member
-        fileNameBytes = (byte[]) object.get(FILE_NAME_FIELD);
+        fileName = (String) object.get(FILE_NAME_FIELD);
       }
-      String fileName = new String(fileNameBytes);
 
       // build file message
       byte[] fileMessageBytes = null;
+      String fileMessage = null;
       GfJsonArray fileMessageJsonBytes = object.getJSONArray(FILE_MESSAGE);
       if (fileMessageJsonBytes != null) { // if in gfsh
         fileMessageBytes = GfJsonArray.toByteArray(fileMessageJsonBytes);
+        fileMessage = new String(fileMessageBytes);
       } else { // if on member
-        fileMessageBytes = (byte[]) object.get(FILE_MESSAGE);
+        fileMessage = (String) object.get(FILE_MESSAGE);
       }
-      String fileMessage = new String(fileMessageBytes);
 
-      GfJsonObject fileDataBytes = object.getJSONObject(FILE_DATA_FIELD);
-      byte[] byteArray = GfJsonArray.toByteArray(fileDataBytes.getJSONArray(DATA_FIELD));
-      int dataLength = fileDataBytes.getInt(DATA_LENGTH_FIELD);
-      DeflaterInflaterData uncompressBytes = CliUtil.uncompressBytes(byteArray, dataLength);
-      byte[] uncompressed = uncompressBytes.getData();
+      String fileDataString = (String) object.get(FILE_DATA_FIELD);
+      int fileDataLength = (int) object.get(DATA_LENGTH_FIELD);
+      byte[] byteArray = Base64.getDecoder().decode(fileDataString);
+      byte[] uncompressBytes = CliUtil.uncompressBytes(byteArray,fileDataLength).getData();
 
       boolean isGfshVM = CliUtil.isGfshVM();
       File fileToDumpData = new File(fileName);
@@ -299,13 +285,13 @@ public abstract class AbstractResultData implements ResultData {
       if (fileType == FILE_TYPE_TEXT) {
         FileWriter fw = new FileWriter(fileToDumpData);
         BufferedWriter bw = new BufferedWriter(fw);
-        bw.write(new String(uncompressed));
+        bw.write(new String(uncompressBytes));
         bw.flush();
         fw.flush();
         fw.close();
       } else if (fileType == FILE_TYPE_BINARY) {
         FileOutputStream fos = new FileOutputStream(fileToDumpData);
-        fos.write(uncompressed);
+        fos.write(uncompressBytes);
         fos.flush();
         fos.close();
       }


[30/34] geode git commit: GEODE-2538: Don't invoke a cache loader when fetching values for a lucene query

Posted by kl...@apache.org.
GEODE-2538: Don't invoke a cache loader when fetching values for a lucene query

Instead of using getAll, fetch the values of a lucene query using a
function that calls getEntry. We can then avoid invoking the cache
loader.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/712d87f7
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/712d87f7
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/712d87f7

Branch: refs/heads/GEODE-4160-mockito
Commit: 712d87f791906cbd1c11dd0f4655032dabf57755
Parents: 11521a8
Author: Dan Smith <up...@apache.org>
Authored: Mon Feb 27 14:21:58 2017 -0800
Committer: Dan Smith <up...@apache.org>
Committed: Mon Feb 27 14:26:15 2017 -0800

----------------------------------------------------------------------
 .../cache/lucene/internal/LuceneQueryImpl.java  |  5 +
 .../lucene/internal/LuceneServiceImpl.java      |  2 +
 .../PageableLuceneQueryResultsImpl.java         | 23 ++++-
 .../internal/results/LuceneGetPageFunction.java | 96 ++++++++++++++++++++
 .../internal/results/MapResultCollector.java    | 55 +++++++++++
 .../lucene/LuceneQueriesIntegrationTest.java    | 41 +++++++++
 .../geode/cache/lucene/PaginationDUnitTest.java |  7 +-
 .../internal/LuceneQueryImplJUnitTest.java      | 54 +++++++----
 ...PageableLuceneQueryResultsImplJUnitTest.java | 39 +++++++-
 .../results/LuceneGetPageFunctionJUnitTest.java | 59 ++++++++++++
 10 files changed, 351 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
index de622e0..1ece774 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
@@ -93,6 +93,11 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K, V> {
 
   private PageableLuceneQueryResults<K, V> findPages(int pageSize) throws LuceneQueryException {
     TopEntries<K> entries = findTopEntries();
+    return newPageableResults(pageSize, entries);
+  }
+
+  protected PageableLuceneQueryResults<K, V> newPageableResults(final int pageSize,
+      final TopEntries<K> entries) {
     return new PageableLuceneQueryResultsImpl<K, V>(entries.getHits(), region, pageSize);
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index a608dd9..dd32000 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
 import org.apache.geode.cache.lucene.internal.management.LuceneServiceMBean;
 import org.apache.geode.cache.lucene.internal.management.ManagementIndexListener;
+import org.apache.geode.cache.lucene.internal.results.LuceneGetPageFunction;
 import org.apache.geode.management.internal.beans.CacheServiceMBeanBase;
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.analysis.Analyzer;
@@ -89,6 +90,7 @@ public class LuceneServiceImpl implements InternalLuceneService {
     this.cache = gfc;
 
     FunctionService.registerFunction(new LuceneQueryFunction());
+    FunctionService.registerFunction(new LuceneGetPageFunction());
     FunctionService.registerFunction(new WaitUntilFlushedFunction());
     FunctionService.registerFunction(new DumpDirectoryFiles());
     registerDataSerializables();

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
index 5c5d825..8db98a5 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
@@ -17,14 +17,21 @@ package org.apache.geode.cache.lucene.internal;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Set;
 
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.FunctionService;
+import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
 import org.apache.geode.cache.lucene.LuceneResultStruct;
 import org.apache.geode.cache.lucene.internal.distributed.EntryScore;
+import org.apache.geode.cache.lucene.internal.results.LuceneGetPageFunction;
+import org.apache.geode.cache.lucene.internal.results.MapResultCollector;
 
 /**
  * Implementation of PageableLuceneQueryResults that fetchs a page at a time from the server, given
@@ -74,15 +81,15 @@ public class PageableLuceneQueryResultsImpl<K, V> implements PageableLuceneQuery
 
   public List<LuceneResultStruct<K, V>> getHitEntries(int fromIndex, int toIndex) {
     List<EntryScore<K>> scores = hits.subList(fromIndex, toIndex);
-    ArrayList<K> keys = new ArrayList<K>(scores.size());
+    Set<K> keys = new HashSet<K>(scores.size());
     for (EntryScore<K> score : scores) {
       keys.add(score.getKey());
     }
 
-    Map<K, V> values = userRegion.getAll(keys);
+    Map<K, V> values = getValues(keys);
 
     ArrayList<LuceneResultStruct<K, V>> results =
-        new ArrayList<LuceneResultStruct<K, V>>(scores.size());
+        new ArrayList<LuceneResultStruct<K, V>>(values.size());
     for (EntryScore<K> score : scores) {
       V value = values.get(score.getKey());
       if (value != null)
@@ -91,6 +98,16 @@ public class PageableLuceneQueryResultsImpl<K, V> implements PageableLuceneQuery
     return results;
   }
 
+  protected Map<K, V> getValues(final Set<K> keys) {
+    ResultCollector resultCollector = onRegion().withFilter(keys)
+        .withCollector(new MapResultCollector()).execute(LuceneGetPageFunction.ID);
+    return (Map<K, V>) resultCollector.getResult();
+  }
+
+  protected Execution onRegion() {
+    return FunctionService.onRegion(userRegion);
+  }
+
   @Override
   public List<LuceneResultStruct<K, V>> next() {
     if (!hasNext()) {

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
new file mode 100644
index 0000000..f5c2b99
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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
+ * 
+ * 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.apache.geode.cache.lucene.internal.results;
+
+import org.apache.geode.cache.EntryDestroyedException;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Region.Entry;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.FunctionException;
+import org.apache.geode.cache.execute.RegionFunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.cache.lucene.LuceneQueryException;
+import org.apache.geode.cache.lucene.LuceneQueryProvider;
+import org.apache.geode.cache.lucene.LuceneService;
+import org.apache.geode.cache.lucene.LuceneServiceProvider;
+import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
+import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
+import org.apache.geode.cache.lucene.internal.distributed.CollectorManager;
+import org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext;
+import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector;
+import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollectorManager;
+import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
+import org.apache.geode.cache.lucene.internal.repository.IndexResultCollector;
+import org.apache.geode.cache.lucene.internal.repository.RepositoryManager;
+import org.apache.geode.cache.partition.PartitionRegionHelper;
+import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.BucketNotFoundException;
+import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.logging.log4j.Logger;
+import org.apache.lucene.search.Query;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * {@link LuceneGetPageFunction} Returns the values of entries back to the user This behaves
+ * basically like a getAll, but it does not invoke a cache loader
+ */
+public class LuceneGetPageFunction implements Function, InternalEntity {
+  private static final long serialVersionUID = 1L;
+  public static final String ID = LuceneGetPageFunction.class.getName();
+
+  private static final Logger logger = LogService.getLogger();
+
+  @Override
+  public void execute(FunctionContext context) {
+    RegionFunctionContext ctx = (RegionFunctionContext) context;
+    Region region = PartitionRegionHelper.getLocalDataForContext(ctx);
+    Set<?> keys = ctx.getFilter();
+
+    Map<Object, Object> results = new HashMap<>(keys.size());
+
+    for (Object key : keys) {
+      final Entry entry = region.getEntry(key);
+      try {
+        Object value = entry == null ? null : entry.getValue();
+        if (value != null) {
+          results.put(key, value);
+        }
+      } catch (EntryDestroyedException e) {
+        // skip
+      }
+    }
+    ctx.getResultSender().lastResult(results);
+  }
+
+
+  @Override
+  public String getId() {
+    return ID;
+  }
+
+  @Override
+  public boolean optimizeForWrite() {
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/MapResultCollector.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/MapResultCollector.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/MapResultCollector.java
new file mode 100644
index 0000000..9264126
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/MapResultCollector.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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
+ *
+ * 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.apache.geode.cache.lucene.internal.results;
+
+import org.apache.geode.cache.execute.FunctionException;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.distributed.DistributedMember;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class MapResultCollector implements ResultCollector<Map<?, ?>, Map<Object, Object>> {
+  private final Map<Object, Object> results = new HashMap<>();
+
+  @Override
+  public Map<Object, Object> getResult() throws FunctionException {
+    return results;
+  }
+
+  @Override
+  public Map<Object, Object> getResult(final long timeout, final TimeUnit unit)
+      throws FunctionException, InterruptedException {
+    return results;
+  }
+
+  @Override
+  public void addResult(final DistributedMember memberID, final Map<?, ?> resultOfSingleExecution) {
+    this.results.putAll(resultOfSingleExecution);
+
+  }
+
+  @Override
+  public void endResults() {
+
+  }
+
+  @Override
+  public void clearResults() {
+    results.clear();
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
index 01bdca4..6420307 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -29,6 +29,9 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
+import org.apache.geode.cache.CacheLoader;
+import org.apache.geode.cache.CacheLoaderException;
+import org.apache.geode.cache.LoaderHelper;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.Tokenizer;
@@ -363,6 +366,44 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
   }
 
   @Test
+  public void shouldReturnCorrectResultsOnDeletionAfterQueryExecutionWithLoader() throws Exception {
+    final int pageSize = 2;
+    final LuceneQuery<Object, Object> query = addValuesAndCreateQuery(pageSize);
+    region.getAttributesMutator().setCacheLoader(new CacheLoader() {
+      @Override
+      public Object load(final LoaderHelper helper) throws CacheLoaderException {
+        return new TestObject("should not", "load this");
+      }
+
+      @Override
+      public void close() {
+
+      }
+    });
+    final PageableLuceneQueryResults<Object, Object> pages = query.findPages();
+    List<LuceneResultStruct<Object, Object>> allEntries = new ArrayList<>();
+    assertTrue(pages.hasNext());
+    assertEquals(7, pages.size());
+    // Destroying an entry from the region after the query is executed.
+    region.destroy("C");
+    final List<LuceneResultStruct<Object, Object>> page1 = pages.next();
+    assertEquals(pageSize, page1.size());
+    final List<LuceneResultStruct<Object, Object>> page2 = pages.next();
+    assertEquals(pageSize, page2.size());
+    final List<LuceneResultStruct<Object, Object>> page3 = pages.next();
+    assertEquals(pageSize, page3.size());
+    assertFalse(pages.hasNext());
+
+    allEntries.addAll(page1);
+    allEntries.addAll(page2);
+    allEntries.addAll(page3);
+    assertEquals(region.keySet(),
+        allEntries.stream().map(entry -> entry.getKey()).collect(Collectors.toSet()));
+    assertEquals(region.values(),
+        allEntries.stream().map(entry -> entry.getValue()).collect(Collectors.toSet()));
+  }
+
+  @Test
   public void shouldReturnCorrectResultsOnMultipleDeletionsAfterQueryExecution() throws Exception {
     final LuceneQuery<Object, Object> query = addValuesAndCreateQuery(2);
 

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
index de71c08..3ff86f7 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/PaginationDUnitTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionedRegionStorageException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.test.dunit.Assert;
 import org.apache.geode.test.dunit.SerializableRunnableIF;
@@ -59,7 +60,7 @@ public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
 
   @Test
   @Parameters(method = "getListOfRegionTestTypes")
-  public void noSuchElementExceptionWhenAllDataStoreAreClosedWhilePagination(
+  public void partitionedRegionStorageExceptionWhenAllDataStoreAreClosedWhilePagination(
       RegionTestableType regionTestType) {
     SerializableRunnableIF createIndex = () -> {
       LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -90,8 +91,8 @@ public class PaginationDUnitTest extends LuceneQueriesAccessorBase {
         fail();
       } catch (Exception e) {
         Assert.assertEquals(
-            "Expected Exception = java.util.NoSuchElementException but hit " + e.toString(), true,
-            e instanceof java.util.NoSuchElementException);
+            "Expected Exception = PartitionedRegionStorageException but hit " + e.toString(), true,
+            e instanceof PartitionedRegionStorageException);
       }
     });
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneQueryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneQueryImplJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneQueryImplJUnitTest.java
index ca439fe..20f5d1d 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneQueryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneQueryImplJUnitTest.java
@@ -16,35 +16,38 @@
 package org.apache.geode.cache.lucene.internal;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.ArgumentCaptor;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.lucene.LuceneQueryException;
 import org.apache.geode.cache.lucene.LuceneQueryProvider;
-import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
 import org.apache.geode.cache.lucene.LuceneResultStruct;
+import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
 import org.apache.geode.cache.lucene.internal.distributed.EntryScore;
 import org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext;
+import org.apache.geode.cache.lucene.internal.distributed.LuceneQueryFunction;
 import org.apache.geode.cache.lucene.internal.distributed.TopEntries;
 import org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector;
 import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @Category(UnitTest.class)
 public class LuceneQueryImplJUnitTest {
@@ -54,6 +57,7 @@ public class LuceneQueryImplJUnitTest {
   private LuceneQueryProvider provider;
   private ResultCollector<TopEntriesCollector, TopEntries> collector;
   private Region region;
+  private PageableLuceneQueryResults<Object, Object> results;
 
   @Before
   public void createMocks() {
@@ -65,12 +69,20 @@ public class LuceneQueryImplJUnitTest {
     when(execution.withArgs(any())).thenReturn(execution);
     when(execution.withCollector(any())).thenReturn(execution);
     when(execution.execute(anyString())).thenReturn((ResultCollector) collector);
+    results = mock(PageableLuceneQueryResults.class);
 
     query = new LuceneQueryImpl<Object, Object>("index", region, provider, LIMIT, 20) {
+
       @Override
       protected Execution onRegion() {
         return execution;
       }
+
+      @Override
+      protected PageableLuceneQueryResults<Object, Object> newPageableResults(final int pageSize,
+          final TopEntries<Object> entries) {
+        return results;
+      }
     };
   }
 
@@ -79,9 +91,12 @@ public class LuceneQueryImplJUnitTest {
     entries.addHit(new EntryScore("hi", 5));
     when(collector.getResult()).thenReturn(entries);
 
-    Map<String, String> getAllResult = new HashMap<String, String>();
-    getAllResult.put("hi", "value");
-    when(region.getAll(eq(Collections.singletonList("hi")))).thenReturn(getAllResult);
+    when(results.getMaxScore()).thenReturn(5f);
+    when(results.size()).thenReturn(1);
+    List<LuceneResultStruct<Object, Object>> page =
+        Collections.singletonList(new LuceneResultStructImpl<>("hi", "value", 5f));
+    when(results.next()).thenReturn(page);
+    when(results.hasNext()).thenReturn(true);
   }
 
   @Test
@@ -137,6 +152,7 @@ public class LuceneQueryImplJUnitTest {
     assertEquals("index", context.getIndexName());
 
     assertEquals(5, results.getMaxScore(), 0.01);
+    assertEquals(1, results.size());
     final List<LuceneResultStruct<Object, Object>> page = results.next();
     assertEquals(1, page.size());
     LuceneResultStruct element = page.iterator().next();

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
index 35a4c91..bc38112 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
@@ -15,6 +15,12 @@
 package org.apache.geode.cache.lucene.internal;
 
 import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,12 +29,16 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Set;
 
+import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.ResultCollector;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -48,6 +58,7 @@ public class PageableLuceneQueryResultsImplJUnitTest {
   private List<EntryScore<String>> hits;
   private List<LuceneResultStruct> expected = new ArrayList<LuceneResultStruct>();
   private Region<String, String> userRegion;
+  private Execution execution;
 
   @Before
   public void setUp() {
@@ -58,13 +69,21 @@ public class PageableLuceneQueryResultsImplJUnitTest {
       expected.add(new LuceneResultStructImpl<String, String>("key_" + i, "value_" + i, i));
     }
 
-    userRegion = Mockito.mock(Region.class);
+    userRegion = mock(Region.class);
 
-    Mockito.when(userRegion.getAll(Mockito.anyCollection())).thenAnswer(new Answer() {
+    final ResultCollector collector = mock(ResultCollector.class);
+    execution = mock(Execution.class);
+    when(execution.withFilter(any())).thenReturn(execution);
+    when(execution.withCollector(any())).thenReturn(execution);
+    when(execution.execute(anyString())).thenReturn(collector);
+
+    when(collector.getResult()).then(new Answer() {
 
       @Override
       public Map answer(InvocationOnMock invocation) throws Throwable {
-        Collection<String> keys = invocation.getArgumentAt(0, Collection.class);
+        ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
+        verify(execution, atLeast(1)).withFilter(captor.capture());
+        Collection<String> keys = captor.getValue();
         Map<String, String> results = new HashMap<String, String>();
         for (String key : keys) {
           results.put(key, key.replace("key_", "value_"));
@@ -88,7 +107,12 @@ public class PageableLuceneQueryResultsImplJUnitTest {
   @Test
   public void testPagination() {
     PageableLuceneQueryResultsImpl<String, String> results =
-        new PageableLuceneQueryResultsImpl<String, String>(hits, userRegion, 10);
+        new PageableLuceneQueryResultsImpl<String, String>(hits, userRegion, 10) {
+          @Override
+          protected Execution onRegion() {
+            return execution;
+          }
+        };
 
     assertEquals(23, results.size());
 
@@ -114,7 +138,12 @@ public class PageableLuceneQueryResultsImplJUnitTest {
   @Test
   public void testNoPagination() {
     PageableLuceneQueryResultsImpl<String, String> results =
-        new PageableLuceneQueryResultsImpl<String, String>(hits, userRegion, 0);
+        new PageableLuceneQueryResultsImpl<String, String>(hits, userRegion, 0) {
+          @Override
+          protected Execution onRegion() {
+            return execution;
+          }
+        };
 
     assertEquals(23, results.size());
 

http://git-wip-us.apache.org/repos/asf/geode/blob/712d87f7/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunctionJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunctionJUnitTest.java
new file mode 100644
index 0000000..c62082c
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunctionJUnitTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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
+ *
+ * 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.apache.geode.cache.lucene.internal.results;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Region.Entry;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.RegionFunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.execute.InternalRegionFunctionContext;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Collections;
+import java.util.Set;
+
+@Category(UnitTest.class)
+public class LuceneGetPageFunctionJUnitTest {
+
+  @Test
+  public void shouldReturnMapWithKeyAndValue() {
+    PartitionedRegion region = mock(PartitionedRegion.class);
+    InternalRegionFunctionContext context = mock(InternalRegionFunctionContext.class);
+    when(context.getDataSet()).thenReturn(region);
+    ResultSender resultSender = mock(ResultSender.class);
+    when(context.getResultSender()).thenReturn(resultSender);
+    LuceneGetPageFunction function = new LuceneGetPageFunction();
+    when(context.getLocalDataSet(any())).thenReturn(region);
+    final Entry entry = mock(Entry.class);
+    when(region.getEntry(any())).thenReturn(entry);
+    when(entry.getValue()).thenReturn("value");
+    when(context.getFilter()).thenReturn((Set) Collections.singleton("key"));
+    function.execute(context);
+
+    verify(resultSender).lastResult(eq(Collections.singletonMap("key", "value")));
+  }
+
+}


[16/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/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 ce15d1b..07a024c 100755
--- a/geode-json/src/main/java/org/json/JSONObject.java
+++ b/geode-json/src/main/java/org/json/JSONObject.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -29,55 +27,53 @@ 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 +84,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 +94,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 +127,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 +151,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 +170,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 +180,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,6 +199,7 @@ 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
    */
@@ -269,6 +266,7 @@ public class JSONObject {
 
   /**
    * Returns the number of name/value mappings in this object.
+   * 
    * @return the length of this.
    */
   public int length() {
@@ -276,8 +274,9 @@ 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.
@@ -289,11 +288,12 @@ 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.
    */
@@ -303,8 +303,9 @@ 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.
@@ -316,8 +317,9 @@ 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.
@@ -329,13 +331,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).
    */
@@ -353,8 +355,9 @@ 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.
@@ -368,22 +371,21 @@ 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.
    */
@@ -408,15 +410,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));
@@ -446,6 +448,7 @@ 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.
    */
@@ -454,8 +457,9 @@ 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.
    */
@@ -465,8 +469,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}
    */
@@ -476,6 +480,7 @@ 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.
@@ -489,8 +494,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.
    */
@@ -499,8 +504,9 @@ 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.
@@ -515,8 +521,9 @@ 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.
    */
@@ -525,8 +532,9 @@ 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.
@@ -538,8 +546,9 @@ 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.
@@ -554,8 +563,9 @@ 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.
    */
@@ -564,8 +574,9 @@ 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.
@@ -577,8 +588,9 @@ 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.
@@ -593,8 +605,9 @@ 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.
    */
@@ -603,8 +616,9 @@ 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.
@@ -616,12 +630,11 @@ 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.
@@ -636,9 +649,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 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.
    */
@@ -647,10 +661,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.
@@ -662,8 +676,9 @@ 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.
@@ -678,8 +693,9 @@ 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.
    */
@@ -688,8 +704,9 @@ 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.
@@ -703,6 +720,7 @@ 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}.
@@ -719,6 +737,7 @@ 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
    */
@@ -730,6 +749,7 @@ 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}.
@@ -746,6 +766,7 @@ 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.
    */
@@ -755,9 +776,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.
@@ -779,11 +800,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() {
@@ -791,12 +812,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() {
@@ -804,19 +825,22 @@ 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() {
@@ -830,8 +854,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",
@@ -839,7 +863,9 @@ 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.
@@ -860,8 +886,9 @@ 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.
    */
@@ -887,8 +914,9 @@ 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.
    */
@@ -910,7 +938,8 @@ 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
@@ -918,6 +947,7 @@ 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}
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/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 34815a8..4a09d89 100755
--- a/geode-json/src/main/java/org/json/JSONString.java
+++ b/geode-json/src/main/java/org/json/JSONString.java
@@ -1,18 +1,17 @@
 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/eac0bb8c/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 db1121e..43224a5 100755
--- a/geode-json/src/main/java/org/json/JSONStringer.java
+++ b/geode-json/src/main/java/org/json/JSONStringer.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -23,448 +21,439 @@ 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();
+  /**
+   * 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.
-         */
-        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,
-    }
+  /**
+   * Lexical scoping elements within this stringer, necessary to insert the appropriate separator
+   * characters (ie. commas and colons) and to detect nesting errors.
+   */
+  enum Scope {
 
     /**
-     * Unlike the original implementation, this stack isn't limited to 20
-     * levels of nesting.
+     * An array with no elements requires no separators or newlines before it is closed.
      */
-    private final List<Scope> stack = new ArrayList<Scope>();
+    EMPTY_ARRAY,
 
     /**
-     * A string containing a full set of spaces for a single level of
-     * indentation, or null for no pretty printing.
+     * A array with at least one value requires a comma and newline before the next element.
      */
-    private final String indent;
-
-    public JSONStringer() {
-        indent = null;
-    }
-
-    JSONStringer(int indentSpaces) {
-        char[] indentChars = new char[indentSpaces];
-        Arrays.fill(indentChars, ' ');
-        indent = new String(indentChars);
-    }
+    NONEMPTY_ARRAY,
 
     /**
-     * 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.
+     * An object with no keys or values requires no separators or newlines before it is closed.
      */
-    public JSONStringer array() throws JSONException {
-        return open(Scope.EMPTY_ARRAY, "[");
-    }
+    EMPTY_OBJECT,
 
     /**
-     * Ends encoding the current array.
-     *
-     * @return this stringer.
-     * @throws JSONException On internal errors. Shouldn't happen.
+     * An object whose most recent element is a key. The next element must be a value.
      */
-    public JSONStringer endArray() throws JSONException {
-        return close(Scope.EMPTY_ARRAY, Scope.NONEMPTY_ARRAY, "]");
-    }
+    DANGLING_KEY,
 
     /**
-     * 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.
+     * An object with at least one name/value pair requires a comma and newline before the next
+     * element.
      */
-    public JSONStringer object() throws JSONException {
-        return open(Scope.EMPTY_OBJECT, "{");
-    }
+    NONEMPTY_OBJECT,
 
     /**
-     * Ends encoding the current object.
-     *
-     * @return this stringer.
-     * @throws JSONException On internal errors. Shouldn't happen.
+     * A special bracketless array needed by JSONStringer.join() and JSONObject.quote() only. Not
+     * used for JSON encoding.
      */
-    public JSONStringer endObject() throws JSONException {
-        return close(Scope.EMPTY_OBJECT, Scope.NONEMPTY_OBJECT, "}");
+    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");
     }
-
-    /**
-     * 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();
+    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");
     }
 
-    /**
-     * 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;
+    stack.remove(stack.size() - 1);
+    if (context == nonempty) {
+      newline();
     }
-
-    /**
-     * 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);
+    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");
     }
-
-    /**
-     * Replace the value on the top of the stack with the given value.
-     */
-    private void replaceTop(Scope topOfStack) {
-        stack.set(stack.size() - 1, topOfStack);
+    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");
     }
 
-    /**
-     * 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;
-    }
+    if (value instanceof JSONArray) {
+      ((JSONArray) value).writeTo(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;
+    } else if (value instanceof JSONObject) {
+      ((JSONObject) value).writeTo(this);
+      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;
+    beforeValue();
+
+    if (value instanceof JSONString) {
+      out.append(((JSONString) value).toJSONString());
+      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");
-        }
-        beforeValue();
+    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);
-        return this;
+      } else {
+        string(value.toString());
+      }
     }
 
-    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("\"");
+    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");
     }
-
-    private void newline() {
-        if (indent == null) {
-            return;
-        }
-
-        out.append("\n");
-        for (int i = 0; i < stack.size(); i++) {
-            out.append(indent);
-        }
+    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");
+    }
+    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 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;
     }
+    out.append("\"");
+  }
 
-    /**
-     * 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);
+  private void newline() {
+    if (indent == null) {
+      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");
-        }
+    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");
+    }
+    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");
+    }
+    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;
     }
 
-    /**
-     * 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();
+    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();
+  }
 }


[23/34] geode git commit: GEODE-2142: Adding JSON library from the https://github.com/tdunning/open-json project

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/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
new file mode 100755
index 0000000..db1121e
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONStringer.java
@@ -0,0 +1,470 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+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>
+ * JSONObject object = ...
+ * String json = object.toString();</pre>
+ *
+ * <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>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.
+ * </ul>
+ * 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>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
+ * 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.
+         */
+        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,
+    }
+
+    /**
+     * 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");
+        }
+
+        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");
+        }
+
+        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;
+    }
+
+    /**
+     * 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");
+        }
+        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;
+            }
+
+        }
+        out.append("\"");
+    }
+
+    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");
+        }
+        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");
+        }
+        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;
+        }
+
+        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();
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/main/java/org/json/JSONTokener.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONTokener.java b/geode-json/src/main/java/org/json/JSONTokener.java
new file mode 100755
index 0000000..59eb4bc
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONTokener.java
@@ -0,0 +1,658 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+// Note: this class was written without inspecting the non-free org.json sourcecode.
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Parses a JSON (<a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>)
+ * encoded string into the corresponding object. Most clients of
+ * this class will use only need the {@link #JSONTokener(String) constructor}
+ * and {@link #nextValue} method. Example usage: <pre>
+ * String json = "{"
+ *         + "  \"query\": \"Pizza\", "
+ *         + "  \"locations\": [ 94043, 90210 ] "
+ *         + "}";
+ *
+ * JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
+ * String query = object.getString("query");
+ * JSONArray locations = object.getJSONArray("locations");</pre>
+ *
+ * <p>For best interoperability and performance use JSON that complies with
+ * RFC 4627, such as that generated by {@link JSONStringer}. For legacy reasons
+ * this parser is lenient, so a successful parse does not indicate that the
+ * input string was valid JSON. All of the following syntax errors will be
+ * ignored:
+ * <ul>
+ * <li>End of line comments starting with {@code //} or {@code #} and ending
+ * with a newline character.
+ * <li>C-style comments starting with {@code /*} and ending with
+ * {@code *}{@code /}. Such comments may not be nested.
+ * <li>Strings that are unquoted or {@code 'single quoted'}.
+ * <li>Hexadecimal integers prefixed with {@code 0x} or {@code 0X}.
+ * <li>Octal integers prefixed with {@code 0}.
+ * <li>Array elements separated by {@code ;}.
+ * <li>Unnecessary array separators. These are interpreted as if null was the
+ * omitted value.
+ * <li>Key-value pairs separated by {@code =} or {@code =>}.
+ * <li>Key-value pairs separated by {@code ;}.
+ * </ul>
+ *
+ * <p>Each tokener may be used to parse a single JSON string. 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 JSONTokener {
+
+    /**
+     * The input JSON.
+     */
+    private final String in;
+
+    /**
+     * The index of the next character to be returned by {@link #next}. When
+     * the input is exhausted, this equals the input's length.
+     */
+    private int pos;
+
+    /**
+     * @param in JSON encoded string. Null is not permitted and will yield a
+     *           tokener that throws {@code NullPointerExceptions} when methods are
+     *           called.
+     */
+    public JSONTokener(String in) {
+        // consume an optional byte order mark (BOM) if it exists
+        if (in != null && in.startsWith("\ufeff")) {
+            in = in.substring(1);
+        }
+        this.in = in;
+    }
+
+    public JSONTokener(Reader input) throws IOException {
+        StringBuilder s = new StringBuilder();
+        char[] readBuf = new char[102400];
+        int n = input.read(readBuf);
+        while (n >= 0) {
+            s.append(readBuf, 0, n);
+            n = input.read(readBuf);
+        }
+        in = s.toString();
+        pos = 0;
+    }
+
+    /**
+     * Returns the next value from the input.
+     *
+     * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean,
+     * Integer, Long, Double or {@link JSONObject#NULL}.
+     * @throws JSONException if the input is malformed.
+     */
+    public Object nextValue() throws JSONException {
+        int c = nextCleanInternal();
+        switch (c) {
+            case -1:
+                throw syntaxError("End of input");
+
+            case '{':
+                return readObject();
+
+            case '[':
+                return readArray();
+
+            case '\'':
+            case '"':
+                return nextString((char) c);
+
+            default:
+                pos--;
+                return readLiteral();
+        }
+    }
+
+    private int nextCleanInternal() throws JSONException {
+        while (pos < in.length()) {
+            int c = in.charAt(pos++);
+            switch (c) {
+                case '\t':
+                case ' ':
+                case '\n':
+                case '\r':
+                    continue;
+
+                case '/':
+                    if (pos == in.length()) {
+                        return c;
+                    }
+
+                    char peek = in.charAt(pos);
+                    switch (peek) {
+                        case '*':
+                            // skip a /* c-style comment */
+                            pos++;
+                            int commentEnd = in.indexOf("*/", pos);
+                            if (commentEnd == -1) {
+                                throw syntaxError("Unterminated comment");
+                            }
+                            pos = commentEnd + 2;
+                            continue;
+
+                        case '/':
+                            // skip a // end-of-line comment
+                            pos++;
+                            skipToEndOfLine();
+                            continue;
+
+                        default:
+                            return c;
+                    }
+
+                case '#':
+                    /*
+                     * Skip a # hash end-of-line comment. The JSON RFC doesn't
+                     * specify this behavior, but it's required to parse
+                     * existing documents. See http://b/2571423.
+                     */
+                    skipToEndOfLine();
+                    continue;
+
+                default:
+                    return c;
+            }
+        }
+
+        return -1;
+    }
+
+    /**
+     * Advances the position until after the next newline character. If the line
+     * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
+     * caller.
+     */
+    private void skipToEndOfLine() {
+        for (; pos < in.length(); pos++) {
+            char c = in.charAt(pos);
+            if (c == '\r' || c == '\n') {
+                pos++;
+                break;
+            }
+        }
+    }
+
+    /**
+     * Returns the string up to but not including {@code quote}, unescaping any
+     * character escape sequences encountered along the way. The opening quote
+     * should have already been read. This consumes the closing quote, but does
+     * not include it in the returned string.
+     *
+     * @param quote either ' or ".
+     * @return The unescaped string.
+     * @throws JSONException if the string isn't terminated by a closing quote correctly.
+     */
+    public String nextString(char quote) throws JSONException {
+        /*
+         * For strings that are free of escape sequences, we can just extract
+         * the result as a substring of the input. But if we encounter an escape
+         * sequence, we need to use a StringBuilder to compose the result.
+         */
+        StringBuilder builder = null;
+
+        /* the index of the first character not yet appended to the builder. */
+        int start = pos;
+
+        while (pos < in.length()) {
+            int c = in.charAt(pos++);
+            if (c == quote) {
+                if (builder == null) {
+                    // a new string avoids leaking memory
+                    //noinspection RedundantStringConstructorCall
+                    return new String(in.substring(start, pos - 1));
+                } else {
+                    builder.append(in, start, pos - 1);
+                    return builder.toString();
+                }
+            }
+
+            if (c == '\\') {
+                if (pos == in.length()) {
+                    throw syntaxError("Unterminated escape sequence");
+                }
+                if (builder == null) {
+                    builder = new StringBuilder();
+                }
+                builder.append(in, start, pos - 1);
+                builder.append(readEscapeCharacter());
+                start = pos;
+            }
+        }
+
+        throw syntaxError("Unterminated string");
+    }
+
+    /**
+     * Unescapes the character identified by the character or characters that
+     * immediately follow a backslash. The backslash '\' should have already
+     * been read. This supports both unicode escapes "u000A" and two-character
+     * escapes "\n".
+     */
+    private char readEscapeCharacter() throws JSONException {
+        char escaped = in.charAt(pos++);
+        switch (escaped) {
+            case 'u':
+                if (pos + 4 > in.length()) {
+                    throw syntaxError("Unterminated escape sequence");
+                }
+                String hex = in.substring(pos, pos + 4);
+                pos += 4;
+                try {
+                    return (char) Integer.parseInt(hex, 16);
+                } catch (NumberFormatException nfe) {
+                    throw syntaxError("Invalid escape sequence: " + hex);
+                }
+
+            case 't':
+                return '\t';
+
+            case 'b':
+                return '\b';
+
+            case 'n':
+                return '\n';
+
+            case 'r':
+                return '\r';
+
+            case 'f':
+                return '\f';
+
+            case '\'':
+            case '"':
+            case '\\':
+            default:
+                return escaped;
+        }
+    }
+
+    /**
+     * Reads a null, boolean, numeric or unquoted string literal value. Numeric
+     * values will be returned as an Integer, Long, or Double, in that order of
+     * preference.
+     */
+    private Object readLiteral() throws JSONException {
+        String literal = nextToInternal("{}[]/\\:,=;# \t\f");
+
+        if (literal.length() == 0) {
+            throw syntaxError("Expected literal value");
+        } else if ("null".equalsIgnoreCase(literal)) {
+            return JSONObject.NULL;
+        } else if ("true".equalsIgnoreCase(literal)) {
+            return Boolean.TRUE;
+        } else if ("false".equalsIgnoreCase(literal)) {
+            return Boolean.FALSE;
+        }
+
+        /* try to parse as an integral type... */
+        if (literal.indexOf('.') == -1) {
+            int base = 10;
+            String number = literal;
+            if (number.startsWith("0x") || number.startsWith("0X")) {
+                number = number.substring(2);
+                base = 16;
+            } else if (number.startsWith("0") && number.length() > 1) {
+                number = number.substring(1);
+                base = 8;
+            }
+            try {
+                long longValue = Long.parseLong(number, base);
+                if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
+                    return (int) longValue;
+                } else {
+                    return longValue;
+                }
+            } catch (NumberFormatException e) {
+                /*
+                 * This only happens for integral numbers greater than
+                 * Long.MAX_VALUE, numbers in exponential form (5e-10) and
+                 * unquoted strings. Fall through to try floating point.
+                 */
+            }
+        }
+
+        /* ...next try to parse as a floating point... */
+        try {
+            return Double.valueOf(literal);
+        } catch (NumberFormatException ignored) {
+        }
+
+        /* ... finally give up. We have an unquoted string */
+        //noinspection RedundantStringConstructorCall
+        return new String(literal); // a new string avoids leaking memory
+    }
+
+    /**
+     * Returns the string up to but not including any of the given characters or
+     * a newline character. This does not consume the excluded character.
+     */
+    private String nextToInternal(String excluded) {
+        int start = pos;
+        for (; pos < in.length(); pos++) {
+            char c = in.charAt(pos);
+            if (c == '\r' || c == '\n' || excluded.indexOf(c) != -1) {
+                return in.substring(start, pos);
+            }
+        }
+        return in.substring(start);
+    }
+
+    /**
+     * Reads a sequence of key/value pairs and the trailing closing brace '}' of
+     * an object. The opening brace '{' should have already been read.
+     */
+    private JSONObject readObject() throws JSONException {
+        JSONObject result = new JSONObject();
+
+        /* Peek to see if this is the empty object. */
+        int first = nextCleanInternal();
+        if (first == '}') {
+            return result;
+        } else if (first != -1) {
+            pos--;
+        }
+
+        while (true) {
+            Object name = nextValue();
+            if (!(name instanceof String)) {
+                if (name == null) {
+                    throw syntaxError("Names cannot be null");
+                } else {
+                    throw syntaxError("Names must be strings, but " + name
+                            + " is of type " + name.getClass().getName());
+                }
+            }
+
+            /*
+             * Expect the name/value separator to be either a colon ':', an
+             * equals sign '=', or an arrow "=>". The last two are bogus but we
+             * include them because that's what the original implementation did.
+             */
+            int separator = nextCleanInternal();
+            if (separator != ':' && separator != '=') {
+                throw syntaxError("Expected ':' after " + name);
+            }
+            if (pos < in.length() && in.charAt(pos) == '>') {
+                pos++;
+            }
+
+            result.put((String) name, nextValue());
+
+            switch (nextCleanInternal()) {
+                case '}':
+                    return result;
+                case ';':
+                case ',':
+                    continue;
+                default:
+                    throw syntaxError("Unterminated object");
+            }
+        }
+    }
+
+    /**
+     * Reads a sequence of values and the trailing closing brace ']' of an
+     * array. The opening brace '[' should have already been read. Note that
+     * "[]" yields an empty array, but "[,]" returns a two-element array
+     * equivalent to "[null,null]".
+     */
+    private JSONArray readArray() throws JSONException {
+        JSONArray result = new JSONArray();
+
+        /* to cover input that ends with ",]". */
+        boolean hasTrailingSeparator = false;
+
+        while (true) {
+            switch (nextCleanInternal()) {
+                case -1:
+                    throw syntaxError("Unterminated array");
+                case ']':
+                    if (hasTrailingSeparator) {
+                        result.put(null);
+                    }
+                    return result;
+                case ',':
+                case ';':
+                    /* A separator without a value first means "null". */
+                    result.put(null);
+                    hasTrailingSeparator = true;
+                    continue;
+                default:
+                    pos--;
+            }
+
+            result.put(nextValue());
+
+            switch (nextCleanInternal()) {
+                case ']':
+                    return result;
+                case ',':
+                case ';':
+                    hasTrailingSeparator = true;
+                    continue;
+                default:
+                    throw syntaxError("Unterminated array");
+            }
+        }
+    }
+
+    /**
+     * Returns an exception containing the given message plus the current
+     * position and the entire input string.
+     *
+     * @param message The message we want to include.
+     * @return An exception that we can throw.
+     */
+    public JSONException syntaxError(String message) {
+        return new JSONException(message + this);
+    }
+
+    /**
+     * Returns the current position and the entire input string.
+     */
+    @Override
+    public String toString() {
+        // consistent with the original implementation
+        return " at character " + pos + " of " + in;
+    }
+
+    /*
+     * Legacy APIs.
+     *
+     * None of the methods below are on the critical path of parsing JSON
+     * documents. They exist only because they were exposed by the original
+     * implementation and may be used by some clients.
+     */
+
+    /**
+     * Returns true until the input has been exhausted.
+     *
+     * @return true if more input exists.
+     */
+    public boolean more() {
+        return pos < in.length();
+    }
+
+    /**
+     * Returns the next available character, or the null character '\0' if all
+     * input has been exhausted. The return value of this method is ambiguous
+     * for JSON strings that contain the character '\0'.
+     *
+     * @return the next character.
+     */
+    public char next() {
+        return pos < in.length() ? in.charAt(pos++) : '\0';
+    }
+
+    /**
+     * Returns the next available character if it equals {@code c}. Otherwise an
+     * exception is thrown.
+     *
+     * @param c The character we are looking for.
+     * @return the next character.
+     * @throws JSONException If the next character isn't {@code c}
+     */
+    public char next(char c) throws JSONException {
+        char result = next();
+        if (result != c) {
+            throw syntaxError("Expected " + c + " but was " + result);
+        }
+        return result;
+    }
+
+    /**
+     * Returns the next character that is not whitespace and does not belong to
+     * a comment. If the input is exhausted before such a character can be
+     * found, the null character '\0' is returned. The return value of this
+     * method is ambiguous for JSON strings that contain the character '\0'.
+     *
+     * @return The next non-whitespace character.
+     * @throws JSONException Should not be possible.
+     */
+    public char nextClean() throws JSONException {
+        int nextCleanInt = nextCleanInternal();
+        return nextCleanInt == -1 ? '\0' : (char) nextCleanInt;
+    }
+
+    /**
+     * Returns the next {@code length} characters of the input.
+     *
+     * <p>The returned string shares its backing character array with this
+     * tokener's input string. If a reference to the returned string may be held
+     * indefinitely, you should use {@code new String(result)} to copy it first
+     * to avoid memory leaks.
+     *
+     * @param length The desired number of characters to return.
+     * @return The next few characters.
+     * @throws JSONException if the remaining input is not long enough to
+     *                       satisfy this request.
+     */
+    public String next(int length) throws JSONException {
+        if (pos + length > in.length()) {
+            throw syntaxError(length + " is out of bounds");
+        }
+        String result = in.substring(pos, pos + length);
+        pos += length;
+        return result;
+    }
+
+    /**
+     * Returns the {@link String#trim trimmed} string holding the characters up
+     * to but not including the first of:
+     * <ul>
+     * <li>any character in {@code excluded}
+     * <li>a newline character '\n'
+     * <li>a carriage return '\r'
+     * </ul>
+     *
+     * <p>The returned string shares its backing character array with this
+     * tokener's input string. If a reference to the returned string may be held
+     * indefinitely, you should use {@code new String(result)} to copy it first
+     * to avoid memory leaks.
+     *
+     * @param excluded The limiting string where the search should stop.
+     * @return a possibly-empty string
+     */
+    public String nextTo(String excluded) {
+        if (excluded == null) {
+            throw new NullPointerException("excluded == null");
+        }
+        return nextToInternal(excluded).trim();
+    }
+
+    /**
+     * Equivalent to {@code nextTo(String.valueOf(excluded))}.
+     *
+     * @param excluded The limiting character.
+     * @return a possibly-empty string
+     */
+    public String nextTo(char excluded) {
+        return nextToInternal(String.valueOf(excluded)).trim();
+    }
+
+    /**
+     * Advances past all input up to and including the next occurrence of
+     * {@code thru}. If the remaining input doesn't contain {@code thru}, the
+     * input is exhausted.
+     *
+     * @param thru The string to skip over.
+     */
+    public void skipPast(String thru) {
+        int thruStart = in.indexOf(thru, pos);
+        pos = thruStart == -1 ? in.length() : (thruStart + thru.length());
+    }
+
+    /**
+     * Advances past all input up to but not including the next occurrence of
+     * {@code to}. If the remaining input doesn't contain {@code to}, the input
+     * is unchanged.
+     *
+     * @param to The character we want to skip to.
+     * @return The value of {@code to} or null.
+     */
+    public char skipTo(char to) {
+        int index = in.indexOf(to, pos);
+        if (index != -1) {
+            pos = index;
+            return to;
+        } else {
+            return '\0';
+        }
+    }
+
+    /**
+     * Unreads the most recent character of input. If no input characters have
+     * been read, the input is unchanged.
+     */
+    public void back() {
+        if (--pos == -1) {
+            pos = 0;
+        }
+    }
+
+    /**
+     * Returns the integer [0..15] value for the given hex character, or -1
+     * for non-hex input.
+     *
+     * @param hex a character in the ranges [0-9], [A-F] or [a-f]. Any other
+     *            character will yield a -1 result.
+     * @return The decoded integer.
+     */
+    public static int dehexchar(char hex) {
+        if (hex >= '0' && hex <= '9') {
+            return hex - '0';
+        } else if (hex >= 'A' && hex <= 'F') {
+            return hex - 'A' + 10;
+        } else if (hex >= 'a' && hex <= 'f') {
+            return hex - 'a' + 10;
+        } else {
+            return -1;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/FileTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/FileTest.java b/geode-json/src/test/java/org/json/FileTest.java
new file mode 100755
index 0000000..dae910b
--- /dev/null
+++ b/geode-json/src/test/java/org/json/FileTest.java
@@ -0,0 +1,287 @@
+package org.json;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Set;
+
+public class FileTest {
+    @Test
+    public void testFile() throws IOException, JSONException {
+        String ref = "[\n" +
+                "  {\n" +
+                "    \"_id\": \"58309f3bd307b72ae49a9b23\",\n" +
+                "    \"index\": 0,\n" +
+                "    \"guid\": \"5764ebd8-b333-469e-8d83-4eb5658f1566\",\n" +
+                "    \"isActive\": true,\n" +
+                "    \"balance\": \"$1,099.93\",\n" +
+                "    \"picture\": \"http://placehold.it/32x32\",\n" +
+                "    \"age\": 37,\n" +
+                "    \"eyeColor\": \"blue\",\n" +
+                "    \"name\": \"Barrera Wilkerson\",\n" +
+                "    \"gender\": \"male\",\n" +
+                "    \"company\": \"VURBO\",\n" +
+                "    \"email\": \"barrerawilkerson@vurbo.com\",\n" +
+                "    \"phone\": \"+1 (817) 429-2473\",\n" +
+                "    \"address\": \"522 Vanderveer Street, Detroit, Wyoming, 4320\",\n" +
+                "    \"about\": \"Et officia aute ullamco magna adipisicing non ut cupidatat cupidatat aliquip. Tempor occaecat ex ad dolore aliquip mollit ea esse ipsum. Est incididunt sunt commodo duis est. Reprehenderit in ut reprehenderit ad culpa ea fugiat et est adipisicing aliquip. Id mollit voluptate qui pariatur officia.\\r\\n\",\n" +
+                "    \"registered\": \"2016-06-29T08:54:14 +07:00\",\n" +
+                "    \"latitude\": -87.548434,\n" +
+                "    \"longitude\": 64.251242,\n" +
+                "    \"tags\": [\n" +
+                "      \"aliqua\",\n" +
+                "      \"ex\",\n" +
+                "      \"sit\",\n" +
+                "      \"magna\",\n" +
+                "      \"dolor\",\n" +
+                "      \"laborum\",\n" +
+                "      \"non\"\n" +
+                "    ],\n" +
+                "    \"friends\": [\n" +
+                "      {\n" +
+                "        \"id\": 0,\n" +
+                "        \"name\": \"Byers Pratt\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 1,\n" +
+                "        \"name\": \"Kennedy Contreras\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 2,\n" +
+                "        \"name\": \"Frazier Monroe\"\n" +
+                "      }\n" +
+                "    ],\n" +
+                "    \"greeting\": \"Hello, Barrera Wilkerson! You have 3 unread messages.\",\n" +
+                "    \"favoriteFruit\": \"banana\"\n" +
+                "  },\n" +
+                "  {\n" +
+                "    \"_id\": \"58309f3b1f506440093a41d1\",\n" +
+                "    \"index\": 1,\n" +
+                "    \"guid\": \"de1a6cc9-f8b3-426e-b68a-cc30e1fff3c1\",\n" +
+                "    \"isActive\": false,\n" +
+                "    \"balance\": \"$3,397.60\",\n" +
+                "    \"picture\": \"http://placehold.it/32x32\",\n" +
+                "    \"age\": 32,\n" +
+                "    \"eyeColor\": \"blue\",\n" +
+                "    \"name\": \"Trisha Morris\",\n" +
+                "    \"gender\": \"female\",\n" +
+                "    \"company\": \"AMTAP\",\n" +
+                "    \"email\": \"trishamorris@amtap.com\",\n" +
+                "    \"phone\": \"+1 (805) 423-3375\",\n" +
+                "    \"address\": \"495 Tampa Court, Libertytown, New Hampshire, 5177\",\n" +
+                "    \"about\": \"Elit culpa Lorem dolor sit laborum ut ullamco ullamco nostrud reprehenderit adipisicing eiusmod. Aliqua quis dolor esse sint. Dolore in excepteur laborum anim ut consectetur. Nisi officia est eu ex ex id. Ipsum duis ullamco ad ut labore dolor. In amet tempor deserunt ullamco velit eu fugiat.\\r\\n\",\n" +
+                "    \"registered\": \"2015-02-08T06:14:19 +08:00\",\n" +
+                "    \"latitude\": -81.956277,\n" +
+                "    \"longitude\": 143.685584,\n" +
+                "    \"tags\": [\n" +
+                "      \"cillum\",\n" +
+                "      \"ullamco\",\n" +
+                "      \"magna\",\n" +
+                "      \"cillum\",\n" +
+                "      \"voluptate\",\n" +
+                "      \"magna\",\n" +
+                "      \"exercitation\"\n" +
+                "    ],\n" +
+                "    \"friends\": [\n" +
+                "      {\n" +
+                "        \"id\": 0,\n" +
+                "        \"name\": \"Fuentes Stout\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 1,\n" +
+                "        \"name\": \"Violet Vargas\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 2,\n" +
+                "        \"name\": \"Schmidt Wilder\"\n" +
+                "      }\n" +
+                "    ],\n" +
+                "    \"greeting\": \"Hello, Trisha Morris! You have 4 unread messages.\",\n" +
+                "    \"favoriteFruit\": \"strawberry\"\n" +
+                "  },\n" +
+                "  {\n" +
+                "    \"_id\": \"58309f3beaef2f31339b3755\",\n" +
+                "    \"index\": 2,\n" +
+                "    \"guid\": \"0bf387b7-abc2-4828-becc-1269928f7c3d\",\n" +
+                "    \"isActive\": false,\n" +
+                "    \"balance\": \"$1,520.64\",\n" +
+                "    \"picture\": \"http://placehold.it/32x32\",\n" +
+                "    \"age\": 37,\n" +
+                "    \"eyeColor\": \"blue\",\n" +
+                "    \"name\": \"Deanna Santiago\",\n" +
+                "    \"gender\": \"female\",\n" +
+                "    \"company\": \"MEGALL\",\n" +
+                "    \"email\": \"deannasantiago@megall.com\",\n" +
+                "    \"phone\": \"+1 (916) 511-2291\",\n" +
+                "    \"address\": \"919 Fayette Street, Homestead, Utah, 8669\",\n" +
+                "    \"about\": \"Sit amet ex quis velit irure Lorem non quis aliquip dolor pariatur nulla Lorem officia. Deserunt officia sit velit labore sint nostrud elit aliquip labore ullamco consectetur id amet. Ullamco duis commodo sit incididunt. Fugiat consectetur ad incididunt officia. Sint cillum minim laborum laboris id cillum est exercitation in eiusmod qui.\\r\\n\",\n" +
+                "    \"registered\": \"2015-11-18T08:39:28 +08:00\",\n" +
+                "    \"latitude\": 79.105701,\n" +
+                "    \"longitude\": -146.901754,\n" +
+                "    \"tags\": [\n" +
+                "      \"non\",\n" +
+                "      \"ullamco\",\n" +
+                "      \"cillum\",\n" +
+                "      \"ipsum\",\n" +
+                "      \"amet\",\n" +
+                "      \"aliqua\",\n" +
+                "      \"aliquip\"\n" +
+                "    ],\n" +
+                "    \"friends\": [\n" +
+                "      {\n" +
+                "        \"id\": 0,\n" +
+                "        \"name\": \"Hanson Anderson\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 1,\n" +
+                "        \"name\": \"Pollard Soto\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 2,\n" +
+                "        \"name\": \"Barlow Campbell\"\n" +
+                "      }\n" +
+                "    ],\n" +
+                "    \"greeting\": \"Hello, Deanna Santiago! You have 7 unread messages.\",\n" +
+                "    \"favoriteFruit\": \"apple\"\n" +
+                "  },\n" +
+                "  {\n" +
+                "    \"_id\": \"58309f3b49a68ad01346f27f\",\n" +
+                "    \"index\": 3,\n" +
+                "    \"guid\": \"d29c0dcc-48fb-4ca4-a63b-b47c0e6d6398\",\n" +
+                "    \"isActive\": false,\n" +
+                "    \"balance\": \"$2,069.96\",\n" +
+                "    \"picture\": \"http://placehold.it/32x32\",\n" +
+                "    \"age\": 29,\n" +
+                "    \"eyeColor\": \"green\",\n" +
+                "    \"name\": \"Brooks Gates\",\n" +
+                "    \"gender\": \"male\",\n" +
+                "    \"company\": \"TERRAGEN\",\n" +
+                "    \"email\": \"brooksgates@terragen.com\",\n" +
+                "    \"phone\": \"+1 (875) 483-2224\",\n" +
+                "    \"address\": \"562 Noll Street, Kipp, Louisiana, 7659\",\n" +
+                "    \"about\": \"Reprehenderit laboris mollit nulla commodo quis laborum commodo. Laborum aliquip laboris officia minim ipsum laborum ipsum reprehenderit quis laboris est sint culpa. Culpa magna aute mollit exercitation.\\r\\n\",\n" +
+                "    \"registered\": \"2016-05-04T10:34:38 +07:00\",\n" +
+                "    \"latitude\": 72.77079,\n" +
+                "    \"longitude\": -134.291768,\n" +
+                "    \"tags\": [\n" +
+                "      \"est\",\n" +
+                "      \"sunt\",\n" +
+                "      \"laboris\",\n" +
+                "      \"ea\",\n" +
+                "      \"proident\",\n" +
+                "      \"aute\",\n" +
+                "      \"excepteur\"\n" +
+                "    ],\n" +
+                "    \"friends\": [\n" +
+                "      {\n" +
+                "        \"id\": 0,\n" +
+                "        \"name\": \"Roxanne Morgan\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 1,\n" +
+                "        \"name\": \"Tamara Kelly\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 2,\n" +
+                "        \"name\": \"Cleveland Bush\"\n" +
+                "      }\n" +
+                "    ],\n" +
+                "    \"greeting\": \"Hello, Brooks Gates! You have 1 unread messages.\",\n" +
+                "    \"favoriteFruit\": \"banana\"\n" +
+                "  },\n" +
+                "  {\n" +
+                "    \"_id\": \"58309f3be746700e9af9a645\",\n" +
+                "    \"index\": 4,\n" +
+                "    \"guid\": \"54382bd6-c476-469d-9e1c-e546f959db51\",\n" +
+                "    \"isActive\": true,\n" +
+                "    \"balance\": \"$2,012.57\",\n" +
+                "    \"picture\": \"http://placehold.it/32x32\",\n" +
+                "    \"age\": 40,\n" +
+                "    \"eyeColor\": \"brown\",\n" +
+                "    \"name\": \"Jackie Thomas\",\n" +
+                "    \"gender\": \"female\",\n" +
+                "    \"company\": \"HINWAY\",\n" +
+                "    \"email\": \"jackiethomas@hinway.com\",\n" +
+                "    \"phone\": \"+1 (843) 470-2096\",\n" +
+                "    \"address\": \"910 Emerson Place, Gwynn, Federated States Of Micronesia, 4688\",\n" +
+                "    \"about\": \"Id cupidatat laboris elit est eiusmod esse nostrud. Ex commodo nisi voluptate est nisi laborum officia sint incididunt pariatur qui deserunt ullamco. Fugiat proident magna ipsum sit sint id adipisicing sit nostrud labore sit officia. Eiusmod exercitation non enim excepteur amet irure ullamco consectetur cupidatat proident Lorem reprehenderit aliquip. Veniam esse dolor Lorem incididunt proident officia enim in incididunt culpa. Mollit voluptate commodo aliquip anim ipsum nostrud ut labore enim labore qui do minim incididunt. Quis irure proident voluptate nisi qui sunt aute duis irure.\\r\\n\",\n" +
+                "    \"registered\": \"2014-08-03T09:21:43 +07:00\",\n" +
+                "    \"latitude\": 84.871256,\n" +
+                "    \"longitude\": 2.043339,\n" +
+                "    \"tags\": [\n" +
+                "      \"tempor\",\n" +
+                "      \"ut\",\n" +
+                "      \"deserunt\",\n" +
+                "      \"esse\",\n" +
+                "      \"nostrud\",\n" +
+                "      \"dolore\",\n" +
+                "      \"ex\"\n" +
+                "    ],\n" +
+                "    \"friends\": [\n" +
+                "      {\n" +
+                "        \"id\": 0,\n" +
+                "        \"name\": \"Lois Walters\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 1,\n" +
+                "        \"name\": \"Brewer Buchanan\"\n" +
+                "      },\n" +
+                "      {\n" +
+                "        \"id\": 2,\n" +
+                "        \"name\": \"Mccormick Fleming\"\n" +
+                "      }\n" +
+                "    ],\n" +
+                "    \"greeting\": \"Hello, Jackie Thomas! You have 2 unread messages.\",\n" +
+                "    \"favoriteFruit\": \"banana\"\n" +
+                "  }\n" +
+                "]";
+
+        JSONArray x1 = (JSONArray) new JSONTokener(new InputStreamReader(this.getClass().getResourceAsStream("/sample-01.json"))).nextValue();
+        JSONArray x2 = (JSONArray) new JSONTokener(ref).nextValue();
+
+        Assert.assertTrue(jsonEquals(x1, x2));
+    }
+
+    private boolean jsonEquals(JSONArray x1, JSONArray x2) throws JSONException {
+        if (x1.length() != x2.length()) {
+            return false;
+        }
+
+        for (int i = 0; i < x1.length(); i++) {
+            Object element1 = x1.get(i);
+            Object element2 = x2.get(i);
+            if (!jsonEquals(element1, element2)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean jsonEquals(JSONObject x1, JSONObject x2) throws JSONException {
+        if (x1.length() != x2.length()) {
+            return false;
+        }
+        Set<String> names = x1.keySet();
+        for (String name : names) {
+            if (!jsonEquals(x1.get(name), x2.get(name))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean jsonEquals(Object element1, Object element2) throws JSONException {
+        if (!element1.getClass().equals(element2.getClass())) {
+            return false;
+        }
+        if (element1 instanceof JSONObject) {
+            return jsonEquals((JSONObject) element1, (JSONObject) element2);
+        }
+        if (element1 instanceof JSONArray) {
+            return jsonEquals((JSONArray) element1, (JSONArray) element2);
+        }
+        return element1.equals(element2);
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/JSONArrayTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONArrayTest.java b/geode-json/src/test/java/org/json/JSONArrayTest.java
new file mode 100755
index 0000000..8f6632b
--- /dev/null
+++ b/geode-json/src/test/java/org/json/JSONArrayTest.java
@@ -0,0 +1,608 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * This black box test was written without inspecting the non-free org.json sourcecode.
+ */
+public class JSONArrayTest {
+    @Test
+    public void testEmptyArray() throws JSONException {
+        JSONArray array = new JSONArray();
+        assertEquals(0, array.length());
+        assertEquals("", array.join(" AND "));
+        try {
+            array.get(0);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.getBoolean(0);
+            fail();
+        } catch (JSONException ignored) {
+        }
+
+        assertEquals("[]", array.toString());
+        assertEquals("[]", array.toString(4));
+
+        // out of bounds is co-opted with defaulting
+        assertTrue(array.isNull(0));
+        assertNull(array.opt(0));
+        assertFalse(array.optBoolean(0));
+        assertTrue(array.optBoolean(0, true));
+
+        // bogus (but documented) behaviour: returns null rather than an empty object!
+        assertNull(array.toJSONObject(new JSONArray()));
+    }
+
+    @Test
+    public void testEqualsAndHashCode() throws JSONException {
+        JSONArray a = new JSONArray();
+        JSONArray b = new JSONArray();
+        assertTrue(a.equals(b));
+        assertEquals("equals() not consistent with hashCode()", a.hashCode(), b.hashCode());
+
+        a.put(true);
+        a.put(false);
+        b.put(true);
+        b.put(false);
+        assertTrue(a.equals(b));
+        assertEquals(a.hashCode(), b.hashCode());
+
+        b.put(true);
+        assertFalse(a.equals(b));
+        assertTrue(a.hashCode() != b.hashCode());
+    }
+
+    @Test
+    public void testBooleans() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(true);
+        array.put(false);
+        array.put(2, false);
+        array.put(3, false);
+        array.put(2, true);
+        assertEquals("[true,false,true,false]", array.toString());
+        assertEquals(4, array.length());
+        assertEquals(Boolean.TRUE, array.get(0));
+        assertEquals(Boolean.FALSE, array.get(1));
+        assertEquals(Boolean.TRUE, array.get(2));
+        assertEquals(Boolean.FALSE, array.get(3));
+        assertFalse(array.isNull(0));
+        assertFalse(array.isNull(1));
+        assertFalse(array.isNull(2));
+        assertFalse(array.isNull(3));
+        assertEquals(true, array.optBoolean(0));
+        assertEquals(false, array.optBoolean(1, true));
+        assertEquals(true, array.optBoolean(2, false));
+        assertEquals(false, array.optBoolean(3));
+        assertEquals("true", array.getString(0));
+        assertEquals("false", array.getString(1));
+        assertEquals("true", array.optString(2));
+        assertEquals("false", array.optString(3, "x"));
+        assertEquals("[\n     true,\n     false,\n     true,\n     false\n]", array.toString(5));
+
+        JSONArray other = new JSONArray();
+        other.put(true);
+        other.put(false);
+        other.put(true);
+        other.put(false);
+        assertTrue(array.equals(other));
+        other.put(true);
+        assertFalse(array.equals(other));
+
+        other = new JSONArray();
+        other.put("true");
+        other.put("false");
+        other.put("truE");
+        other.put("FALSE");
+        assertFalse(array.equals(other));
+        assertFalse(other.equals(array));
+        assertEquals(true, other.getBoolean(0));
+        assertEquals(false, other.optBoolean(1, true));
+        assertEquals(true, other.optBoolean(2));
+        assertEquals(false, other.getBoolean(3));
+    }
+
+    // http://code.google.com/p/android/issues/detail?id=16411
+    @Test
+    public void testCoerceStringToBoolean() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put("maybe");
+        try {
+            array.getBoolean(0);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals(false, array.optBoolean(0));
+        assertEquals(true, array.optBoolean(0, true));
+    }
+
+    @Test
+    public void testNulls() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(3, null);
+        array.put(0, JSONObject.NULL);
+        assertEquals(4, array.length());
+        assertEquals("[null,null,null,null]", array.toString());
+
+        // there's 2 ways to represent null; each behaves differently!
+        assertEquals(JSONObject.NULL, array.get(0));
+        try {
+            array.get(1);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.get(2);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.get(3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals(JSONObject.NULL, array.opt(0));
+        assertEquals(null, array.opt(1));
+        assertEquals(null, array.opt(2));
+        assertEquals(null, array.opt(3));
+        assertTrue(array.isNull(0));
+        assertTrue(array.isNull(1));
+        assertTrue(array.isNull(2));
+        assertTrue(array.isNull(3));
+        assertEquals("null", array.optString(0));
+        assertEquals("", array.optString(1));
+        assertEquals("", array.optString(2));
+        assertEquals("", array.optString(3));
+    }
+
+    /**
+     * Our behaviour is questioned by this bug:
+     * http://code.google.com/p/android/issues/detail?id=7257
+     */
+    @Test
+    public void testParseNullYieldsJSONObjectNull() throws JSONException {
+        JSONArray array = new JSONArray("[\"null\",null]");
+        array.put(null);
+        assertEquals("null", array.get(0));
+        assertEquals(JSONObject.NULL, array.get(1));
+        try {
+            array.get(2);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals("null", array.getString(0));
+        assertEquals("null", array.getString(1));
+        try {
+            array.getString(2);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testNumbers() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(Double.MIN_VALUE);
+        array.put(9223372036854775806L);
+        array.put(Double.MAX_VALUE);
+        array.put(-0d);
+        assertEquals(4, array.length());
+
+        // toString() and getString(int) return different values for -0d
+        assertEquals("[4.9E-324,9223372036854775806,1.7976931348623157E308,-0]", array.toString());
+
+        assertEquals(Double.MIN_VALUE, array.get(0));
+        assertEquals(9223372036854775806L, array.get(1));
+        assertEquals(Double.MAX_VALUE, array.get(2));
+        assertEquals(-0d, array.get(3));
+        assertEquals(Double.MIN_VALUE, array.getDouble(0), 0);
+        assertEquals(9.223372036854776E18, array.getDouble(1), 0);
+        assertEquals(Double.MAX_VALUE, array.getDouble(2), 0);
+        assertEquals(-0d, array.getDouble(3), 0);
+        assertEquals(0, array.getLong(0));
+        assertEquals(9223372036854775806L, array.getLong(1));
+        assertEquals(Long.MAX_VALUE, array.getLong(2));
+        assertEquals(0, array.getLong(3));
+        assertEquals(0, array.getInt(0));
+        assertEquals(-2, array.getInt(1));
+        assertEquals(Integer.MAX_VALUE, array.getInt(2));
+        assertEquals(0, array.getInt(3));
+        assertEquals(Double.MIN_VALUE, array.opt(0));
+        assertEquals(Double.MIN_VALUE, array.optDouble(0), 0);
+        assertEquals(0, array.optLong(0, 1L));
+        assertEquals(0, array.optInt(0, 1));
+        assertEquals("4.9E-324", array.getString(0));
+        assertEquals("9223372036854775806", array.getString(1));
+        assertEquals("1.7976931348623157E308", array.getString(2));
+        assertEquals("-0.0", array.getString(3));
+
+        JSONArray other = new JSONArray();
+        other.put(Double.MIN_VALUE);
+        other.put(9223372036854775806L);
+        other.put(Double.MAX_VALUE);
+        other.put(-0d);
+        assertTrue(array.equals(other));
+        other.put(0, 0L);
+        assertFalse(array.equals(other));
+    }
+
+    @Test
+    public void testStrings() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put("true");
+        array.put("5.5");
+        array.put("9223372036854775806");
+        array.put("null");
+        array.put("5\"8' tall");
+        assertEquals(5, array.length());
+        assertEquals("[\"true\",\"5.5\",\"9223372036854775806\",\"null\",\"5\\\"8' tall\"]",
+                array.toString());
+
+        // although the documentation doesn't mention it, join() escapes text and wraps
+        // strings in quotes
+        assertEquals("\"true\" \"5.5\" \"9223372036854775806\" \"null\" \"5\\\"8' tall\"",
+                array.join(" "));
+
+        assertEquals("true", array.get(0));
+        assertEquals("null", array.getString(3));
+        assertEquals("5\"8' tall", array.getString(4));
+        assertEquals("true", array.opt(0));
+        assertEquals("5.5", array.optString(1));
+        assertEquals("9223372036854775806", array.optString(2, null));
+        assertEquals("null", array.optString(3, "-1"));
+        assertFalse(array.isNull(0));
+        assertFalse(array.isNull(3));
+
+        assertEquals(true, array.getBoolean(0));
+        assertEquals(true, array.optBoolean(0));
+        assertEquals(true, array.optBoolean(0, false));
+        assertEquals(0, array.optInt(0));
+        assertEquals(-2, array.optInt(0, -2));
+
+        assertEquals(5.5d, array.getDouble(1), 0);
+        assertEquals(5L, array.getLong(1));
+        assertEquals(5, array.getInt(1));
+        assertEquals(5, array.optInt(1, 3));
+
+        // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
+        // double and then converting that to a long. This is consistent with JavaScript.
+        assertEquals(9223372036854775807L, array.getLong(2));
+        assertEquals(9.223372036854776E18, array.getDouble(2), 0);
+        assertEquals(Integer.MAX_VALUE, array.getInt(2));
+
+        assertFalse(array.isNull(3));
+        try {
+            array.getDouble(3);
+            fail();
+        } catch (JSONException e) {
+            // expected
+        }
+        assertEquals(Double.NaN, array.optDouble(3), 0);
+        assertEquals(-1.0d, array.optDouble(3, -1.0d), 0);
+    }
+
+    @Test
+    public void testJoin() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(null);
+        assertEquals("null", array.join(" & "));
+        array.put("\"");
+        assertEquals("null & \"\\\"\"", array.join(" & "));
+        array.put(5);
+        assertEquals("null & \"\\\"\" & 5", array.join(" & "));
+        array.put(true);
+        assertEquals("null & \"\\\"\" & 5 & true", array.join(" & "));
+        array.put(new JSONArray(Arrays.asList(true, false)));
+        assertEquals("null & \"\\\"\" & 5 & true & [true,false]", array.join(" & "));
+        array.put(new JSONObject(Collections.singletonMap("x", 6)));
+        assertEquals("null & \"\\\"\" & 5 & true & [true,false] & {\"x\":6}", array.join(" & "));
+    }
+
+    @Test
+    public void testJoinWithNull() throws JSONException {
+        JSONArray array = new JSONArray(Arrays.asList(5, 6));
+        assertEquals("5null6", array.join(null));
+    }
+
+    @Test
+    public void testJoinWithSpecialCharacters() throws JSONException {
+        JSONArray array = new JSONArray(Arrays.asList(5, 6));
+        assertEquals("5\"6", array.join("\""));
+    }
+
+    @Test
+    public void testToJSONObject() throws JSONException {
+        JSONArray keys = new JSONArray();
+        keys.put("a");
+        keys.put("b");
+
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        values.put(false);
+
+        JSONObject object = values.toJSONObject(keys);
+        assertEquals(5.5d, object.get("a"));
+        assertEquals(false, object.get("b"));
+
+        keys.put(0, "a");
+        values.put(0, 11.0d);
+        assertEquals(5.5d, object.get("a"));
+    }
+
+    @Test
+    public void testToJSONObjectWithNulls() throws JSONException {
+        JSONArray keys = new JSONArray();
+        keys.put("a");
+        keys.put("b");
+
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        values.put(null);
+
+        // null values are stripped!
+        JSONObject object = values.toJSONObject(keys);
+        assertEquals(1, object.length());
+        assertFalse(object.has("b"));
+        assertEquals("{\"a\":5.5}", object.toString());
+    }
+
+    @Test
+    public void testToJSONObjectMoreNamesThanValues() throws JSONException {
+        JSONArray keys = new JSONArray();
+        keys.put("a");
+        keys.put("b");
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        JSONObject object = values.toJSONObject(keys);
+        assertEquals(1, object.length());
+        assertEquals(5.5d, object.get("a"));
+    }
+
+    @Test
+    public void testToJSONObjectMoreValuesThanNames() throws JSONException {
+        JSONArray keys = new JSONArray();
+        keys.put("a");
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        values.put(11.0d);
+        JSONObject object = values.toJSONObject(keys);
+        assertEquals(1, object.length());
+        assertEquals(5.5d, object.get("a"));
+    }
+
+    @Test
+    public void testToJSONObjectNullKey() throws JSONException {
+        JSONArray keys = new JSONArray();
+        keys.put(JSONObject.NULL);
+        JSONArray values = new JSONArray();
+        values.put(5.5d);
+        JSONObject object = values.toJSONObject(keys);
+        assertEquals(1, object.length());
+        assertEquals(5.5d, object.get("null"));
+    }
+
+    @Test
+    public void testPutUnsupportedNumbers() throws JSONException {
+        JSONArray array = new JSONArray();
+
+        try {
+            array.put(Double.NaN);
+            fail();
+        } catch (JSONException e) {
+            // expected
+        }
+        try {
+            array.put(0, Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException e) {
+            // expected
+        }
+        try {
+            array.put(0, Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testPutUnsupportedNumbersAsObject() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(Double.valueOf(Double.NaN));
+        array.put(Double.valueOf(Double.NEGATIVE_INFINITY));
+        array.put(Double.valueOf(Double.POSITIVE_INFINITY));
+        assertEquals(null, array.toString());
+    }
+
+    /**
+     * Although JSONArray is usually defensive about which numbers it accepts,
+     * it doesn't check inputs in its constructor.
+     */
+    @Test
+    public void testCreateWithUnsupportedNumbers() throws JSONException {
+        JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
+        assertEquals(2, array.length());
+        assertEquals(5.5, array.getDouble(0), 0);
+        assertEquals(Double.NaN, array.getDouble(1), 0);
+    }
+
+    @Test
+    public void testToStringWithUnsupportedNumbers() throws JSONException {
+        // when the array contains an unsupported number, toString returns null!
+        JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
+        assertNull(array.toString());
+    }
+
+    @Test
+    public void testListConstructorCopiesContents() throws JSONException {
+        // have to use asList instead of Collections.singleton() to allow mutation
+        //noinspection ArraysAsListWithZeroOrOneArgument
+        List<Object> contents = Arrays.<Object>asList(5);
+        JSONArray array = new JSONArray(contents);
+        contents.set(0, 10);
+        assertEquals(5, array.get(0));
+    }
+
+    @Test
+    public void testTokenerConstructor() throws JSONException {
+        JSONArray object = new JSONArray(new JSONTokener("[false]"));
+        assertEquals(1, object.length());
+        assertEquals(false, object.get(0));
+    }
+
+    @Test
+    public void testTokenerConstructorWrongType() throws JSONException {
+        try {
+            new JSONArray(new JSONTokener("{\"foo\": false}"));
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testTokenerConstructorNull() throws JSONException {
+        try {
+            new JSONArray((JSONTokener) null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    @Test
+    public void testTokenerConstructorParseFail() {
+        try {
+            new JSONArray(new JSONTokener("["));
+            fail();
+        } catch (JSONException ignored) {
+        } catch (StackOverflowError e) {
+            fail("Stack overflowed on input: \"[\"");
+        }
+    }
+
+    @Test
+    public void testStringConstructor() throws JSONException {
+        JSONArray object = new JSONArray("[false]");
+        assertEquals(1, object.length());
+        assertEquals(false, object.get(0));
+    }
+
+    @Test
+    public void testStringConstructorWrongType() throws JSONException {
+        try {
+            new JSONArray("{\"foo\": false}");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testStringConstructorNull() throws JSONException {
+        try {
+            new JSONArray((String) null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    @Test
+    public void testStringConstructorParseFail() {
+        try {
+            new JSONArray("[");
+            fail();
+        } catch (JSONException ignored) {
+        } catch (StackOverflowError e) {
+            fail("Stack overflowed on input: \"[\"");
+        }
+    }
+
+    @Test
+    public void testCreate() throws JSONException {
+        JSONArray array = new JSONArray(Arrays.asList(5.5, true));
+        assertEquals(2, array.length());
+        assertEquals(5.5, array.getDouble(0), 0.0);
+        assertEquals(true, array.get(1));
+        assertEquals("[5.5,true]", array.toString());
+    }
+
+    @Test
+    public void testAccessOutOfBounds() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put("foo");
+        assertEquals(null, array.opt(3));
+        assertEquals(null, array.opt(-3));
+        assertEquals("", array.optString(3));
+        assertEquals("", array.optString(-3));
+        try {
+            array.get(3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.get(-3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.getString(3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            array.getString(-3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void test_remove() throws Exception {
+        JSONArray a = new JSONArray();
+        assertEquals(null, a.remove(-1));
+        assertEquals(null, a.remove(0));
+
+        a.put("hello");
+        assertEquals(null, a.remove(-1));
+        assertEquals(null, a.remove(1));
+        assertEquals("hello", a.remove(0));
+        assertEquals(null, a.remove(0));
+    }
+
+    enum MyEnum { A, B, C }
+
+    // https://code.google.com/p/android/issues/detail?id=62539
+    // but changed in open-json to return toString for all enums
+    @Test
+    public void testEnums() throws Exception {
+        // This works because it's in java.* and any class in there falls back to toString.
+        JSONArray a1 = new JSONArray(java.lang.annotation.RetentionPolicy.values());
+        assertEquals("[\"SOURCE\",\"CLASS\",\"RUNTIME\"]", a1.toString());
+
+        // This doesn't because it's not.
+        JSONArray a2 = new JSONArray(MyEnum.values());
+        assertEquals("[\"A\",\"B\",\"C\"]", a2.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONFunctionTestObject.java b/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
new file mode 100755
index 0000000..fe18ab6
--- /dev/null
+++ b/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
@@ -0,0 +1,17 @@
+package org.json;
+
+/**
+ * Class to test the function hack
+ */
+public class JSONFunctionTestObject {
+    private String value;
+
+    public JSONFunctionTestObject(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
+}
\ No newline at end of file


[28/34] geode git commit: GEODE-2545: NPE during lucene query execution when cache is closing or region is destroyed

Posted by kl...@apache.org.
GEODE-2545: NPE during lucene query execution when cache is closing or region is destroyed

* Throw an InternalFunctionTargetInvocationException if executing a query while cache is closing


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c4a5ab28
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c4a5ab28
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c4a5ab28

Branch: refs/heads/GEODE-4160-mockito
Commit: c4a5ab284baba371418cb7a389cb0f327d8becdc
Parents: 8ff2fd4
Author: Jason Huynh <hu...@gmail.com>
Authored: Mon Feb 27 10:02:23 2017 -0800
Committer: Jason Huynh <hu...@gmail.com>
Committed: Mon Feb 27 10:02:23 2017 -0800

----------------------------------------------------------------------
 .../distributed/LuceneQueryFunction.java        |  4 ++++
 .../LuceneQueryFunctionJUnitTest.java           | 25 +++++++++-----------
 2 files changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c4a5ab28/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
index e0a0a22..dd70480 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
@@ -75,6 +75,10 @@ public class LuceneQueryFunction implements Function, InternalEntity {
     LuceneService service = LuceneServiceProvider.get(region.getCache());
     LuceneIndexImpl index =
         (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
+    if (index == null) {
+      throw new InternalFunctionInvocationTargetException(
+          "Index for Region:" + region.getFullPath() + " was not found");
+    }
     RepositoryManager repoManager = index.getRepositoryManager();
     LuceneIndexStats stats = index.getIndexStats();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c4a5ab28/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
index 0d06cab..6a9af9b 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
@@ -208,20 +208,17 @@ public class LuceneQueryFunctionJUnitTest {
     function.execute(mockContext);
   }
 
-  // Disabled currently as we are retrying the function if a bucket is not found
-  // @Test(expected = FunctionException.class)
-  // public void testBucketNotFound() throws Exception {
-  // when(mockContext.getDataSet()).thenReturn(mockRegion);
-  // when(mockContext.getArguments()).thenReturn(searchArgs);
-  // when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
-  // when(mockRepoManager.getRepositories(eq(mockContext)))
-  // .thenThrow(new BucketNotFoundException(""));
-  // LuceneQueryFunction function = new LuceneQueryFunction();
-  //
-  // function.execute(mockContext);
-  //
-  // verify(mockResultSender).sendException(any(BucketNotFoundException.class));
-  // }
+  @Test(expected = FunctionException.class)
+  public void whenServiceReturnsNullIndexDuringQueryExecutionFunctionExceptionShouldBeThrown()
+      throws Exception {
+    when(mockContext.getDataSet()).thenReturn(mockRegion);
+    when(mockContext.getArguments()).thenReturn(searchArgs);
+    LuceneQueryFunction function = new LuceneQueryFunction();
+
+    when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(null);
+
+    function.execute(mockContext);
+  }
 
   @Test(expected = FunctionException.class)
   public void testReduceError() throws Exception {


[12/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/JSONStringerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONStringerTest.java b/geode-json/src/test/java/org/json/JSONStringerTest.java
index 7c7362d..b3a8188 100755
--- a/geode-json/src/test/java/org/json/JSONStringerTest.java
+++ b/geode-json/src/test/java/org/json/JSONStringerTest.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -27,395 +25,392 @@ import static org.junit.Assert.*;
  */
 public class JSONStringerTest {
 
-    @Test
-    public void testJSONFunctionHackTest() {
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.key("key");
-        stringer.value(new JSONFunctionTestObject("window.test('foo' + \"bar\")"));
-        stringer.endObject();
-        assertEquals("{\"key\":window.test('foo' + \"bar\")}", stringer.toString());
+  @Test
+  public void testJSONFunctionHackTest() {
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.key("key");
+    stringer.value(new JSONFunctionTestObject("window.test('foo' + \"bar\")"));
+    stringer.endObject();
+    assertEquals("{\"key\":window.test('foo' + \"bar\")}", stringer.toString());
+  }
+
+  @Test
+  public void testEmptyStringer() {
+    // why isn't this the empty string?
+    assertNull(new JSONStringer().toString());
+  }
+
+  @Test
+  public void testValueJSONNull() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(JSONObject.NULL);
+    stringer.endArray();
+    assertEquals("[null]", stringer.toString());
+  }
+
+  @Test
+  public void testEmptyObject() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.endObject();
+    assertEquals("{}", stringer.toString());
+  }
+
+  @Test
+  public void testEmptyArray() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.endArray();
+    assertEquals("[]", stringer.toString());
+  }
+
+  @Test
+  public void testArray() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(false);
+    stringer.value(5.0);
+    stringer.value(5L);
+    stringer.value("five");
+    stringer.value(null);
+    stringer.endArray();
+    assertEquals("[false,5,5,\"five\",null]", stringer.toString());
+  }
+
+  @Test
+  public void testValueObjectMethods() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(Boolean.FALSE);
+    stringer.value(Double.valueOf(5.0));
+    stringer.value(Long.valueOf(5L));
+    stringer.endArray();
+    assertEquals("[false,5,5]", stringer.toString());
+  }
+
+  @Test
+  public void testKeyValue() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.key("a").value(false);
+    stringer.key("b").value(5.0);
+    stringer.key("c").value(5L);
+    stringer.key("d").value("five");
+    stringer.key("e").value(null);
+    stringer.endObject();
+    assertEquals("{\"a\":false," + "\"b\":5," + "\"c\":5," + "\"d\":\"five\"," + "\"e\":null}",
+        stringer.toString());
+  }
+
+  /**
+   * Test what happens when extreme values are emitted. Such values are likely to be rounded during
+   * parsing.
+   */
+  @Test
+  public void testNumericRepresentations() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(Long.MAX_VALUE);
+    stringer.value(Double.MIN_VALUE);
+    stringer.endArray();
+    assertEquals("[9223372036854775807,4.9E-324]", stringer.toString());
+  }
+
+  @Test
+  public void testWeirdNumbers() throws JSONException {
+    try {
+      new JSONStringer().array().value(Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testEmptyStringer() {
-        // why isn't this the empty string?
-        assertNull(new JSONStringer().toString());
+    try {
+      new JSONStringer().array().value(Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testValueJSONNull() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(JSONObject.NULL);
-        stringer.endArray();
-        assertEquals("[null]", stringer.toString());
+    try {
+      new JSONStringer().array().value(Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
     }
 
-    @Test
-    public void testEmptyObject() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.endObject();
-        assertEquals("{}", stringer.toString());
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(-0.0d);
+    stringer.value(0.0d);
+    stringer.endArray();
+    assertEquals("[-0,0]", stringer.toString());
+  }
+
+  @Test
+  public void testMismatchedScopes() {
+    try {
+      new JSONStringer().key("a");
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testEmptyArray() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.endArray();
-        assertEquals("[]", stringer.toString());
+    try {
+      new JSONStringer().value("a");
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testArray() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(false);
-        stringer.value(5.0);
-        stringer.value(5L);
-        stringer.value("five");
-        stringer.value(null);
-        stringer.endArray();
-        assertEquals("[false,5,5,\"five\",null]", stringer.toString());
+    try {
+      new JSONStringer().endObject();
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testValueObjectMethods() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(Boolean.FALSE);
-        stringer.value(Double.valueOf(5.0));
-        stringer.value(Long.valueOf(5L));
-        stringer.endArray();
-        assertEquals("[false,5,5]", stringer.toString());
+    try {
+      new JSONStringer().endArray();
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testKeyValue() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.key("a").value(false);
-        stringer.key("b").value(5.0);
-        stringer.key("c").value(5L);
-        stringer.key("d").value("five");
-        stringer.key("e").value(null);
-        stringer.endObject();
-        assertEquals("{\"a\":false," +
-                "\"b\":5," +
-                "\"c\":5," +
-                "\"d\":\"five\"," +
-                "\"e\":null}", stringer.toString());
+    try {
+      new JSONStringer().array().endObject();
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    /**
-     * Test what happens when extreme values are emitted. Such values are likely
-     * to be rounded during parsing.
-     */
-    @Test
-    public void testNumericRepresentations() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(Long.MAX_VALUE);
-        stringer.value(Double.MIN_VALUE);
-        stringer.endArray();
-        assertEquals("[9223372036854775807,4.9E-324]", stringer.toString());
+    try {
+      new JSONStringer().object().endArray();
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testWeirdNumbers() throws JSONException {
-        try {
-            new JSONStringer().array().value(Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().array().value(Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().array().value(Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(-0.0d);
-        stringer.value(0.0d);
-        stringer.endArray();
-        assertEquals("[-0,0]", stringer.toString());
+    try {
+      new JSONStringer().object().key("a").key("a");
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testMismatchedScopes() {
-        try {
-            new JSONStringer().key("a");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().value("a");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().endObject();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().endArray();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().array().endObject();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().object().endArray();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().object().key("a").key("a");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONStringer().object().value(false);
-            fail();
-        } catch (JSONException ignored) {
-        }
+    try {
+      new JSONStringer().object().value(false);
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testNullKey() {
-        try {
-            new JSONStringer().object().key(null);
-            fail();
-        } catch (JSONException ignored) {
-        }
+  }
+
+  @Test
+  public void testNullKey() {
+    try {
+      new JSONStringer().object().key(null);
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testRepeatedKey() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.key("a").value(true);
-        stringer.key("a").value(false);
-        stringer.endObject();
-        // JSONStringer doesn't attempt to detect duplicates
-        assertEquals("{\"a\":true,\"a\":false}", stringer.toString());
+  }
+
+  @Test
+  public void testRepeatedKey() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.key("a").value(true);
+    stringer.key("a").value(false);
+    stringer.endObject();
+    // JSONStringer doesn't attempt to detect duplicates
+    assertEquals("{\"a\":true,\"a\":false}", stringer.toString());
+  }
+
+  @Test
+  public void testEmptyKey() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.key("").value(false);
+    stringer.endObject();
+    assertEquals("{\"\":false}", stringer.toString()); // legit behaviour!
+  }
+
+  @Test
+  public void testEscaping() throws JSONException {
+    assertEscapedAllWays("a", "a");
+    assertEscapedAllWays("a\\\"", "a\"");
+    assertEscapedAllWays("\\\"", "\"");
+    assertEscapedAllWays(":", ":");
+    assertEscapedAllWays(",", ",");
+    assertEscapedAllWays("\\b", "\b");
+    assertEscapedAllWays("\\f", "\f");
+    assertEscapedAllWays("\\n", "\n");
+    assertEscapedAllWays("\\r", "\r");
+    assertEscapedAllWays("\\t", "\t");
+    assertEscapedAllWays(" ", " ");
+    assertEscapedAllWays("\\\\", "\\");
+    assertEscapedAllWays("{", "{");
+    assertEscapedAllWays("}", "}");
+    assertEscapedAllWays("[", "[");
+    assertEscapedAllWays("]", "]");
+    assertEscapedAllWays("\\u0000", "\0");
+    assertEscapedAllWays("\\u0019", "\u0019");
+    assertEscapedAllWays(" ", "\u0020");
+    assertEscapedAllWays("<\\/foo>", "</foo>");
+  }
+
+  private void assertEscapedAllWays(String escaped, String original) throws JSONException {
+    assertEquals("{\"" + escaped + "\":false}",
+        new JSONStringer().object().key(original).value(false).endObject().toString());
+    assertEquals("{\"a\":\"" + escaped + "\"}",
+        new JSONStringer().object().key("a").value(original).endObject().toString());
+    assertEquals("[\"" + escaped + "\"]",
+        new JSONStringer().array().value(original).endArray().toString());
+    assertEquals("\"" + escaped + "\"", JSONObject.quote(original));
+  }
+
+  @Test
+  public void testJSONArrayAsValue() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(false);
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.value(array);
+    stringer.endArray();
+    assertEquals("[[false]]", stringer.toString());
+  }
+
+  @Test
+  public void testJSONObjectAsValue() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("a", false);
+    JSONStringer stringer = new JSONStringer();
+    stringer.object();
+    stringer.key("b").value(object);
+    stringer.endObject();
+    assertEquals("{\"b\":{\"a\":false}}", stringer.toString());
+  }
+
+  @Test
+  public void testArrayNestingMaxDepthSupports20() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.array();
     }
-
-    @Test
-    public void testEmptyKey() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.key("").value(false);
-        stringer.endObject();
-        assertEquals("{\"\":false}", stringer.toString()); // legit behaviour!
+    for (int i = 0; i < 20; i++) {
+      stringer.endArray();
     }
+    assertEquals("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]", stringer.toString());
 
-    @Test
-    public void testEscaping() throws JSONException {
-        assertEscapedAllWays("a", "a");
-        assertEscapedAllWays("a\\\"", "a\"");
-        assertEscapedAllWays("\\\"", "\"");
-        assertEscapedAllWays(":", ":");
-        assertEscapedAllWays(",", ",");
-        assertEscapedAllWays("\\b", "\b");
-        assertEscapedAllWays("\\f", "\f");
-        assertEscapedAllWays("\\n", "\n");
-        assertEscapedAllWays("\\r", "\r");
-        assertEscapedAllWays("\\t", "\t");
-        assertEscapedAllWays(" ", " ");
-        assertEscapedAllWays("\\\\", "\\");
-        assertEscapedAllWays("{", "{");
-        assertEscapedAllWays("}", "}");
-        assertEscapedAllWays("[", "[");
-        assertEscapedAllWays("]", "]");
-        assertEscapedAllWays("\\u0000", "\0");
-        assertEscapedAllWays("\\u0019", "\u0019");
-        assertEscapedAllWays(" ", "\u0020");
-        assertEscapedAllWays("<\\/foo>", "</foo>");
+    stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.array();
     }
-
-    private void assertEscapedAllWays(String escaped, String original) throws JSONException {
-        assertEquals("{\"" + escaped + "\":false}",
-                new JSONStringer().object().key(original).value(false).endObject().toString());
-        assertEquals("{\"a\":\"" + escaped + "\"}",
-                new JSONStringer().object().key("a").value(original).endObject().toString());
-        assertEquals("[\"" + escaped + "\"]",
-                new JSONStringer().array().value(original).endArray().toString());
-        assertEquals("\"" + escaped + "\"", JSONObject.quote(original));
+  }
+
+  @Test
+  public void testObjectNestingMaxDepthSupports20() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.object();
+      stringer.key("a");
     }
-
-    @Test
-    public void testJSONArrayAsValue() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(false);
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.value(array);
-        stringer.endArray();
-        assertEquals("[[false]]", stringer.toString());
+    stringer.value(false);
+    for (int i = 0; i < 20; i++) {
+      stringer.endObject();
     }
-
-    @Test
-    public void testJSONObjectAsValue() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("a", false);
-        JSONStringer stringer = new JSONStringer();
-        stringer.object();
-        stringer.key("b").value(object);
-        stringer.endObject();
-        assertEquals("{\"b\":{\"a\":false}}", stringer.toString());
+    assertEquals("{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":"
+        + "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":false"
+        + "}}}}}}}}}}}}}}}}}}}}", stringer.toString());
+
+    stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.object();
+      stringer.key("a");
     }
-
-    @Test
-    public void testArrayNestingMaxDepthSupports20() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.array();
-        }
-        for (int i = 0; i < 20; i++) {
-            stringer.endArray();
-        }
-        assertEquals("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]", stringer.toString());
-
-        stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.array();
-        }
+  }
+
+  @Test
+  public void testMixedMaxDepthSupports20() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    for (int i = 0; i < 20; i += 2) {
+      stringer.array();
+      stringer.object();
+      stringer.key("a");
     }
-
-    @Test
-    public void testObjectNestingMaxDepthSupports20() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.object();
-            stringer.key("a");
-        }
-        stringer.value(false);
-        for (int i = 0; i < 20; i++) {
-            stringer.endObject();
-        }
-        assertEquals("{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":" +
-                "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":false" +
-                "}}}}}}}}}}}}}}}}}}}}", stringer.toString());
-
-        stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.object();
-            stringer.key("a");
-        }
+    stringer.value(false);
+    for (int i = 0; i < 20; i += 2) {
+      stringer.endObject();
+      stringer.endArray();
     }
-
-    @Test
-    public void testMixedMaxDepthSupports20() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        for (int i = 0; i < 20; i += 2) {
-            stringer.array();
-            stringer.object();
-            stringer.key("a");
-        }
-        stringer.value(false);
-        for (int i = 0; i < 20; i += 2) {
-            stringer.endObject();
-            stringer.endArray();
-        }
-        assertEquals("[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":" +
-                "[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":false" +
-                "}]}]}]}]}]}]}]}]}]}]", stringer.toString());
-
-        stringer = new JSONStringer();
-        for (int i = 0; i < 20; i += 2) {
-            stringer.array();
-            stringer.object();
-            stringer.key("a");
-        }
+    assertEquals("[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":"
+        + "[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":false" + "}]}]}]}]}]}]}]}]}]}]",
+        stringer.toString());
+
+    stringer = new JSONStringer();
+    for (int i = 0; i < 20; i += 2) {
+      stringer.array();
+      stringer.object();
+      stringer.key("a");
     }
+  }
 
-    @Test
-    public void testMaxDepthWithArrayValue() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(false);
-
-        JSONStringer stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.array();
-        }
-        stringer.value(array);
-        for (int i = 0; i < 20; i++) {
-            stringer.endArray();
-        }
-        assertEquals("[[[[[[[[[[[[[[[[[[[[[false]]]]]]]]]]]]]]]]]]]]]", stringer.toString());
-    }
+  @Test
+  public void testMaxDepthWithArrayValue() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(false);
 
-    @Test
-    public void testMaxDepthWithObjectValue() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("a", false);
-        JSONStringer stringer = new JSONStringer();
-        for (int i = 0; i < 20; i++) {
-            stringer.object();
-            stringer.key("b");
-        }
-        stringer.value(object);
-        for (int i = 0; i < 20; i++) {
-            stringer.endObject();
-        }
-        assertEquals("{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":" +
-                "{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":" +
-                "{\"a\":false}}}}}}}}}}}}}}}}}}}}}", stringer.toString());
+    JSONStringer stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.array();
     }
-
-    @Test
-    public void testMultipleRoots() throws JSONException {
-        JSONStringer stringer = new JSONStringer();
-        stringer.array();
-        stringer.endArray();
-        try {
-            stringer.object();
-            fail();
-        } catch (JSONException ignored) {
-        }
+    stringer.value(array);
+    for (int i = 0; i < 20; i++) {
+      stringer.endArray();
     }
-
-    @Test
-    public void testEnums() {
-        JSONObject x = new JSONObject();
-        x.put("a", TimeUnit.SECONDS);
-        x.put("b", "xyx");
-        JSONStringer s = new JSONStringer();
-        s.array();
-        s.value(x);
-        s.endArray();
-        assertEquals("[{\"a\":\"SECONDS\",\"b\":\"xyx\"}]", s.toString());
+    assertEquals("[[[[[[[[[[[[[[[[[[[[[false]]]]]]]]]]]]]]]]]]]]]", stringer.toString());
+  }
+
+  @Test
+  public void testMaxDepthWithObjectValue() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("a", false);
+    JSONStringer stringer = new JSONStringer();
+    for (int i = 0; i < 20; i++) {
+      stringer.object();
+      stringer.key("b");
     }
-
-    @Test
-    public void testJsonString() {
-        JSONObject x = new JSONObject();
-        x.put("a", new Goo());
-        JSONStringer s = new JSONStringer();
-        s.array();
-        s.value(x);
-        s.endArray();
-        // note lack of quotes
-        assertEquals("[{\"a\":fffooo}]", s.toString());
+    stringer.value(object);
+    for (int i = 0; i < 20; i++) {
+      stringer.endObject();
     }
-
-    private static class Goo implements JSONString {
-        @Override
-        public String toJSONString() {
-            return "fffooo";
-        }
+    assertEquals("{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":"
+        + "{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":"
+        + "{\"a\":false}}}}}}}}}}}}}}}}}}}}}", stringer.toString());
+  }
+
+  @Test
+  public void testMultipleRoots() throws JSONException {
+    JSONStringer stringer = new JSONStringer();
+    stringer.array();
+    stringer.endArray();
+    try {
+      stringer.object();
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testEnums() {
+    JSONObject x = new JSONObject();
+    x.put("a", TimeUnit.SECONDS);
+    x.put("b", "xyx");
+    JSONStringer s = new JSONStringer();
+    s.array();
+    s.value(x);
+    s.endArray();
+    assertEquals("[{\"a\":\"SECONDS\",\"b\":\"xyx\"}]", s.toString());
+  }
+
+  @Test
+  public void testJsonString() {
+    JSONObject x = new JSONObject();
+    x.put("a", new Goo());
+    JSONStringer s = new JSONStringer();
+    s.array();
+    s.value(x);
+    s.endArray();
+    // note lack of quotes
+    assertEquals("[{\"a\":fffooo}]", s.toString());
+  }
+
+  private static class Goo implements JSONString {
+    @Override
+    public String toJSONString() {
+      return "fffooo";
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/JSONTokenerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONTokenerTest.java b/geode-json/src/test/java/org/json/JSONTokenerTest.java
index 9975177..f68b3ce 100755
--- a/geode-json/src/test/java/org/json/JSONTokenerTest.java
+++ b/geode-json/src/test/java/org/json/JSONTokenerTest.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -24,598 +22,595 @@ import junit.framework.TestCase;
  */
 public class JSONTokenerTest extends TestCase {
 
-    public void testNulls() throws JSONException {
-        // JSONTokener accepts null, only to fail later on almost all APIs!
-        new JSONTokener((String) null).back();
-
-        try {
-            new JSONTokener((String) null).more();
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).next();
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).next(3);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).next('A');
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).nextClean();
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).nextString('"');
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).nextTo('A');
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).nextTo("ABC");
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).nextValue();
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).skipPast("ABC");
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        try {
-            new JSONTokener((String) null).skipTo('A');
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-
-        //noinspection ThrowableResultOfMethodCallIgnored
-        assertEquals("foo! at character 0 of null",
-                new JSONTokener((String) null).syntaxError("foo!").getMessage());
-
-        assertEquals(" at character 0 of null", new JSONTokener((String) null).toString());
-    }
-
-    public void testEmptyString() throws JSONException {
-        JSONTokener backTokener = new JSONTokener("");
-        backTokener.back();
-        assertEquals(" at character 0 of ", backTokener.toString());
-        assertFalse(new JSONTokener("").more());
-        assertEquals('\0', new JSONTokener("").next());
-        try {
-            new JSONTokener("").next(3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONTokener("").next('A');
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals('\0', new JSONTokener("").nextClean());
-        try {
-            new JSONTokener("").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals("", new JSONTokener("").nextTo('A'));
-        assertEquals("", new JSONTokener("").nextTo("ABC"));
-        try {
-            new JSONTokener("").nextValue();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        new JSONTokener("").skipPast("ABC");
-        assertEquals('\0', new JSONTokener("").skipTo('A'));
-        //noinspection ThrowableResultOfMethodCallIgnored
-        assertEquals("foo! at character 0 of ",
-                new JSONTokener("").syntaxError("foo!").getMessage());
-        assertEquals(" at character 0 of ", new JSONTokener("").toString());
-    }
-
-    public void testCharacterNavigation() throws JSONException {
-        JSONTokener abcdeTokener = new JSONTokener("ABCDE");
-        assertEquals('A', abcdeTokener.next());
-        assertEquals('B', abcdeTokener.next('B'));
-        assertEquals("CD", abcdeTokener.next(2));
-        try {
-            abcdeTokener.next(2);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals('E', abcdeTokener.nextClean());
-        assertEquals('\0', abcdeTokener.next());
-        assertFalse(abcdeTokener.more());
-        abcdeTokener.back();
-        assertTrue(abcdeTokener.more());
-        assertEquals('E', abcdeTokener.next());
-    }
-
-    public void testBackNextAndMore() throws JSONException {
-        JSONTokener abcTokener = new JSONTokener("ABC");
-        assertTrue(abcTokener.more());
-        abcTokener.next();
-        abcTokener.next();
-        assertTrue(abcTokener.more());
-        abcTokener.next();
-        assertFalse(abcTokener.more());
-        abcTokener.back();
-        assertTrue(abcTokener.more());
-        abcTokener.next();
-        assertFalse(abcTokener.more());
-        abcTokener.back();
-        abcTokener.back();
-        abcTokener.back();
-        abcTokener.back(); // you can back up before the beginning of a String!
-        assertEquals('A', abcTokener.next());
-    }
-
-    public void testNextMatching() throws JSONException {
-        JSONTokener abcdTokener = new JSONTokener("ABCD");
-        assertEquals('A', abcdTokener.next('A'));
-        try {
-            abcdTokener.next('C'); // although it failed, this op consumes a character of input
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals('C', abcdTokener.next('C'));
-        assertEquals('D', abcdTokener.next('D'));
-        try {
-            abcdTokener.next('E');
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    public void testNextN() throws JSONException {
-        JSONTokener abcdeTokener = new JSONTokener("ABCDEF");
-        assertEquals("", abcdeTokener.next(0));
-        try {
-            abcdeTokener.next(7);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals("ABC", abcdeTokener.next(3));
-        try {
-            abcdeTokener.next(4);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    public void testNextNWithAllRemaining() throws JSONException {
-        JSONTokener tokener = new JSONTokener("ABCDEF");
-        tokener.next(3);
-        try {
-            tokener.next(3);
-        } catch (JSONException e) {
-            AssertionFailedError error = new AssertionFailedError("off-by-one error?");
-            error.initCause(e);
-            throw error;
-        }
-    }
-
-    public void testNext0() throws JSONException {
-        JSONTokener tokener = new JSONTokener("ABCDEF");
-        tokener.next(5);
-        tokener.next();
-        try {
-            tokener.next(0);
-        } catch (JSONException e) {
-            Error error = new AssertionFailedError("Returning an empty string should be valid");
-            error.initCause(e);
-            throw error;
-        }
-    }
-
-    public void testNextCleanComments() throws JSONException {
-        JSONTokener tokener = new JSONTokener(
-                "  A  /*XX*/B/*XX//XX\n//XX\nXX*/C//X//X//X\nD/*X*///X\n");
-        assertEquals('A', tokener.nextClean());
-        assertEquals('B', tokener.nextClean());
-        assertEquals('C', tokener.nextClean());
-        assertEquals('D', tokener.nextClean());
-        assertEquals('\0', tokener.nextClean());
-    }
-
-    public void testNextCleanNestedCStyleComments() throws JSONException {
-        JSONTokener tokener = new JSONTokener("A /* B /* C */ D */ E");
-        assertEquals('A', tokener.nextClean());
-        assertEquals('D', tokener.nextClean());
-        assertEquals('*', tokener.nextClean());
-        assertEquals('/', tokener.nextClean());
-        assertEquals('E', tokener.nextClean());
-    }
-
-    /**
-     * Some applications rely on parsing '#' to lead an end-of-line comment.
-     * http://b/2571423
-     */
-    public void testNextCleanHashComments() throws JSONException {
-        JSONTokener tokener = new JSONTokener("A # B */ /* C */ \nD #");
-        assertEquals('A', tokener.nextClean());
-        assertEquals('D', tokener.nextClean());
-        assertEquals('\0', tokener.nextClean());
-    }
-
-    public void testNextCleanCommentsTrailingSingleSlash() throws JSONException {
-        JSONTokener tokener = new JSONTokener(" / S /");
-        assertEquals('/', tokener.nextClean());
-        assertEquals('S', tokener.nextClean());
-        assertEquals('/', tokener.nextClean());
-        assertEquals("nextClean doesn't consume a trailing slash",
-                '\0', tokener.nextClean());
-    }
-
-    public void testNextCleanTrailingOpenComment() throws JSONException {
-        try {
-            new JSONTokener("  /* ").nextClean();
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals('\0', new JSONTokener("  // ").nextClean());
-    }
-
-    public void testNextCleanNewlineDelimiters() throws JSONException {
-        assertEquals('B', new JSONTokener("  // \r\n  B ").nextClean());
-        assertEquals('B', new JSONTokener("  // \n  B ").nextClean());
-        assertEquals('B', new JSONTokener("  // \r  B ").nextClean());
-    }
-
-    public void testNextCleanSkippedWhitespace() throws JSONException {
-        assertEquals("character tabulation", 'A', new JSONTokener("\tA").nextClean());
-        assertEquals("line feed",            'A', new JSONTokener("\nA").nextClean());
-        assertEquals("carriage return",      'A', new JSONTokener("\rA").nextClean());
-        assertEquals("space",                'A', new JSONTokener(" A").nextClean());
-    }
-
-    /**
-     * Tests which characters tokener treats as ignorable whitespace. See Kevin Bourrillion's
-     * <a href="https://spreadsheets.google.com/pub?key=pd8dAQyHbdewRsnE5x5GzKQ">list
-     * of whitespace characters</a>.
-     */
-    public void testNextCleanRetainedWhitespace() throws JSONException {
-        assertNotClean("null",                      '\u0000');
-        assertNotClean("next line",                 '\u0085');
-        assertNotClean("non-breaking space",        '\u00a0');
-        assertNotClean("ogham space mark",          '\u1680');
-        assertNotClean("mongolian vowel separator", '\u180e');
-        assertNotClean("en quad",                   '\u2000');
-        assertNotClean("em quad",                   '\u2001');
-        assertNotClean("en space",                  '\u2002');
-        assertNotClean("em space",                  '\u2003');
-        assertNotClean("three-per-em space",        '\u2004');
-        assertNotClean("four-per-em space",         '\u2005');
-        assertNotClean("six-per-em space",          '\u2006');
-        assertNotClean("figure space",              '\u2007');
-        assertNotClean("punctuation space",         '\u2008');
-        assertNotClean("thin space",                '\u2009');
-        assertNotClean("hair space",                '\u200a');
-        assertNotClean("zero-width space",          '\u200b');
-        assertNotClean("left-to-right mark",        '\u200e');
-        assertNotClean("right-to-left mark",        '\u200f');
-        assertNotClean("line separator",            '\u2028');
-        assertNotClean("paragraph separator",       '\u2029');
-        assertNotClean("narrow non-breaking space", '\u202f');
-        assertNotClean("medium mathematical space", '\u205f');
-        assertNotClean("ideographic space",         '\u3000');
-        assertNotClean("line tabulation",           '\u000b');
-        assertNotClean("form feed",                 '\u000c');
-        assertNotClean("information separator 4",   '\u001c');
-        assertNotClean("information separator 3",   '\u001d');
-        assertNotClean("information separator 2",   '\u001e');
-        assertNotClean("information separator 1",   '\u001f');
-    }
-
-    private void assertNotClean(String name, char c) throws JSONException {
-        assertEquals("The character " + name + " is not whitespace according to the JSON spec.",
-                c, new JSONTokener(new String(new char[] { c, 'A' })).nextClean());
-    }
-
-    public void testNextString() throws JSONException {
-        assertEquals("", new JSONTokener("'").nextString('\''));
-        assertEquals("", new JSONTokener("\"").nextString('\"'));
-        assertEquals("ABC", new JSONTokener("ABC'DEF").nextString('\''));
-        assertEquals("ABC", new JSONTokener("ABC'''DEF").nextString('\''));
-
-        // nextString permits slash-escaping of arbitrary characters!
-        assertEquals("ABC", new JSONTokener("A\\B\\C'DEF").nextString('\''));
-
-        JSONTokener tokener = new JSONTokener(" 'abc' 'def' \"ghi\"");
-        tokener.next();
-        assertEquals('\'', tokener.next());
-        assertEquals("abc", tokener.nextString('\''));
-        tokener.next();
-        assertEquals('\'', tokener.next());
-        assertEquals("def", tokener.nextString('\''));
-        tokener.next();
-        assertEquals('"', tokener.next());
-        assertEquals("ghi", tokener.nextString('\"'));
-        assertFalse(tokener.more());
-    }
-
-    public void testNextStringNoDelimiter() throws JSONException {
-        try {
-            new JSONTokener("").nextString('\'');
-            fail();
-        } catch (JSONException ignored) {
-        }
-
-        JSONTokener tokener = new JSONTokener(" 'abc");
-        tokener.next();
-        tokener.next();
-        try {
-            tokener.next('\'');
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    public void testNextStringEscapedQuote() throws JSONException {
-        try {
-            new JSONTokener("abc\\").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-
-        // we're mixing Java escaping like \" and JavaScript escaping like \\\"
-        // which makes these tests extra tricky to read!
-        assertEquals("abc\"def", new JSONTokener("abc\\\"def\"ghi").nextString('"'));
-        assertEquals("abc\\def", new JSONTokener("abc\\\\def\"ghi").nextString('"'));
-        assertEquals("abc/def", new JSONTokener("abc\\/def\"ghi").nextString('"'));
-        assertEquals("abc\bdef", new JSONTokener("abc\\bdef\"ghi").nextString('"'));
-        assertEquals("abc\fdef", new JSONTokener("abc\\fdef\"ghi").nextString('"'));
-        assertEquals("abc\ndef", new JSONTokener("abc\\ndef\"ghi").nextString('"'));
-        assertEquals("abc\rdef", new JSONTokener("abc\\rdef\"ghi").nextString('"'));
-        assertEquals("abc\tdef", new JSONTokener("abc\\tdef\"ghi").nextString('"'));
-    }
-
-    public void testNextStringUnicodeEscaped() throws JSONException {
-        // we're mixing Java escaping like \\ and JavaScript escaping like \\u
-        assertEquals("abc def", new JSONTokener("abc\\u0020def\"ghi").nextString('"'));
-        assertEquals("abcU0020def", new JSONTokener("abc\\U0020def\"ghi").nextString('"'));
-
-        // JSON requires 4 hex characters after a unicode escape
-        try {
-            new JSONTokener("abc\\u002\"").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONTokener("abc\\u").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONTokener("abc\\u    \"").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals("abc\"def", new JSONTokener("abc\\u0022def\"ghi").nextString('"'));
-        try {
-            new JSONTokener("abc\\u000G\"").nextString('"');
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    public void testNextStringNonQuote() throws JSONException {
-        assertEquals("AB", new JSONTokener("ABC").nextString('C'));
-        assertEquals("ABCD", new JSONTokener("AB\\CDC").nextString('C'));
-        assertEquals("AB\nC", new JSONTokener("AB\\nCn").nextString('n'));
-    }
-
-    public void testNextTo() throws JSONException {
-        assertEquals("ABC", new JSONTokener("ABCDEFG").nextTo("DHI"));
-        assertEquals("ABCDEF", new JSONTokener("ABCDEF").nextTo(""));
-
-        JSONTokener tokener = new JSONTokener("ABC\rDEF\nGHI\r\nJKL");
-        assertEquals("ABC", tokener.nextTo("M"));
-        assertEquals('\r', tokener.next());
-        assertEquals("DEF", tokener.nextTo("M"));
-        assertEquals('\n', tokener.next());
-        assertEquals("GHI", tokener.nextTo("M"));
-        assertEquals('\r', tokener.next());
-        assertEquals('\n', tokener.next());
-        assertEquals("JKL", tokener.nextTo("M"));
-
-        tokener = new JSONTokener("ABCDEFGHI");
-        assertEquals("ABC", tokener.nextTo("DEF"));
-        assertEquals("", tokener.nextTo("DEF"));
-        assertEquals('D', tokener.next());
-        assertEquals("", tokener.nextTo("DEF"));
-        assertEquals('E', tokener.next());
-        assertEquals("", tokener.nextTo("DEF"));
-        assertEquals('F', tokener.next());
-        assertEquals("GHI", tokener.nextTo("DEF"));
-        assertEquals("", tokener.nextTo("DEF"));
-
-        tokener = new JSONTokener(" \t \fABC \t DEF");
-        assertEquals("ABC", tokener.nextTo("DEF"));
-        assertEquals('D', tokener.next());
-
-        tokener = new JSONTokener(" \t \fABC \n DEF");
-        assertEquals("ABC", tokener.nextTo("\n"));
-        assertEquals("", tokener.nextTo("\n"));
-
-        tokener = new JSONTokener("");
-        try {
-            tokener.nextTo(null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    public void testNextToTrimming() {
-        assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo("DE"));
-        assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo('D'));
-    }
-
-    public void testNextToTrailing() {
-        assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo("G"));
-        assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo('G'));
-    }
-
-    public void testNextToDoesntStopOnNull() {
-        String message = "nextTo() shouldn't stop after \\0 characters";
-        JSONTokener tokener = new JSONTokener(" \0\t \fABC \n DEF");
-        assertEquals(message, "ABC", tokener.nextTo("D"));
-        assertEquals(message, '\n', tokener.next());
-        assertEquals(message, "", tokener.nextTo("D"));
-    }
-
-    public void testNextToConsumesNull() {
-        String message = "nextTo shouldn't consume \\0.";
-        JSONTokener tokener = new JSONTokener("ABC\0DEF");
-        assertEquals(message, "ABC", tokener.nextTo("\0"));
-        assertEquals(message, '\0', tokener.next());
-        assertEquals(message, "DEF", tokener.nextTo("\0"));
-    }
-
-    public void testSkipPast() {
-        JSONTokener tokener = new JSONTokener("ABCDEF");
-        tokener.skipPast("ABC");
-        assertEquals('D', tokener.next());
-        tokener.skipPast("EF");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABCDEF");
-        tokener.skipPast("ABCDEF");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABCDEF");
-        tokener.skipPast("G");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABC\0ABC");
-        tokener.skipPast("ABC");
-        assertEquals('\0', tokener.next());
-        assertEquals('A', tokener.next());
-
-        tokener = new JSONTokener("\0ABC");
-        tokener.skipPast("ABC");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABC\nDEF");
-        tokener.skipPast("DEF");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABC");
-        tokener.skipPast("ABCDEF");
-        assertEquals('\0', tokener.next());
-
-        tokener = new JSONTokener("ABCDABCDABCD");
-        tokener.skipPast("ABC");
-        assertEquals('D', tokener.next());
-        tokener.skipPast("ABC");
-        assertEquals('D', tokener.next());
-        tokener.skipPast("ABC");
-        assertEquals('D', tokener.next());
-
-        tokener = new JSONTokener("");
-        try {
-            tokener.skipPast(null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    public void testSkipTo() {
-        JSONTokener tokener = new JSONTokener("ABCDEF");
-        tokener.skipTo('A');
-        assertEquals('A', tokener.next());
-        tokener.skipTo('D');
-        assertEquals('D', tokener.next());
-        tokener.skipTo('G');
-        assertEquals('E', tokener.next());
-        tokener.skipTo('A');
-        assertEquals('F', tokener.next());
-
-        tokener = new JSONTokener("ABC\nDEF");
-        tokener.skipTo('F');
-        assertEquals('F', tokener.next());
-
-        tokener = new JSONTokener("ABCfDEF");
-        tokener.skipTo('F');
-        assertEquals('F', tokener.next());
-
-        tokener = new JSONTokener("ABC/* DEF */");
-        tokener.skipTo('D');
-        assertEquals('D', tokener.next());
-    }
-
-    public void testSkipToStopsOnNull() {
-        JSONTokener tokener = new JSONTokener("ABC\0DEF");
-        tokener.skipTo('F');
-        assertEquals("skipTo shouldn't stop when it sees '\\0'", 'F', tokener.next());
-    }
-
-    public void testBomIgnoredAsFirstCharacterOfDocument() throws JSONException {
-        JSONTokener tokener = new JSONTokener("\ufeff[]");
-        JSONArray array = (JSONArray) tokener.nextValue();
-        assertEquals(0, array.length());
-    }
-
-    public void testBomTreatedAsCharacterInRestOfDocument() throws JSONException {
-        JSONTokener tokener = new JSONTokener("[\ufeff]");
-        JSONArray array = (JSONArray) tokener.nextValue();
-        assertEquals(1, array.length());
-    }
-
-    public void testDehexchar() {
-        assertEquals( 0, JSONTokener.dehexchar('0'));
-        assertEquals( 1, JSONTokener.dehexchar('1'));
-        assertEquals( 2, JSONTokener.dehexchar('2'));
-        assertEquals( 3, JSONTokener.dehexchar('3'));
-        assertEquals( 4, JSONTokener.dehexchar('4'));
-        assertEquals( 5, JSONTokener.dehexchar('5'));
-        assertEquals( 6, JSONTokener.dehexchar('6'));
-        assertEquals( 7, JSONTokener.dehexchar('7'));
-        assertEquals( 8, JSONTokener.dehexchar('8'));
-        assertEquals( 9, JSONTokener.dehexchar('9'));
-        assertEquals(10, JSONTokener.dehexchar('A'));
-        assertEquals(11, JSONTokener.dehexchar('B'));
-        assertEquals(12, JSONTokener.dehexchar('C'));
-        assertEquals(13, JSONTokener.dehexchar('D'));
-        assertEquals(14, JSONTokener.dehexchar('E'));
-        assertEquals(15, JSONTokener.dehexchar('F'));
-        assertEquals(10, JSONTokener.dehexchar('a'));
-        assertEquals(11, JSONTokener.dehexchar('b'));
-        assertEquals(12, JSONTokener.dehexchar('c'));
-        assertEquals(13, JSONTokener.dehexchar('d'));
-        assertEquals(14, JSONTokener.dehexchar('e'));
-        assertEquals(15, JSONTokener.dehexchar('f'));
-
-        for (int c = 0; c <= 0xFFFF; c++) {
-            if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
-                continue;
-            }
-            assertEquals("dehexchar " + c, -1, JSONTokener.dehexchar((char) c));
-        }
+  public void testNulls() throws JSONException {
+    // JSONTokener accepts null, only to fail later on almost all APIs!
+    new JSONTokener((String) null).back();
+
+    try {
+      new JSONTokener((String) null).more();
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).next();
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).next(3);
+      fail();
+    } catch (NullPointerException ignored) {
     }
+
+    try {
+      new JSONTokener((String) null).next('A');
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).nextClean();
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).nextString('"');
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).nextTo('A');
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).nextTo("ABC");
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).nextValue();
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).skipPast("ABC");
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    try {
+      new JSONTokener((String) null).skipTo('A');
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+
+    // noinspection ThrowableResultOfMethodCallIgnored
+    assertEquals("foo! at character 0 of null",
+        new JSONTokener((String) null).syntaxError("foo!").getMessage());
+
+    assertEquals(" at character 0 of null", new JSONTokener((String) null).toString());
+  }
+
+  public void testEmptyString() throws JSONException {
+    JSONTokener backTokener = new JSONTokener("");
+    backTokener.back();
+    assertEquals(" at character 0 of ", backTokener.toString());
+    assertFalse(new JSONTokener("").more());
+    assertEquals('\0', new JSONTokener("").next());
+    try {
+      new JSONTokener("").next(3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONTokener("").next('A');
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals('\0', new JSONTokener("").nextClean());
+    try {
+      new JSONTokener("").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals("", new JSONTokener("").nextTo('A'));
+    assertEquals("", new JSONTokener("").nextTo("ABC"));
+    try {
+      new JSONTokener("").nextValue();
+      fail();
+    } catch (JSONException ignored) {
+    }
+    new JSONTokener("").skipPast("ABC");
+    assertEquals('\0', new JSONTokener("").skipTo('A'));
+    // noinspection ThrowableResultOfMethodCallIgnored
+    assertEquals("foo! at character 0 of ", new JSONTokener("").syntaxError("foo!").getMessage());
+    assertEquals(" at character 0 of ", new JSONTokener("").toString());
+  }
+
+  public void testCharacterNavigation() throws JSONException {
+    JSONTokener abcdeTokener = new JSONTokener("ABCDE");
+    assertEquals('A', abcdeTokener.next());
+    assertEquals('B', abcdeTokener.next('B'));
+    assertEquals("CD", abcdeTokener.next(2));
+    try {
+      abcdeTokener.next(2);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals('E', abcdeTokener.nextClean());
+    assertEquals('\0', abcdeTokener.next());
+    assertFalse(abcdeTokener.more());
+    abcdeTokener.back();
+    assertTrue(abcdeTokener.more());
+    assertEquals('E', abcdeTokener.next());
+  }
+
+  public void testBackNextAndMore() throws JSONException {
+    JSONTokener abcTokener = new JSONTokener("ABC");
+    assertTrue(abcTokener.more());
+    abcTokener.next();
+    abcTokener.next();
+    assertTrue(abcTokener.more());
+    abcTokener.next();
+    assertFalse(abcTokener.more());
+    abcTokener.back();
+    assertTrue(abcTokener.more());
+    abcTokener.next();
+    assertFalse(abcTokener.more());
+    abcTokener.back();
+    abcTokener.back();
+    abcTokener.back();
+    abcTokener.back(); // you can back up before the beginning of a String!
+    assertEquals('A', abcTokener.next());
+  }
+
+  public void testNextMatching() throws JSONException {
+    JSONTokener abcdTokener = new JSONTokener("ABCD");
+    assertEquals('A', abcdTokener.next('A'));
+    try {
+      abcdTokener.next('C'); // although it failed, this op consumes a character of input
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals('C', abcdTokener.next('C'));
+    assertEquals('D', abcdTokener.next('D'));
+    try {
+      abcdTokener.next('E');
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  public void testNextN() throws JSONException {
+    JSONTokener abcdeTokener = new JSONTokener("ABCDEF");
+    assertEquals("", abcdeTokener.next(0));
+    try {
+      abcdeTokener.next(7);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals("ABC", abcdeTokener.next(3));
+    try {
+      abcdeTokener.next(4);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  public void testNextNWithAllRemaining() throws JSONException {
+    JSONTokener tokener = new JSONTokener("ABCDEF");
+    tokener.next(3);
+    try {
+      tokener.next(3);
+    } catch (JSONException e) {
+      AssertionFailedError error = new AssertionFailedError("off-by-one error?");
+      error.initCause(e);
+      throw error;
+    }
+  }
+
+  public void testNext0() throws JSONException {
+    JSONTokener tokener = new JSONTokener("ABCDEF");
+    tokener.next(5);
+    tokener.next();
+    try {
+      tokener.next(0);
+    } catch (JSONException e) {
+      Error error = new AssertionFailedError("Returning an empty string should be valid");
+      error.initCause(e);
+      throw error;
+    }
+  }
+
+  public void testNextCleanComments() throws JSONException {
+    JSONTokener tokener =
+        new JSONTokener("  A  /*XX*/B/*XX//XX\n//XX\nXX*/C//X//X//X\nD/*X*///X\n");
+    assertEquals('A', tokener.nextClean());
+    assertEquals('B', tokener.nextClean());
+    assertEquals('C', tokener.nextClean());
+    assertEquals('D', tokener.nextClean());
+    assertEquals('\0', tokener.nextClean());
+  }
+
+  public void testNextCleanNestedCStyleComments() throws JSONException {
+    JSONTokener tokener = new JSONTokener("A /* B /* C */ D */ E");
+    assertEquals('A', tokener.nextClean());
+    assertEquals('D', tokener.nextClean());
+    assertEquals('*', tokener.nextClean());
+    assertEquals('/', tokener.nextClean());
+    assertEquals('E', tokener.nextClean());
+  }
+
+  /**
+   * Some applications rely on parsing '#' to lead an end-of-line comment. http://b/2571423
+   */
+  public void testNextCleanHashComments() throws JSONException {
+    JSONTokener tokener = new JSONTokener("A # B */ /* C */ \nD #");
+    assertEquals('A', tokener.nextClean());
+    assertEquals('D', tokener.nextClean());
+    assertEquals('\0', tokener.nextClean());
+  }
+
+  public void testNextCleanCommentsTrailingSingleSlash() throws JSONException {
+    JSONTokener tokener = new JSONTokener(" / S /");
+    assertEquals('/', tokener.nextClean());
+    assertEquals('S', tokener.nextClean());
+    assertEquals('/', tokener.nextClean());
+    assertEquals("nextClean doesn't consume a trailing slash", '\0', tokener.nextClean());
+  }
+
+  public void testNextCleanTrailingOpenComment() throws JSONException {
+    try {
+      new JSONTokener("  /* ").nextClean();
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals('\0', new JSONTokener("  // ").nextClean());
+  }
+
+  public void testNextCleanNewlineDelimiters() throws JSONException {
+    assertEquals('B', new JSONTokener("  // \r\n  B ").nextClean());
+    assertEquals('B', new JSONTokener("  // \n  B ").nextClean());
+    assertEquals('B', new JSONTokener("  // \r  B ").nextClean());
+  }
+
+  public void testNextCleanSkippedWhitespace() throws JSONException {
+    assertEquals("character tabulation", 'A', new JSONTokener("\tA").nextClean());
+    assertEquals("line feed", 'A', new JSONTokener("\nA").nextClean());
+    assertEquals("carriage return", 'A', new JSONTokener("\rA").nextClean());
+    assertEquals("space", 'A', new JSONTokener(" A").nextClean());
+  }
+
+  /**
+   * Tests which characters tokener treats as ignorable whitespace. See Kevin Bourrillion's
+   * <a href="https://spreadsheets.google.com/pub?key=pd8dAQyHbdewRsnE5x5GzKQ">list of whitespace
+   * characters</a>.
+   */
+  public void testNextCleanRetainedWhitespace() throws JSONException {
+    assertNotClean("null", '\u0000');
+    assertNotClean("next line", '\u0085');
+    assertNotClean("non-breaking space", '\u00a0');
+    assertNotClean("ogham space mark", '\u1680');
+    assertNotClean("mongolian vowel separator", '\u180e');
+    assertNotClean("en quad", '\u2000');
+    assertNotClean("em quad", '\u2001');
+    assertNotClean("en space", '\u2002');
+    assertNotClean("em space", '\u2003');
+    assertNotClean("three-per-em space", '\u2004');
+    assertNotClean("four-per-em space", '\u2005');
+    assertNotClean("six-per-em space", '\u2006');
+    assertNotClean("figure space", '\u2007');
+    assertNotClean("punctuation space", '\u2008');
+    assertNotClean("thin space", '\u2009');
+    assertNotClean("hair space", '\u200a');
+    assertNotClean("zero-width space", '\u200b');
+    assertNotClean("left-to-right mark", '\u200e');
+    assertNotClean("right-to-left mark", '\u200f');
+    assertNotClean("line separator", '\u2028');
+    assertNotClean("paragraph separator", '\u2029');
+    assertNotClean("narrow non-breaking space", '\u202f');
+    assertNotClean("medium mathematical space", '\u205f');
+    assertNotClean("ideographic space", '\u3000');
+    assertNotClean("line tabulation", '\u000b');
+    assertNotClean("form feed", '\u000c');
+    assertNotClean("information separator 4", '\u001c');
+    assertNotClean("information separator 3", '\u001d');
+    assertNotClean("information separator 2", '\u001e');
+    assertNotClean("information separator 1", '\u001f');
+  }
+
+  private void assertNotClean(String name, char c) throws JSONException {
+    assertEquals("The character " + name + " is not whitespace according to the JSON spec.", c,
+        new JSONTokener(new String(new char[] {c, 'A'})).nextClean());
+  }
+
+  public void testNextString() throws JSONException {
+    assertEquals("", new JSONTokener("'").nextString('\''));
+    assertEquals("", new JSONTokener("\"").nextString('\"'));
+    assertEquals("ABC", new JSONTokener("ABC'DEF").nextString('\''));
+    assertEquals("ABC", new JSONTokener("ABC'''DEF").nextString('\''));
+
+    // nextString permits slash-escaping of arbitrary characters!
+    assertEquals("ABC", new JSONTokener("A\\B\\C'DEF").nextString('\''));
+
+    JSONTokener tokener = new JSONTokener(" 'abc' 'def' \"ghi\"");
+    tokener.next();
+    assertEquals('\'', tokener.next());
+    assertEquals("abc", tokener.nextString('\''));
+    tokener.next();
+    assertEquals('\'', tokener.next());
+    assertEquals("def", tokener.nextString('\''));
+    tokener.next();
+    assertEquals('"', tokener.next());
+    assertEquals("ghi", tokener.nextString('\"'));
+    assertFalse(tokener.more());
+  }
+
+  public void testNextStringNoDelimiter() throws JSONException {
+    try {
+      new JSONTokener("").nextString('\'');
+      fail();
+    } catch (JSONException ignored) {
+    }
+
+    JSONTokener tokener = new JSONTokener(" 'abc");
+    tokener.next();
+    tokener.next();
+    try {
+      tokener.next('\'');
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  public void testNextStringEscapedQuote() throws JSONException {
+    try {
+      new JSONTokener("abc\\").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+
+    // we're mixing Java escaping like \" and JavaScript escaping like \\\"
+    // which makes these tests extra tricky to read!
+    assertEquals("abc\"def", new JSONTokener("abc\\\"def\"ghi").nextString('"'));
+    assertEquals("abc\\def", new JSONTokener("abc\\\\def\"ghi").nextString('"'));
+    assertEquals("abc/def", new JSONTokener("abc\\/def\"ghi").nextString('"'));
+    assertEquals("abc\bdef", new JSONTokener("abc\\bdef\"ghi").nextString('"'));
+    assertEquals("abc\fdef", new JSONTokener("abc\\fdef\"ghi").nextString('"'));
+    assertEquals("abc\ndef", new JSONTokener("abc\\ndef\"ghi").nextString('"'));
+    assertEquals("abc\rdef", new JSONTokener("abc\\rdef\"ghi").nextString('"'));
+    assertEquals("abc\tdef", new JSONTokener("abc\\tdef\"ghi").nextString('"'));
+  }
+
+  public void testNextStringUnicodeEscaped() throws JSONException {
+    // we're mixing Java escaping like \\ and JavaScript escaping like \\u
+    assertEquals("abc def", new JSONTokener("abc\\u0020def\"ghi").nextString('"'));
+    assertEquals("abcU0020def", new JSONTokener("abc\\U0020def\"ghi").nextString('"'));
+
+    // JSON requires 4 hex characters after a unicode escape
+    try {
+      new JSONTokener("abc\\u002\"").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONTokener("abc\\u").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONTokener("abc\\u    \"").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals("abc\"def", new JSONTokener("abc\\u0022def\"ghi").nextString('"'));
+    try {
+      new JSONTokener("abc\\u000G\"").nextString('"');
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  public void testNextStringNonQuote() throws JSONException {
+    assertEquals("AB", new JSONTokener("ABC").nextString('C'));
+    assertEquals("ABCD", new JSONTokener("AB\\CDC").nextString('C'));
+    assertEquals("AB\nC", new JSONTokener("AB\\nCn").nextString('n'));
+  }
+
+  public void testNextTo() throws JSONException {
+    assertEquals("ABC", new JSONTokener("ABCDEFG").nextTo("DHI"));
+    assertEquals("ABCDEF", new JSONTokener("ABCDEF").nextTo(""));
+
+    JSONTokener tokener = new JSONTokener("ABC\rDEF\nGHI\r\nJKL");
+    assertEquals("ABC", tokener.nextTo("M"));
+    assertEquals('\r', tokener.next());
+    assertEquals("DEF", tokener.nextTo("M"));
+    assertEquals('\n', tokener.next());
+    assertEquals("GHI", tokener.nextTo("M"));
+    assertEquals('\r', tokener.next());
+    assertEquals('\n', tokener.next());
+    assertEquals("JKL", tokener.nextTo("M"));
+
+    tokener = new JSONTokener("ABCDEFGHI");
+    assertEquals("ABC", tokener.nextTo("DEF"));
+    assertEquals("", tokener.nextTo("DEF"));
+    assertEquals('D', tokener.next());
+    assertEquals("", tokener.nextTo("DEF"));
+    assertEquals('E', tokener.next());
+    assertEquals("", tokener.nextTo("DEF"));
+    assertEquals('F', tokener.next());
+    assertEquals("GHI", tokener.nextTo("DEF"));
+    assertEquals("", tokener.nextTo("DEF"));
+
+    tokener = new JSONTokener(" \t \fABC \t DEF");
+    assertEquals("ABC", tokener.nextTo("DEF"));
+    assertEquals('D', tokener.next());
+
+    tokener = new JSONTokener(" \t \fABC \n DEF");
+    assertEquals("ABC", tokener.nextTo("\n"));
+    assertEquals("", tokener.nextTo("\n"));
+
+    tokener = new JSONTokener("");
+    try {
+      tokener.nextTo(null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  public void testNextToTrimming() {
+    assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo("DE"));
+    assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo('D'));
+  }
+
+  public void testNextToTrailing() {
+    assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo("G"));
+    assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo('G'));
+  }
+
+  public void testNextToDoesntStopOnNull() {
+    String message = "nextTo() shouldn't stop after \\0 characters";
+    JSONTokener tokener = new JSONTokener(" \0\t \fABC \n DEF");
+    assertEquals(message, "ABC", tokener.nextTo("D"));
+    assertEquals(message, '\n', tokener.next());
+    assertEquals(message, "", tokener.nextTo("D"));
+  }
+
+  public void testNextToConsumesNull() {
+    String message = "nextTo shouldn't consume \\0.";
+    JSONTokener tokener = new JSONTokener("ABC\0DEF");
+    assertEquals(message, "ABC", tokener.nextTo("\0"));
+    assertEquals(message, '\0', tokener.next());
+    assertEquals(message, "DEF", tokener.nextTo("\0"));
+  }
+
+  public void testSkipPast() {
+    JSONTokener tokener = new JSONTokener("ABCDEF");
+    tokener.skipPast("ABC");
+    assertEquals('D', tokener.next());
+    tokener.skipPast("EF");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABCDEF");
+    tokener.skipPast("ABCDEF");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABCDEF");
+    tokener.skipPast("G");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABC\0ABC");
+    tokener.skipPast("ABC");
+    assertEquals('\0', tokener.next());
+    assertEquals('A', tokener.next());
+
+    tokener = new JSONTokener("\0ABC");
+    tokener.skipPast("ABC");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABC\nDEF");
+    tokener.skipPast("DEF");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABC");
+    tokener.skipPast("ABCDEF");
+    assertEquals('\0', tokener.next());
+
+    tokener = new JSONTokener("ABCDABCDABCD");
+    tokener.skipPast("ABC");
+    assertEquals('D', tokener.next());
+    tokener.skipPast("ABC");
+    assertEquals('D', tokener.next());
+    tokener.skipPast("ABC");
+    assertEquals('D', tokener.next());
+
+    tokener = new JSONTokener("");
+    try {
+      tokener.skipPast(null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  public void testSkipTo() {
+    JSONTokener tokener = new JSONTokener("ABCDEF");
+    tokener.skipTo('A');
+    assertEquals('A', tokener.next());
+    tokener.skipTo('D');
+    assertEquals('D', tokener.next());
+    tokener.skipTo('G');
+    assertEquals('E', tokener.next());
+    tokener.skipTo('A');
+    assertEquals('F', tokener.next());
+
+    tokener = new JSONTokener("ABC\nDEF");
+    tokener.skipTo('F');
+    assertEquals('F', tokener.next());
+
+    tokener = new JSONTokener("ABCfDEF");
+    tokener.skipTo('F');
+    assertEquals('F', tokener.next());
+
+    tokener = new JSONTokener("ABC/* DEF */");
+    tokener.skipTo('D');
+    assertEquals('D', tokener.next());
+  }
+
+  public void testSkipToStopsOnNull() {
+    JSONTokener tokener = new JSONTokener("ABC\0DEF");
+    tokener.skipTo('F');
+    assertEquals("skipTo shouldn't stop when it sees '\\0'", 'F', tokener.next());
+  }
+
+  public void testBomIgnoredAsFirstCharacterOfDocument() throws JSONException {
+    JSONTokener tokener = new JSONTokener("\ufeff[]");
+    JSONArray array = (JSONArray) tokener.nextValue();
+    assertEquals(0, array.length());
+  }
+
+  public void testBomTreatedAsCharacterInRestOfDocument() throws JSONException {
+    JSONTokener tokener = new JSONTokener("[\ufeff]");
+    JSONArray array = (JSONArray) tokener.nextValue();
+    assertEquals(1, array.length());
+  }
+
+  public void testDehexchar() {
+    assertEquals(0, JSONTokener.dehexchar('0'));
+    assertEquals(1, JSONTokener.dehexchar('1'));
+    assertEquals(2, JSONTokener.dehexchar('2'));
+    assertEquals(3, JSONTokener.dehexchar('3'));
+    assertEquals(4, JSONTokener.dehexchar('4'));
+    assertEquals(5, JSONTokener.dehexchar('5'));
+    assertEquals(6, JSONTokener.dehexchar('6'));
+    assertEquals(7, JSONTokener.dehexchar('7'));
+    assertEquals(8, JSONTokener.dehexchar('8'));
+    assertEquals(9, JSONTokener.dehexchar('9'));
+    assertEquals(10, JSONTokener.dehexchar('A'));
+    assertEquals(11, JSONTokener.dehexchar('B'));
+    assertEquals(12, JSONTokener.dehexchar('C'));
+    assertEquals(13, JSONTokener.dehexchar('D'));
+    assertEquals(14, JSONTokener.dehexchar('E'));
+    assertEquals(15, JSONTokener.dehexchar('F'));
+    assertEquals(10, JSONTokener.dehexchar('a'));
+    assertEquals(11, JSONTokener.dehexchar('b'));
+    assertEquals(12, JSONTokener.dehexchar('c'));
+    assertEquals(13, JSONTokener.dehexchar('d'));
+    assertEquals(14, JSONTokener.dehexchar('e'));
+    assertEquals(15, JSONTokener.dehexchar('f'));
+
+    for (int c = 0; c <= 0xFFFF; c++) {
+      if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
+        continue;
+      }
+      assertEquals("dehexchar " + c, -1, JSONTokener.dehexchar((char) c));
+    }
+  }
 }


[14/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/JSONArrayTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONArrayTest.java b/geode-json/src/test/java/org/json/JSONArrayTest.java
index 8f6632b..88ba989 100755
--- a/geode-json/src/test/java/org/json/JSONArrayTest.java
+++ b/geode-json/src/test/java/org/json/JSONArrayTest.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -28,581 +26,582 @@ import static org.junit.Assert.*;
  * This black box test was written without inspecting the non-free org.json sourcecode.
  */
 public class JSONArrayTest {
-    @Test
-    public void testEmptyArray() throws JSONException {
-        JSONArray array = new JSONArray();
-        assertEquals(0, array.length());
-        assertEquals("", array.join(" AND "));
-        try {
-            array.get(0);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.getBoolean(0);
-            fail();
-        } catch (JSONException ignored) {
-        }
-
-        assertEquals("[]", array.toString());
-        assertEquals("[]", array.toString(4));
-
-        // out of bounds is co-opted with defaulting
-        assertTrue(array.isNull(0));
-        assertNull(array.opt(0));
-        assertFalse(array.optBoolean(0));
-        assertTrue(array.optBoolean(0, true));
-
-        // bogus (but documented) behaviour: returns null rather than an empty object!
-        assertNull(array.toJSONObject(new JSONArray()));
-    }
-
-    @Test
-    public void testEqualsAndHashCode() throws JSONException {
-        JSONArray a = new JSONArray();
-        JSONArray b = new JSONArray();
-        assertTrue(a.equals(b));
-        assertEquals("equals() not consistent with hashCode()", a.hashCode(), b.hashCode());
-
-        a.put(true);
-        a.put(false);
-        b.put(true);
-        b.put(false);
-        assertTrue(a.equals(b));
-        assertEquals(a.hashCode(), b.hashCode());
-
-        b.put(true);
-        assertFalse(a.equals(b));
-        assertTrue(a.hashCode() != b.hashCode());
-    }
-
-    @Test
-    public void testBooleans() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(true);
-        array.put(false);
-        array.put(2, false);
-        array.put(3, false);
-        array.put(2, true);
-        assertEquals("[true,false,true,false]", array.toString());
-        assertEquals(4, array.length());
-        assertEquals(Boolean.TRUE, array.get(0));
-        assertEquals(Boolean.FALSE, array.get(1));
-        assertEquals(Boolean.TRUE, array.get(2));
-        assertEquals(Boolean.FALSE, array.get(3));
-        assertFalse(array.isNull(0));
-        assertFalse(array.isNull(1));
-        assertFalse(array.isNull(2));
-        assertFalse(array.isNull(3));
-        assertEquals(true, array.optBoolean(0));
-        assertEquals(false, array.optBoolean(1, true));
-        assertEquals(true, array.optBoolean(2, false));
-        assertEquals(false, array.optBoolean(3));
-        assertEquals("true", array.getString(0));
-        assertEquals("false", array.getString(1));
-        assertEquals("true", array.optString(2));
-        assertEquals("false", array.optString(3, "x"));
-        assertEquals("[\n     true,\n     false,\n     true,\n     false\n]", array.toString(5));
-
-        JSONArray other = new JSONArray();
-        other.put(true);
-        other.put(false);
-        other.put(true);
-        other.put(false);
-        assertTrue(array.equals(other));
-        other.put(true);
-        assertFalse(array.equals(other));
-
-        other = new JSONArray();
-        other.put("true");
-        other.put("false");
-        other.put("truE");
-        other.put("FALSE");
-        assertFalse(array.equals(other));
-        assertFalse(other.equals(array));
-        assertEquals(true, other.getBoolean(0));
-        assertEquals(false, other.optBoolean(1, true));
-        assertEquals(true, other.optBoolean(2));
-        assertEquals(false, other.getBoolean(3));
-    }
-
-    // http://code.google.com/p/android/issues/detail?id=16411
-    @Test
-    public void testCoerceStringToBoolean() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put("maybe");
-        try {
-            array.getBoolean(0);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals(false, array.optBoolean(0));
-        assertEquals(true, array.optBoolean(0, true));
-    }
-
-    @Test
-    public void testNulls() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(3, null);
-        array.put(0, JSONObject.NULL);
-        assertEquals(4, array.length());
-        assertEquals("[null,null,null,null]", array.toString());
-
-        // there's 2 ways to represent null; each behaves differently!
-        assertEquals(JSONObject.NULL, array.get(0));
-        try {
-            array.get(1);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.get(2);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.get(3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals(JSONObject.NULL, array.opt(0));
-        assertEquals(null, array.opt(1));
-        assertEquals(null, array.opt(2));
-        assertEquals(null, array.opt(3));
-        assertTrue(array.isNull(0));
-        assertTrue(array.isNull(1));
-        assertTrue(array.isNull(2));
-        assertTrue(array.isNull(3));
-        assertEquals("null", array.optString(0));
-        assertEquals("", array.optString(1));
-        assertEquals("", array.optString(2));
-        assertEquals("", array.optString(3));
-    }
-
-    /**
-     * Our behaviour is questioned by this bug:
-     * http://code.google.com/p/android/issues/detail?id=7257
-     */
-    @Test
-    public void testParseNullYieldsJSONObjectNull() throws JSONException {
-        JSONArray array = new JSONArray("[\"null\",null]");
-        array.put(null);
-        assertEquals("null", array.get(0));
-        assertEquals(JSONObject.NULL, array.get(1));
-        try {
-            array.get(2);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals("null", array.getString(0));
-        assertEquals("null", array.getString(1));
-        try {
-            array.getString(2);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testNumbers() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(Double.MIN_VALUE);
-        array.put(9223372036854775806L);
-        array.put(Double.MAX_VALUE);
-        array.put(-0d);
-        assertEquals(4, array.length());
-
-        // toString() and getString(int) return different values for -0d
-        assertEquals("[4.9E-324,9223372036854775806,1.7976931348623157E308,-0]", array.toString());
-
-        assertEquals(Double.MIN_VALUE, array.get(0));
-        assertEquals(9223372036854775806L, array.get(1));
-        assertEquals(Double.MAX_VALUE, array.get(2));
-        assertEquals(-0d, array.get(3));
-        assertEquals(Double.MIN_VALUE, array.getDouble(0), 0);
-        assertEquals(9.223372036854776E18, array.getDouble(1), 0);
-        assertEquals(Double.MAX_VALUE, array.getDouble(2), 0);
-        assertEquals(-0d, array.getDouble(3), 0);
-        assertEquals(0, array.getLong(0));
-        assertEquals(9223372036854775806L, array.getLong(1));
-        assertEquals(Long.MAX_VALUE, array.getLong(2));
-        assertEquals(0, array.getLong(3));
-        assertEquals(0, array.getInt(0));
-        assertEquals(-2, array.getInt(1));
-        assertEquals(Integer.MAX_VALUE, array.getInt(2));
-        assertEquals(0, array.getInt(3));
-        assertEquals(Double.MIN_VALUE, array.opt(0));
-        assertEquals(Double.MIN_VALUE, array.optDouble(0), 0);
-        assertEquals(0, array.optLong(0, 1L));
-        assertEquals(0, array.optInt(0, 1));
-        assertEquals("4.9E-324", array.getString(0));
-        assertEquals("9223372036854775806", array.getString(1));
-        assertEquals("1.7976931348623157E308", array.getString(2));
-        assertEquals("-0.0", array.getString(3));
-
-        JSONArray other = new JSONArray();
-        other.put(Double.MIN_VALUE);
-        other.put(9223372036854775806L);
-        other.put(Double.MAX_VALUE);
-        other.put(-0d);
-        assertTrue(array.equals(other));
-        other.put(0, 0L);
-        assertFalse(array.equals(other));
-    }
-
-    @Test
-    public void testStrings() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put("true");
-        array.put("5.5");
-        array.put("9223372036854775806");
-        array.put("null");
-        array.put("5\"8' tall");
-        assertEquals(5, array.length());
-        assertEquals("[\"true\",\"5.5\",\"9223372036854775806\",\"null\",\"5\\\"8' tall\"]",
-                array.toString());
-
-        // although the documentation doesn't mention it, join() escapes text and wraps
-        // strings in quotes
-        assertEquals("\"true\" \"5.5\" \"9223372036854775806\" \"null\" \"5\\\"8' tall\"",
-                array.join(" "));
-
-        assertEquals("true", array.get(0));
-        assertEquals("null", array.getString(3));
-        assertEquals("5\"8' tall", array.getString(4));
-        assertEquals("true", array.opt(0));
-        assertEquals("5.5", array.optString(1));
-        assertEquals("9223372036854775806", array.optString(2, null));
-        assertEquals("null", array.optString(3, "-1"));
-        assertFalse(array.isNull(0));
-        assertFalse(array.isNull(3));
-
-        assertEquals(true, array.getBoolean(0));
-        assertEquals(true, array.optBoolean(0));
-        assertEquals(true, array.optBoolean(0, false));
-        assertEquals(0, array.optInt(0));
-        assertEquals(-2, array.optInt(0, -2));
-
-        assertEquals(5.5d, array.getDouble(1), 0);
-        assertEquals(5L, array.getLong(1));
-        assertEquals(5, array.getInt(1));
-        assertEquals(5, array.optInt(1, 3));
-
-        // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
-        // double and then converting that to a long. This is consistent with JavaScript.
-        assertEquals(9223372036854775807L, array.getLong(2));
-        assertEquals(9.223372036854776E18, array.getDouble(2), 0);
-        assertEquals(Integer.MAX_VALUE, array.getInt(2));
-
-        assertFalse(array.isNull(3));
-        try {
-            array.getDouble(3);
-            fail();
-        } catch (JSONException e) {
-            // expected
-        }
-        assertEquals(Double.NaN, array.optDouble(3), 0);
-        assertEquals(-1.0d, array.optDouble(3, -1.0d), 0);
-    }
-
-    @Test
-    public void testJoin() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(null);
-        assertEquals("null", array.join(" & "));
-        array.put("\"");
-        assertEquals("null & \"\\\"\"", array.join(" & "));
-        array.put(5);
-        assertEquals("null & \"\\\"\" & 5", array.join(" & "));
-        array.put(true);
-        assertEquals("null & \"\\\"\" & 5 & true", array.join(" & "));
-        array.put(new JSONArray(Arrays.asList(true, false)));
-        assertEquals("null & \"\\\"\" & 5 & true & [true,false]", array.join(" & "));
-        array.put(new JSONObject(Collections.singletonMap("x", 6)));
-        assertEquals("null & \"\\\"\" & 5 & true & [true,false] & {\"x\":6}", array.join(" & "));
-    }
-
-    @Test
-    public void testJoinWithNull() throws JSONException {
-        JSONArray array = new JSONArray(Arrays.asList(5, 6));
-        assertEquals("5null6", array.join(null));
-    }
-
-    @Test
-    public void testJoinWithSpecialCharacters() throws JSONException {
-        JSONArray array = new JSONArray(Arrays.asList(5, 6));
-        assertEquals("5\"6", array.join("\""));
-    }
-
-    @Test
-    public void testToJSONObject() throws JSONException {
-        JSONArray keys = new JSONArray();
-        keys.put("a");
-        keys.put("b");
-
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        values.put(false);
-
-        JSONObject object = values.toJSONObject(keys);
-        assertEquals(5.5d, object.get("a"));
-        assertEquals(false, object.get("b"));
-
-        keys.put(0, "a");
-        values.put(0, 11.0d);
-        assertEquals(5.5d, object.get("a"));
-    }
-
-    @Test
-    public void testToJSONObjectWithNulls() throws JSONException {
-        JSONArray keys = new JSONArray();
-        keys.put("a");
-        keys.put("b");
-
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        values.put(null);
-
-        // null values are stripped!
-        JSONObject object = values.toJSONObject(keys);
-        assertEquals(1, object.length());
-        assertFalse(object.has("b"));
-        assertEquals("{\"a\":5.5}", object.toString());
-    }
-
-    @Test
-    public void testToJSONObjectMoreNamesThanValues() throws JSONException {
-        JSONArray keys = new JSONArray();
-        keys.put("a");
-        keys.put("b");
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        JSONObject object = values.toJSONObject(keys);
-        assertEquals(1, object.length());
-        assertEquals(5.5d, object.get("a"));
-    }
-
-    @Test
-    public void testToJSONObjectMoreValuesThanNames() throws JSONException {
-        JSONArray keys = new JSONArray();
-        keys.put("a");
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        values.put(11.0d);
-        JSONObject object = values.toJSONObject(keys);
-        assertEquals(1, object.length());
-        assertEquals(5.5d, object.get("a"));
-    }
-
-    @Test
-    public void testToJSONObjectNullKey() throws JSONException {
-        JSONArray keys = new JSONArray();
-        keys.put(JSONObject.NULL);
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        JSONObject object = values.toJSONObject(keys);
-        assertEquals(1, object.length());
-        assertEquals(5.5d, object.get("null"));
-    }
-
-    @Test
-    public void testPutUnsupportedNumbers() throws JSONException {
-        JSONArray array = new JSONArray();
-
-        try {
-            array.put(Double.NaN);
-            fail();
-        } catch (JSONException e) {
-            // expected
-        }
-        try {
-            array.put(0, Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException e) {
-            // expected
-        }
-        try {
-            array.put(0, Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void testPutUnsupportedNumbersAsObject() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put(Double.valueOf(Double.NaN));
-        array.put(Double.valueOf(Double.NEGATIVE_INFINITY));
-        array.put(Double.valueOf(Double.POSITIVE_INFINITY));
-        assertEquals(null, array.toString());
-    }
-
-    /**
-     * Although JSONArray is usually defensive about which numbers it accepts,
-     * it doesn't check inputs in its constructor.
-     */
-    @Test
-    public void testCreateWithUnsupportedNumbers() throws JSONException {
-        JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
-        assertEquals(2, array.length());
-        assertEquals(5.5, array.getDouble(0), 0);
-        assertEquals(Double.NaN, array.getDouble(1), 0);
-    }
-
-    @Test
-    public void testToStringWithUnsupportedNumbers() throws JSONException {
-        // when the array contains an unsupported number, toString returns null!
-        JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
-        assertNull(array.toString());
-    }
-
-    @Test
-    public void testListConstructorCopiesContents() throws JSONException {
-        // have to use asList instead of Collections.singleton() to allow mutation
-        //noinspection ArraysAsListWithZeroOrOneArgument
-        List<Object> contents = Arrays.<Object>asList(5);
-        JSONArray array = new JSONArray(contents);
-        contents.set(0, 10);
-        assertEquals(5, array.get(0));
-    }
-
-    @Test
-    public void testTokenerConstructor() throws JSONException {
-        JSONArray object = new JSONArray(new JSONTokener("[false]"));
-        assertEquals(1, object.length());
-        assertEquals(false, object.get(0));
-    }
-
-    @Test
-    public void testTokenerConstructorWrongType() throws JSONException {
-        try {
-            new JSONArray(new JSONTokener("{\"foo\": false}"));
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testTokenerConstructorNull() throws JSONException {
-        try {
-            new JSONArray((JSONTokener) null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    @Test
-    public void testTokenerConstructorParseFail() {
-        try {
-            new JSONArray(new JSONTokener("["));
-            fail();
-        } catch (JSONException ignored) {
-        } catch (StackOverflowError e) {
-            fail("Stack overflowed on input: \"[\"");
-        }
-    }
-
-    @Test
-    public void testStringConstructor() throws JSONException {
-        JSONArray object = new JSONArray("[false]");
-        assertEquals(1, object.length());
-        assertEquals(false, object.get(0));
-    }
-
-    @Test
-    public void testStringConstructorWrongType() throws JSONException {
-        try {
-            new JSONArray("{\"foo\": false}");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testStringConstructorNull() throws JSONException {
-        try {
-            new JSONArray((String) null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    @Test
-    public void testStringConstructorParseFail() {
-        try {
-            new JSONArray("[");
-            fail();
-        } catch (JSONException ignored) {
-        } catch (StackOverflowError e) {
-            fail("Stack overflowed on input: \"[\"");
-        }
-    }
-
-    @Test
-    public void testCreate() throws JSONException {
-        JSONArray array = new JSONArray(Arrays.asList(5.5, true));
-        assertEquals(2, array.length());
-        assertEquals(5.5, array.getDouble(0), 0.0);
-        assertEquals(true, array.get(1));
-        assertEquals("[5.5,true]", array.toString());
-    }
-
-    @Test
-    public void testAccessOutOfBounds() throws JSONException {
-        JSONArray array = new JSONArray();
-        array.put("foo");
-        assertEquals(null, array.opt(3));
-        assertEquals(null, array.opt(-3));
-        assertEquals("", array.optString(3));
-        assertEquals("", array.optString(-3));
-        try {
-            array.get(3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.get(-3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.getString(3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            array.getString(-3);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void test_remove() throws Exception {
-        JSONArray a = new JSONArray();
-        assertEquals(null, a.remove(-1));
-        assertEquals(null, a.remove(0));
-
-        a.put("hello");
-        assertEquals(null, a.remove(-1));
-        assertEquals(null, a.remove(1));
-        assertEquals("hello", a.remove(0));
-        assertEquals(null, a.remove(0));
-    }
-
-    enum MyEnum { A, B, C }
-
-    // https://code.google.com/p/android/issues/detail?id=62539
-    // but changed in open-json to return toString for all enums
-    @Test
-    public void testEnums() throws Exception {
-        // This works because it's in java.* and any class in there falls back to toString.
-        JSONArray a1 = new JSONArray(java.lang.annotation.RetentionPolicy.values());
-        assertEquals("[\"SOURCE\",\"CLASS\",\"RUNTIME\"]", a1.toString());
-
-        // This doesn't because it's not.
-        JSONArray a2 = new JSONArray(MyEnum.values());
-        assertEquals("[\"A\",\"B\",\"C\"]", a2.toString());
-    }
+  @Test
+  public void testEmptyArray() throws JSONException {
+    JSONArray array = new JSONArray();
+    assertEquals(0, array.length());
+    assertEquals("", array.join(" AND "));
+    try {
+      array.get(0);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.getBoolean(0);
+      fail();
+    } catch (JSONException ignored) {
+    }
+
+    assertEquals("[]", array.toString());
+    assertEquals("[]", array.toString(4));
+
+    // out of bounds is co-opted with defaulting
+    assertTrue(array.isNull(0));
+    assertNull(array.opt(0));
+    assertFalse(array.optBoolean(0));
+    assertTrue(array.optBoolean(0, true));
+
+    // bogus (but documented) behaviour: returns null rather than an empty object!
+    assertNull(array.toJSONObject(new JSONArray()));
+  }
+
+  @Test
+  public void testEqualsAndHashCode() throws JSONException {
+    JSONArray a = new JSONArray();
+    JSONArray b = new JSONArray();
+    assertTrue(a.equals(b));
+    assertEquals("equals() not consistent with hashCode()", a.hashCode(), b.hashCode());
+
+    a.put(true);
+    a.put(false);
+    b.put(true);
+    b.put(false);
+    assertTrue(a.equals(b));
+    assertEquals(a.hashCode(), b.hashCode());
+
+    b.put(true);
+    assertFalse(a.equals(b));
+    assertTrue(a.hashCode() != b.hashCode());
+  }
+
+  @Test
+  public void testBooleans() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(true);
+    array.put(false);
+    array.put(2, false);
+    array.put(3, false);
+    array.put(2, true);
+    assertEquals("[true,false,true,false]", array.toString());
+    assertEquals(4, array.length());
+    assertEquals(Boolean.TRUE, array.get(0));
+    assertEquals(Boolean.FALSE, array.get(1));
+    assertEquals(Boolean.TRUE, array.get(2));
+    assertEquals(Boolean.FALSE, array.get(3));
+    assertFalse(array.isNull(0));
+    assertFalse(array.isNull(1));
+    assertFalse(array.isNull(2));
+    assertFalse(array.isNull(3));
+    assertEquals(true, array.optBoolean(0));
+    assertEquals(false, array.optBoolean(1, true));
+    assertEquals(true, array.optBoolean(2, false));
+    assertEquals(false, array.optBoolean(3));
+    assertEquals("true", array.getString(0));
+    assertEquals("false", array.getString(1));
+    assertEquals("true", array.optString(2));
+    assertEquals("false", array.optString(3, "x"));
+    assertEquals("[\n     true,\n     false,\n     true,\n     false\n]", array.toString(5));
+
+    JSONArray other = new JSONArray();
+    other.put(true);
+    other.put(false);
+    other.put(true);
+    other.put(false);
+    assertTrue(array.equals(other));
+    other.put(true);
+    assertFalse(array.equals(other));
+
+    other = new JSONArray();
+    other.put("true");
+    other.put("false");
+    other.put("truE");
+    other.put("FALSE");
+    assertFalse(array.equals(other));
+    assertFalse(other.equals(array));
+    assertEquals(true, other.getBoolean(0));
+    assertEquals(false, other.optBoolean(1, true));
+    assertEquals(true, other.optBoolean(2));
+    assertEquals(false, other.getBoolean(3));
+  }
+
+  // http://code.google.com/p/android/issues/detail?id=16411
+  @Test
+  public void testCoerceStringToBoolean() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put("maybe");
+    try {
+      array.getBoolean(0);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals(false, array.optBoolean(0));
+    assertEquals(true, array.optBoolean(0, true));
+  }
+
+  @Test
+  public void testNulls() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(3, null);
+    array.put(0, JSONObject.NULL);
+    assertEquals(4, array.length());
+    assertEquals("[null,null,null,null]", array.toString());
+
+    // there's 2 ways to represent null; each behaves differently!
+    assertEquals(JSONObject.NULL, array.get(0));
+    try {
+      array.get(1);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.get(2);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.get(3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals(JSONObject.NULL, array.opt(0));
+    assertEquals(null, array.opt(1));
+    assertEquals(null, array.opt(2));
+    assertEquals(null, array.opt(3));
+    assertTrue(array.isNull(0));
+    assertTrue(array.isNull(1));
+    assertTrue(array.isNull(2));
+    assertTrue(array.isNull(3));
+    assertEquals("null", array.optString(0));
+    assertEquals("", array.optString(1));
+    assertEquals("", array.optString(2));
+    assertEquals("", array.optString(3));
+  }
+
+  /**
+   * Our behaviour is questioned by this bug: http://code.google.com/p/android/issues/detail?id=7257
+   */
+  @Test
+  public void testParseNullYieldsJSONObjectNull() throws JSONException {
+    JSONArray array = new JSONArray("[\"null\",null]");
+    array.put(null);
+    assertEquals("null", array.get(0));
+    assertEquals(JSONObject.NULL, array.get(1));
+    try {
+      array.get(2);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals("null", array.getString(0));
+    assertEquals("null", array.getString(1));
+    try {
+      array.getString(2);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testNumbers() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(Double.MIN_VALUE);
+    array.put(9223372036854775806L);
+    array.put(Double.MAX_VALUE);
+    array.put(-0d);
+    assertEquals(4, array.length());
+
+    // toString() and getString(int) return different values for -0d
+    assertEquals("[4.9E-324,9223372036854775806,1.7976931348623157E308,-0]", array.toString());
+
+    assertEquals(Double.MIN_VALUE, array.get(0));
+    assertEquals(9223372036854775806L, array.get(1));
+    assertEquals(Double.MAX_VALUE, array.get(2));
+    assertEquals(-0d, array.get(3));
+    assertEquals(Double.MIN_VALUE, array.getDouble(0), 0);
+    assertEquals(9.223372036854776E18, array.getDouble(1), 0);
+    assertEquals(Double.MAX_VALUE, array.getDouble(2), 0);
+    assertEquals(-0d, array.getDouble(3), 0);
+    assertEquals(0, array.getLong(0));
+    assertEquals(9223372036854775806L, array.getLong(1));
+    assertEquals(Long.MAX_VALUE, array.getLong(2));
+    assertEquals(0, array.getLong(3));
+    assertEquals(0, array.getInt(0));
+    assertEquals(-2, array.getInt(1));
+    assertEquals(Integer.MAX_VALUE, array.getInt(2));
+    assertEquals(0, array.getInt(3));
+    assertEquals(Double.MIN_VALUE, array.opt(0));
+    assertEquals(Double.MIN_VALUE, array.optDouble(0), 0);
+    assertEquals(0, array.optLong(0, 1L));
+    assertEquals(0, array.optInt(0, 1));
+    assertEquals("4.9E-324", array.getString(0));
+    assertEquals("9223372036854775806", array.getString(1));
+    assertEquals("1.7976931348623157E308", array.getString(2));
+    assertEquals("-0.0", array.getString(3));
+
+    JSONArray other = new JSONArray();
+    other.put(Double.MIN_VALUE);
+    other.put(9223372036854775806L);
+    other.put(Double.MAX_VALUE);
+    other.put(-0d);
+    assertTrue(array.equals(other));
+    other.put(0, 0L);
+    assertFalse(array.equals(other));
+  }
+
+  @Test
+  public void testStrings() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put("true");
+    array.put("5.5");
+    array.put("9223372036854775806");
+    array.put("null");
+    array.put("5\"8' tall");
+    assertEquals(5, array.length());
+    assertEquals("[\"true\",\"5.5\",\"9223372036854775806\",\"null\",\"5\\\"8' tall\"]",
+        array.toString());
+
+    // although the documentation doesn't mention it, join() escapes text and wraps
+    // strings in quotes
+    assertEquals("\"true\" \"5.5\" \"9223372036854775806\" \"null\" \"5\\\"8' tall\"",
+        array.join(" "));
+
+    assertEquals("true", array.get(0));
+    assertEquals("null", array.getString(3));
+    assertEquals("5\"8' tall", array.getString(4));
+    assertEquals("true", array.opt(0));
+    assertEquals("5.5", array.optString(1));
+    assertEquals("9223372036854775806", array.optString(2, null));
+    assertEquals("null", array.optString(3, "-1"));
+    assertFalse(array.isNull(0));
+    assertFalse(array.isNull(3));
+
+    assertEquals(true, array.getBoolean(0));
+    assertEquals(true, array.optBoolean(0));
+    assertEquals(true, array.optBoolean(0, false));
+    assertEquals(0, array.optInt(0));
+    assertEquals(-2, array.optInt(0, -2));
+
+    assertEquals(5.5d, array.getDouble(1), 0);
+    assertEquals(5L, array.getLong(1));
+    assertEquals(5, array.getInt(1));
+    assertEquals(5, array.optInt(1, 3));
+
+    // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
+    // double and then converting that to a long. This is consistent with JavaScript.
+    assertEquals(9223372036854775807L, array.getLong(2));
+    assertEquals(9.223372036854776E18, array.getDouble(2), 0);
+    assertEquals(Integer.MAX_VALUE, array.getInt(2));
+
+    assertFalse(array.isNull(3));
+    try {
+      array.getDouble(3);
+      fail();
+    } catch (JSONException e) {
+      // expected
+    }
+    assertEquals(Double.NaN, array.optDouble(3), 0);
+    assertEquals(-1.0d, array.optDouble(3, -1.0d), 0);
+  }
+
+  @Test
+  public void testJoin() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(null);
+    assertEquals("null", array.join(" & "));
+    array.put("\"");
+    assertEquals("null & \"\\\"\"", array.join(" & "));
+    array.put(5);
+    assertEquals("null & \"\\\"\" & 5", array.join(" & "));
+    array.put(true);
+    assertEquals("null & \"\\\"\" & 5 & true", array.join(" & "));
+    array.put(new JSONArray(Arrays.asList(true, false)));
+    assertEquals("null & \"\\\"\" & 5 & true & [true,false]", array.join(" & "));
+    array.put(new JSONObject(Collections.singletonMap("x", 6)));
+    assertEquals("null & \"\\\"\" & 5 & true & [true,false] & {\"x\":6}", array.join(" & "));
+  }
+
+  @Test
+  public void testJoinWithNull() throws JSONException {
+    JSONArray array = new JSONArray(Arrays.asList(5, 6));
+    assertEquals("5null6", array.join(null));
+  }
+
+  @Test
+  public void testJoinWithSpecialCharacters() throws JSONException {
+    JSONArray array = new JSONArray(Arrays.asList(5, 6));
+    assertEquals("5\"6", array.join("\""));
+  }
+
+  @Test
+  public void testToJSONObject() throws JSONException {
+    JSONArray keys = new JSONArray();
+    keys.put("a");
+    keys.put("b");
+
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    values.put(false);
+
+    JSONObject object = values.toJSONObject(keys);
+    assertEquals(5.5d, object.get("a"));
+    assertEquals(false, object.get("b"));
+
+    keys.put(0, "a");
+    values.put(0, 11.0d);
+    assertEquals(5.5d, object.get("a"));
+  }
+
+  @Test
+  public void testToJSONObjectWithNulls() throws JSONException {
+    JSONArray keys = new JSONArray();
+    keys.put("a");
+    keys.put("b");
+
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    values.put(null);
+
+    // null values are stripped!
+    JSONObject object = values.toJSONObject(keys);
+    assertEquals(1, object.length());
+    assertFalse(object.has("b"));
+    assertEquals("{\"a\":5.5}", object.toString());
+  }
+
+  @Test
+  public void testToJSONObjectMoreNamesThanValues() throws JSONException {
+    JSONArray keys = new JSONArray();
+    keys.put("a");
+    keys.put("b");
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    JSONObject object = values.toJSONObject(keys);
+    assertEquals(1, object.length());
+    assertEquals(5.5d, object.get("a"));
+  }
+
+  @Test
+  public void testToJSONObjectMoreValuesThanNames() throws JSONException {
+    JSONArray keys = new JSONArray();
+    keys.put("a");
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    values.put(11.0d);
+    JSONObject object = values.toJSONObject(keys);
+    assertEquals(1, object.length());
+    assertEquals(5.5d, object.get("a"));
+  }
+
+  @Test
+  public void testToJSONObjectNullKey() throws JSONException {
+    JSONArray keys = new JSONArray();
+    keys.put(JSONObject.NULL);
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    JSONObject object = values.toJSONObject(keys);
+    assertEquals(1, object.length());
+    assertEquals(5.5d, object.get("null"));
+  }
+
+  @Test
+  public void testPutUnsupportedNumbers() throws JSONException {
+    JSONArray array = new JSONArray();
+
+    try {
+      array.put(Double.NaN);
+      fail();
+    } catch (JSONException e) {
+      // expected
+    }
+    try {
+      array.put(0, Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException e) {
+      // expected
+    }
+    try {
+      array.put(0, Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException e) {
+      // expected
+    }
+  }
+
+  @Test
+  public void testPutUnsupportedNumbersAsObject() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put(Double.valueOf(Double.NaN));
+    array.put(Double.valueOf(Double.NEGATIVE_INFINITY));
+    array.put(Double.valueOf(Double.POSITIVE_INFINITY));
+    assertEquals(null, array.toString());
+  }
+
+  /**
+   * Although JSONArray is usually defensive about which numbers it accepts, it doesn't check inputs
+   * in its constructor.
+   */
+  @Test
+  public void testCreateWithUnsupportedNumbers() throws JSONException {
+    JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
+    assertEquals(2, array.length());
+    assertEquals(5.5, array.getDouble(0), 0);
+    assertEquals(Double.NaN, array.getDouble(1), 0);
+  }
+
+  @Test
+  public void testToStringWithUnsupportedNumbers() throws JSONException {
+    // when the array contains an unsupported number, toString returns null!
+    JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
+    assertNull(array.toString());
+  }
+
+  @Test
+  public void testListConstructorCopiesContents() throws JSONException {
+    // have to use asList instead of Collections.singleton() to allow mutation
+    // noinspection ArraysAsListWithZeroOrOneArgument
+    List<Object> contents = Arrays.<Object>asList(5);
+    JSONArray array = new JSONArray(contents);
+    contents.set(0, 10);
+    assertEquals(5, array.get(0));
+  }
+
+  @Test
+  public void testTokenerConstructor() throws JSONException {
+    JSONArray object = new JSONArray(new JSONTokener("[false]"));
+    assertEquals(1, object.length());
+    assertEquals(false, object.get(0));
+  }
+
+  @Test
+  public void testTokenerConstructorWrongType() throws JSONException {
+    try {
+      new JSONArray(new JSONTokener("{\"foo\": false}"));
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testTokenerConstructorNull() throws JSONException {
+    try {
+      new JSONArray((JSONTokener) null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  @Test
+  public void testTokenerConstructorParseFail() {
+    try {
+      new JSONArray(new JSONTokener("["));
+      fail();
+    } catch (JSONException ignored) {
+    } catch (StackOverflowError e) {
+      fail("Stack overflowed on input: \"[\"");
+    }
+  }
+
+  @Test
+  public void testStringConstructor() throws JSONException {
+    JSONArray object = new JSONArray("[false]");
+    assertEquals(1, object.length());
+    assertEquals(false, object.get(0));
+  }
+
+  @Test
+  public void testStringConstructorWrongType() throws JSONException {
+    try {
+      new JSONArray("{\"foo\": false}");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testStringConstructorNull() throws JSONException {
+    try {
+      new JSONArray((String) null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  @Test
+  public void testStringConstructorParseFail() {
+    try {
+      new JSONArray("[");
+      fail();
+    } catch (JSONException ignored) {
+    } catch (StackOverflowError e) {
+      fail("Stack overflowed on input: \"[\"");
+    }
+  }
+
+  @Test
+  public void testCreate() throws JSONException {
+    JSONArray array = new JSONArray(Arrays.asList(5.5, true));
+    assertEquals(2, array.length());
+    assertEquals(5.5, array.getDouble(0), 0.0);
+    assertEquals(true, array.get(1));
+    assertEquals("[5.5,true]", array.toString());
+  }
+
+  @Test
+  public void testAccessOutOfBounds() throws JSONException {
+    JSONArray array = new JSONArray();
+    array.put("foo");
+    assertEquals(null, array.opt(3));
+    assertEquals(null, array.opt(-3));
+    assertEquals("", array.optString(3));
+    assertEquals("", array.optString(-3));
+    try {
+      array.get(3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.get(-3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.getString(3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      array.getString(-3);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void test_remove() throws Exception {
+    JSONArray a = new JSONArray();
+    assertEquals(null, a.remove(-1));
+    assertEquals(null, a.remove(0));
+
+    a.put("hello");
+    assertEquals(null, a.remove(-1));
+    assertEquals(null, a.remove(1));
+    assertEquals("hello", a.remove(0));
+    assertEquals(null, a.remove(0));
+  }
+
+  enum MyEnum {
+    A, B, C
+  }
+
+  // https://code.google.com/p/android/issues/detail?id=62539
+  // but changed in open-json to return toString for all enums
+  @Test
+  public void testEnums() throws Exception {
+    // This works because it's in java.* and any class in there falls back to toString.
+    JSONArray a1 = new JSONArray(java.lang.annotation.RetentionPolicy.values());
+    assertEquals("[\"SOURCE\",\"CLASS\",\"RUNTIME\"]", a1.toString());
+
+    // This doesn't because it's not.
+    JSONArray a2 = new JSONArray(MyEnum.values());
+    assertEquals("[\"A\",\"B\",\"C\"]", a2.toString());
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONFunctionTestObject.java b/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
index fe18ab6..9d24487 100755
--- a/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
+++ b/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
@@ -4,14 +4,14 @@ package org.json;
  * Class to test the function hack
  */
 public class JSONFunctionTestObject {
-    private String value;
+  private String value;
 
-    public JSONFunctionTestObject(String value) {
-        this.value = value;
-    }
+  public JSONFunctionTestObject(String value) {
+    this.value = value;
+  }
 
-    @Override
-    public String toString() {
-        return value;
-    }
-}
\ No newline at end of file
+  @Override
+  public String toString() {
+    return value;
+  }
+}


[19/34] geode git commit: GEODE-2142: removing tests so run precheckin

Posted by kl...@apache.org.
GEODE-2142: removing tests so run precheckin


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/abeaa244
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/abeaa244
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/abeaa244

Branch: refs/heads/GEODE-4160-mockito
Commit: abeaa244b5c814f6040176d34551061c4b3b3b25
Parents: e220d09
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 16:56:17 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 geode-json/src/test/java/org/json/FileTest.java |  160 ---
 .../src/test/java/org/json/JSONArrayTest.java   |  607 ---------
 .../java/org/json/JSONFunctionTestObject.java   |   17 -
 .../src/test/java/org/json/JSONObjectTest.java  | 1190 ------------------
 .../test/java/org/json/JSONStringerTest.java    |  416 ------
 .../src/test/java/org/json/JSONTokenerTest.java |  616 ---------
 .../src/test/java/org/json/ParsingTest.java     |  291 -----
 .../src/test/java/org/json/SelfUseTest.java     |  273 ----
 8 files changed, 3570 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/FileTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/FileTest.java b/geode-json/src/test/java/org/json/FileTest.java
deleted file mode 100755
index 36fcae9..0000000
--- a/geode-json/src/test/java/org/json/FileTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package org.json;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Set;
-
-public class FileTest {
-  @Test
-  public void testFile() throws IOException, JSONException {
-    String ref = "[\n" + "  {\n" + "    \"_id\": \"58309f3bd307b72ae49a9b23\",\n"
-        + "    \"index\": 0,\n" + "    \"guid\": \"5764ebd8-b333-469e-8d83-4eb5658f1566\",\n"
-        + "    \"isActive\": true,\n" + "    \"balance\": \"$1,099.93\",\n"
-        + "    \"picture\": \"http://placehold.it/32x32\",\n" + "    \"age\": 37,\n"
-        + "    \"eyeColor\": \"blue\",\n" + "    \"name\": \"Barrera Wilkerson\",\n"
-        + "    \"gender\": \"male\",\n" + "    \"company\": \"VURBO\",\n"
-        + "    \"email\": \"barrerawilkerson@vurbo.com\",\n"
-        + "    \"phone\": \"+1 (817) 429-2473\",\n"
-        + "    \"address\": \"522 Vanderveer Street, Detroit, Wyoming, 4320\",\n"
-        + "    \"about\": \"Et officia aute ullamco magna adipisicing non ut cupidatat cupidatat aliquip. Tempor occaecat ex ad dolore aliquip mollit ea esse ipsum. Est incididunt sunt commodo duis est. Reprehenderit in ut reprehenderit ad culpa ea fugiat et est adipisicing aliquip. Id mollit voluptate qui pariatur officia.\\r\\n\",\n"
-        + "    \"registered\": \"2016-06-29T08:54:14 +07:00\",\n"
-        + "    \"latitude\": -87.548434,\n" + "    \"longitude\": 64.251242,\n"
-        + "    \"tags\": [\n" + "      \"aliqua\",\n" + "      \"ex\",\n" + "      \"sit\",\n"
-        + "      \"magna\",\n" + "      \"dolor\",\n" + "      \"laborum\",\n" + "      \"non\"\n"
-        + "    ],\n" + "    \"friends\": [\n" + "      {\n" + "        \"id\": 0,\n"
-        + "        \"name\": \"Byers Pratt\"\n" + "      },\n" + "      {\n"
-        + "        \"id\": 1,\n" + "        \"name\": \"Kennedy Contreras\"\n" + "      },\n"
-        + "      {\n" + "        \"id\": 2,\n" + "        \"name\": \"Frazier Monroe\"\n"
-        + "      }\n" + "    ],\n"
-        + "    \"greeting\": \"Hello, Barrera Wilkerson! You have 3 unread messages.\",\n"
-        + "    \"favoriteFruit\": \"banana\"\n" + "  },\n" + "  {\n"
-        + "    \"_id\": \"58309f3b1f506440093a41d1\",\n" + "    \"index\": 1,\n"
-        + "    \"guid\": \"de1a6cc9-f8b3-426e-b68a-cc30e1fff3c1\",\n" + "    \"isActive\": false,\n"
-        + "    \"balance\": \"$3,397.60\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
-        + "    \"age\": 32,\n" + "    \"eyeColor\": \"blue\",\n"
-        + "    \"name\": \"Trisha Morris\",\n" + "    \"gender\": \"female\",\n"
-        + "    \"company\": \"AMTAP\",\n" + "    \"email\": \"trishamorris@amtap.com\",\n"
-        + "    \"phone\": \"+1 (805) 423-3375\",\n"
-        + "    \"address\": \"495 Tampa Court, Libertytown, New Hampshire, 5177\",\n"
-        + "    \"about\": \"Elit culpa Lorem dolor sit laborum ut ullamco ullamco nostrud reprehenderit adipisicing eiusmod. Aliqua quis dolor esse sint. Dolore in excepteur laborum anim ut consectetur. Nisi officia est eu ex ex id. Ipsum duis ullamco ad ut labore dolor. In amet tempor deserunt ullamco velit eu fugiat.\\r\\n\",\n"
-        + "    \"registered\": \"2015-02-08T06:14:19 +08:00\",\n"
-        + "    \"latitude\": -81.956277,\n" + "    \"longitude\": 143.685584,\n"
-        + "    \"tags\": [\n" + "      \"cillum\",\n" + "      \"ullamco\",\n"
-        + "      \"magna\",\n" + "      \"cillum\",\n" + "      \"voluptate\",\n"
-        + "      \"magna\",\n" + "      \"exercitation\"\n" + "    ],\n" + "    \"friends\": [\n"
-        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Fuentes Stout\"\n"
-        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
-        + "        \"name\": \"Violet Vargas\"\n" + "      },\n" + "      {\n"
-        + "        \"id\": 2,\n" + "        \"name\": \"Schmidt Wilder\"\n" + "      }\n"
-        + "    ],\n" + "    \"greeting\": \"Hello, Trisha Morris! You have 4 unread messages.\",\n"
-        + "    \"favoriteFruit\": \"strawberry\"\n" + "  },\n" + "  {\n"
-        + "    \"_id\": \"58309f3beaef2f31339b3755\",\n" + "    \"index\": 2,\n"
-        + "    \"guid\": \"0bf387b7-abc2-4828-becc-1269928f7c3d\",\n" + "    \"isActive\": false,\n"
-        + "    \"balance\": \"$1,520.64\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
-        + "    \"age\": 37,\n" + "    \"eyeColor\": \"blue\",\n"
-        + "    \"name\": \"Deanna Santiago\",\n" + "    \"gender\": \"female\",\n"
-        + "    \"company\": \"MEGALL\",\n" + "    \"email\": \"deannasantiago@megall.com\",\n"
-        + "    \"phone\": \"+1 (916) 511-2291\",\n"
-        + "    \"address\": \"919 Fayette Street, Homestead, Utah, 8669\",\n"
-        + "    \"about\": \"Sit amet ex quis velit irure Lorem non quis aliquip dolor pariatur nulla Lorem officia. Deserunt officia sit velit labore sint nostrud elit aliquip labore ullamco consectetur id amet. Ullamco duis commodo sit incididunt. Fugiat consectetur ad incididunt officia. Sint cillum minim laborum laboris id cillum est exercitation in eiusmod qui.\\r\\n\",\n"
-        + "    \"registered\": \"2015-11-18T08:39:28 +08:00\",\n" + "    \"latitude\": 79.105701,\n"
-        + "    \"longitude\": -146.901754,\n" + "    \"tags\": [\n" + "      \"non\",\n"
-        + "      \"ullamco\",\n" + "      \"cillum\",\n" + "      \"ipsum\",\n"
-        + "      \"amet\",\n" + "      \"aliqua\",\n" + "      \"aliquip\"\n" + "    ],\n"
-        + "    \"friends\": [\n" + "      {\n" + "        \"id\": 0,\n"
-        + "        \"name\": \"Hanson Anderson\"\n" + "      },\n" + "      {\n"
-        + "        \"id\": 1,\n" + "        \"name\": \"Pollard Soto\"\n" + "      },\n"
-        + "      {\n" + "        \"id\": 2,\n" + "        \"name\": \"Barlow Campbell\"\n"
-        + "      }\n" + "    ],\n"
-        + "    \"greeting\": \"Hello, Deanna Santiago! You have 7 unread messages.\",\n"
-        + "    \"favoriteFruit\": \"apple\"\n" + "  },\n" + "  {\n"
-        + "    \"_id\": \"58309f3b49a68ad01346f27f\",\n" + "    \"index\": 3,\n"
-        + "    \"guid\": \"d29c0dcc-48fb-4ca4-a63b-b47c0e6d6398\",\n" + "    \"isActive\": false,\n"
-        + "    \"balance\": \"$2,069.96\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
-        + "    \"age\": 29,\n" + "    \"eyeColor\": \"green\",\n"
-        + "    \"name\": \"Brooks Gates\",\n" + "    \"gender\": \"male\",\n"
-        + "    \"company\": \"TERRAGEN\",\n" + "    \"email\": \"brooksgates@terragen.com\",\n"
-        + "    \"phone\": \"+1 (875) 483-2224\",\n"
-        + "    \"address\": \"562 Noll Street, Kipp, Louisiana, 7659\",\n"
-        + "    \"about\": \"Reprehenderit laboris mollit nulla commodo quis laborum commodo. Laborum aliquip laboris officia minim ipsum laborum ipsum reprehenderit quis laboris est sint culpa. Culpa magna aute mollit exercitation.\\r\\n\",\n"
-        + "    \"registered\": \"2016-05-04T10:34:38 +07:00\",\n" + "    \"latitude\": 72.77079,\n"
-        + "    \"longitude\": -134.291768,\n" + "    \"tags\": [\n" + "      \"est\",\n"
-        + "      \"sunt\",\n" + "      \"laboris\",\n" + "      \"ea\",\n" + "      \"proident\",\n"
-        + "      \"aute\",\n" + "      \"excepteur\"\n" + "    ],\n" + "    \"friends\": [\n"
-        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Roxanne Morgan\"\n"
-        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
-        + "        \"name\": \"Tamara Kelly\"\n" + "      },\n" + "      {\n"
-        + "        \"id\": 2,\n" + "        \"name\": \"Cleveland Bush\"\n" + "      }\n"
-        + "    ],\n" + "    \"greeting\": \"Hello, Brooks Gates! You have 1 unread messages.\",\n"
-        + "    \"favoriteFruit\": \"banana\"\n" + "  },\n" + "  {\n"
-        + "    \"_id\": \"58309f3be746700e9af9a645\",\n" + "    \"index\": 4,\n"
-        + "    \"guid\": \"54382bd6-c476-469d-9e1c-e546f959db51\",\n" + "    \"isActive\": true,\n"
-        + "    \"balance\": \"$2,012.57\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
-        + "    \"age\": 40,\n" + "    \"eyeColor\": \"brown\",\n"
-        + "    \"name\": \"Jackie Thomas\",\n" + "    \"gender\": \"female\",\n"
-        + "    \"company\": \"HINWAY\",\n" + "    \"email\": \"jackiethomas@hinway.com\",\n"
-        + "    \"phone\": \"+1 (843) 470-2096\",\n"
-        + "    \"address\": \"910 Emerson Place, Gwynn, Federated States Of Micronesia, 4688\",\n"
-        + "    \"about\": \"Id cupidatat laboris elit est eiusmod esse nostrud. Ex commodo nisi voluptate est nisi laborum officia sint incididunt pariatur qui deserunt ullamco. Fugiat proident magna ipsum sit sint id adipisicing sit nostrud labore sit officia. Eiusmod exercitation non enim excepteur amet irure ullamco consectetur cupidatat proident Lorem reprehenderit aliquip. Veniam esse dolor Lorem incididunt proident officia enim in incididunt culpa. Mollit voluptate commodo aliquip anim ipsum nostrud ut labore enim labore qui do minim incididunt. Quis irure proident voluptate nisi qui sunt aute duis irure.\\r\\n\",\n"
-        + "    \"registered\": \"2014-08-03T09:21:43 +07:00\",\n" + "    \"latitude\": 84.871256,\n"
-        + "    \"longitude\": 2.043339,\n" + "    \"tags\": [\n" + "      \"tempor\",\n"
-        + "      \"ut\",\n" + "      \"deserunt\",\n" + "      \"esse\",\n" + "      \"nostrud\",\n"
-        + "      \"dolore\",\n" + "      \"ex\"\n" + "    ],\n" + "    \"friends\": [\n"
-        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Lois Walters\"\n"
-        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
-        + "        \"name\": \"Brewer Buchanan\"\n" + "      },\n" + "      {\n"
-        + "        \"id\": 2,\n" + "        \"name\": \"Mccormick Fleming\"\n" + "      }\n"
-        + "    ],\n" + "    \"greeting\": \"Hello, Jackie Thomas! You have 2 unread messages.\",\n"
-        + "    \"favoriteFruit\": \"banana\"\n" + "  }\n" + "]";
-
-    JSONArray x1 = (JSONArray) new JSONTokener(
-        new InputStreamReader(this.getClass().getResourceAsStream("/sample-01.json"))).nextValue();
-    JSONArray x2 = (JSONArray) new JSONTokener(ref).nextValue();
-
-    Assert.assertTrue(jsonEquals(x1, x2));
-  }
-
-  private boolean jsonEquals(JSONArray x1, JSONArray x2) throws JSONException {
-    if (x1.length() != x2.length()) {
-      return false;
-    }
-
-    for (int i = 0; i < x1.length(); i++) {
-      Object element1 = x1.get(i);
-      Object element2 = x2.get(i);
-      if (!jsonEquals(element1, element2)) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  private boolean jsonEquals(JSONObject x1, JSONObject x2) throws JSONException {
-    if (x1.length() != x2.length()) {
-      return false;
-    }
-    Set<String> names = x1.keySet();
-    for (String name : names) {
-      if (!jsonEquals(x1.get(name), x2.get(name))) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  private boolean jsonEquals(Object element1, Object element2) throws JSONException {
-    if (!element1.getClass().equals(element2.getClass())) {
-      return false;
-    }
-    if (element1 instanceof JSONObject) {
-      return jsonEquals((JSONObject) element1, (JSONObject) element2);
-    }
-    if (element1 instanceof JSONArray) {
-      return jsonEquals((JSONArray) element1, (JSONArray) element2);
-    }
-    return element1.equals(element2);
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/JSONArrayTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONArrayTest.java b/geode-json/src/test/java/org/json/JSONArrayTest.java
deleted file mode 100755
index 88ba989..0000000
--- a/geode-json/src/test/java/org/json/JSONArrayTest.java
+++ /dev/null
@@ -1,607 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-/**
- * This black box test was written without inspecting the non-free org.json sourcecode.
- */
-public class JSONArrayTest {
-  @Test
-  public void testEmptyArray() throws JSONException {
-    JSONArray array = new JSONArray();
-    assertEquals(0, array.length());
-    assertEquals("", array.join(" AND "));
-    try {
-      array.get(0);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.getBoolean(0);
-      fail();
-    } catch (JSONException ignored) {
-    }
-
-    assertEquals("[]", array.toString());
-    assertEquals("[]", array.toString(4));
-
-    // out of bounds is co-opted with defaulting
-    assertTrue(array.isNull(0));
-    assertNull(array.opt(0));
-    assertFalse(array.optBoolean(0));
-    assertTrue(array.optBoolean(0, true));
-
-    // bogus (but documented) behaviour: returns null rather than an empty object!
-    assertNull(array.toJSONObject(new JSONArray()));
-  }
-
-  @Test
-  public void testEqualsAndHashCode() throws JSONException {
-    JSONArray a = new JSONArray();
-    JSONArray b = new JSONArray();
-    assertTrue(a.equals(b));
-    assertEquals("equals() not consistent with hashCode()", a.hashCode(), b.hashCode());
-
-    a.put(true);
-    a.put(false);
-    b.put(true);
-    b.put(false);
-    assertTrue(a.equals(b));
-    assertEquals(a.hashCode(), b.hashCode());
-
-    b.put(true);
-    assertFalse(a.equals(b));
-    assertTrue(a.hashCode() != b.hashCode());
-  }
-
-  @Test
-  public void testBooleans() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(true);
-    array.put(false);
-    array.put(2, false);
-    array.put(3, false);
-    array.put(2, true);
-    assertEquals("[true,false,true,false]", array.toString());
-    assertEquals(4, array.length());
-    assertEquals(Boolean.TRUE, array.get(0));
-    assertEquals(Boolean.FALSE, array.get(1));
-    assertEquals(Boolean.TRUE, array.get(2));
-    assertEquals(Boolean.FALSE, array.get(3));
-    assertFalse(array.isNull(0));
-    assertFalse(array.isNull(1));
-    assertFalse(array.isNull(2));
-    assertFalse(array.isNull(3));
-    assertEquals(true, array.optBoolean(0));
-    assertEquals(false, array.optBoolean(1, true));
-    assertEquals(true, array.optBoolean(2, false));
-    assertEquals(false, array.optBoolean(3));
-    assertEquals("true", array.getString(0));
-    assertEquals("false", array.getString(1));
-    assertEquals("true", array.optString(2));
-    assertEquals("false", array.optString(3, "x"));
-    assertEquals("[\n     true,\n     false,\n     true,\n     false\n]", array.toString(5));
-
-    JSONArray other = new JSONArray();
-    other.put(true);
-    other.put(false);
-    other.put(true);
-    other.put(false);
-    assertTrue(array.equals(other));
-    other.put(true);
-    assertFalse(array.equals(other));
-
-    other = new JSONArray();
-    other.put("true");
-    other.put("false");
-    other.put("truE");
-    other.put("FALSE");
-    assertFalse(array.equals(other));
-    assertFalse(other.equals(array));
-    assertEquals(true, other.getBoolean(0));
-    assertEquals(false, other.optBoolean(1, true));
-    assertEquals(true, other.optBoolean(2));
-    assertEquals(false, other.getBoolean(3));
-  }
-
-  // http://code.google.com/p/android/issues/detail?id=16411
-  @Test
-  public void testCoerceStringToBoolean() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put("maybe");
-    try {
-      array.getBoolean(0);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals(false, array.optBoolean(0));
-    assertEquals(true, array.optBoolean(0, true));
-  }
-
-  @Test
-  public void testNulls() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(3, null);
-    array.put(0, JSONObject.NULL);
-    assertEquals(4, array.length());
-    assertEquals("[null,null,null,null]", array.toString());
-
-    // there's 2 ways to represent null; each behaves differently!
-    assertEquals(JSONObject.NULL, array.get(0));
-    try {
-      array.get(1);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.get(2);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.get(3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals(JSONObject.NULL, array.opt(0));
-    assertEquals(null, array.opt(1));
-    assertEquals(null, array.opt(2));
-    assertEquals(null, array.opt(3));
-    assertTrue(array.isNull(0));
-    assertTrue(array.isNull(1));
-    assertTrue(array.isNull(2));
-    assertTrue(array.isNull(3));
-    assertEquals("null", array.optString(0));
-    assertEquals("", array.optString(1));
-    assertEquals("", array.optString(2));
-    assertEquals("", array.optString(3));
-  }
-
-  /**
-   * Our behaviour is questioned by this bug: http://code.google.com/p/android/issues/detail?id=7257
-   */
-  @Test
-  public void testParseNullYieldsJSONObjectNull() throws JSONException {
-    JSONArray array = new JSONArray("[\"null\",null]");
-    array.put(null);
-    assertEquals("null", array.get(0));
-    assertEquals(JSONObject.NULL, array.get(1));
-    try {
-      array.get(2);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals("null", array.getString(0));
-    assertEquals("null", array.getString(1));
-    try {
-      array.getString(2);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testNumbers() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(Double.MIN_VALUE);
-    array.put(9223372036854775806L);
-    array.put(Double.MAX_VALUE);
-    array.put(-0d);
-    assertEquals(4, array.length());
-
-    // toString() and getString(int) return different values for -0d
-    assertEquals("[4.9E-324,9223372036854775806,1.7976931348623157E308,-0]", array.toString());
-
-    assertEquals(Double.MIN_VALUE, array.get(0));
-    assertEquals(9223372036854775806L, array.get(1));
-    assertEquals(Double.MAX_VALUE, array.get(2));
-    assertEquals(-0d, array.get(3));
-    assertEquals(Double.MIN_VALUE, array.getDouble(0), 0);
-    assertEquals(9.223372036854776E18, array.getDouble(1), 0);
-    assertEquals(Double.MAX_VALUE, array.getDouble(2), 0);
-    assertEquals(-0d, array.getDouble(3), 0);
-    assertEquals(0, array.getLong(0));
-    assertEquals(9223372036854775806L, array.getLong(1));
-    assertEquals(Long.MAX_VALUE, array.getLong(2));
-    assertEquals(0, array.getLong(3));
-    assertEquals(0, array.getInt(0));
-    assertEquals(-2, array.getInt(1));
-    assertEquals(Integer.MAX_VALUE, array.getInt(2));
-    assertEquals(0, array.getInt(3));
-    assertEquals(Double.MIN_VALUE, array.opt(0));
-    assertEquals(Double.MIN_VALUE, array.optDouble(0), 0);
-    assertEquals(0, array.optLong(0, 1L));
-    assertEquals(0, array.optInt(0, 1));
-    assertEquals("4.9E-324", array.getString(0));
-    assertEquals("9223372036854775806", array.getString(1));
-    assertEquals("1.7976931348623157E308", array.getString(2));
-    assertEquals("-0.0", array.getString(3));
-
-    JSONArray other = new JSONArray();
-    other.put(Double.MIN_VALUE);
-    other.put(9223372036854775806L);
-    other.put(Double.MAX_VALUE);
-    other.put(-0d);
-    assertTrue(array.equals(other));
-    other.put(0, 0L);
-    assertFalse(array.equals(other));
-  }
-
-  @Test
-  public void testStrings() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put("true");
-    array.put("5.5");
-    array.put("9223372036854775806");
-    array.put("null");
-    array.put("5\"8' tall");
-    assertEquals(5, array.length());
-    assertEquals("[\"true\",\"5.5\",\"9223372036854775806\",\"null\",\"5\\\"8' tall\"]",
-        array.toString());
-
-    // although the documentation doesn't mention it, join() escapes text and wraps
-    // strings in quotes
-    assertEquals("\"true\" \"5.5\" \"9223372036854775806\" \"null\" \"5\\\"8' tall\"",
-        array.join(" "));
-
-    assertEquals("true", array.get(0));
-    assertEquals("null", array.getString(3));
-    assertEquals("5\"8' tall", array.getString(4));
-    assertEquals("true", array.opt(0));
-    assertEquals("5.5", array.optString(1));
-    assertEquals("9223372036854775806", array.optString(2, null));
-    assertEquals("null", array.optString(3, "-1"));
-    assertFalse(array.isNull(0));
-    assertFalse(array.isNull(3));
-
-    assertEquals(true, array.getBoolean(0));
-    assertEquals(true, array.optBoolean(0));
-    assertEquals(true, array.optBoolean(0, false));
-    assertEquals(0, array.optInt(0));
-    assertEquals(-2, array.optInt(0, -2));
-
-    assertEquals(5.5d, array.getDouble(1), 0);
-    assertEquals(5L, array.getLong(1));
-    assertEquals(5, array.getInt(1));
-    assertEquals(5, array.optInt(1, 3));
-
-    // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
-    // double and then converting that to a long. This is consistent with JavaScript.
-    assertEquals(9223372036854775807L, array.getLong(2));
-    assertEquals(9.223372036854776E18, array.getDouble(2), 0);
-    assertEquals(Integer.MAX_VALUE, array.getInt(2));
-
-    assertFalse(array.isNull(3));
-    try {
-      array.getDouble(3);
-      fail();
-    } catch (JSONException e) {
-      // expected
-    }
-    assertEquals(Double.NaN, array.optDouble(3), 0);
-    assertEquals(-1.0d, array.optDouble(3, -1.0d), 0);
-  }
-
-  @Test
-  public void testJoin() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(null);
-    assertEquals("null", array.join(" & "));
-    array.put("\"");
-    assertEquals("null & \"\\\"\"", array.join(" & "));
-    array.put(5);
-    assertEquals("null & \"\\\"\" & 5", array.join(" & "));
-    array.put(true);
-    assertEquals("null & \"\\\"\" & 5 & true", array.join(" & "));
-    array.put(new JSONArray(Arrays.asList(true, false)));
-    assertEquals("null & \"\\\"\" & 5 & true & [true,false]", array.join(" & "));
-    array.put(new JSONObject(Collections.singletonMap("x", 6)));
-    assertEquals("null & \"\\\"\" & 5 & true & [true,false] & {\"x\":6}", array.join(" & "));
-  }
-
-  @Test
-  public void testJoinWithNull() throws JSONException {
-    JSONArray array = new JSONArray(Arrays.asList(5, 6));
-    assertEquals("5null6", array.join(null));
-  }
-
-  @Test
-  public void testJoinWithSpecialCharacters() throws JSONException {
-    JSONArray array = new JSONArray(Arrays.asList(5, 6));
-    assertEquals("5\"6", array.join("\""));
-  }
-
-  @Test
-  public void testToJSONObject() throws JSONException {
-    JSONArray keys = new JSONArray();
-    keys.put("a");
-    keys.put("b");
-
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    values.put(false);
-
-    JSONObject object = values.toJSONObject(keys);
-    assertEquals(5.5d, object.get("a"));
-    assertEquals(false, object.get("b"));
-
-    keys.put(0, "a");
-    values.put(0, 11.0d);
-    assertEquals(5.5d, object.get("a"));
-  }
-
-  @Test
-  public void testToJSONObjectWithNulls() throws JSONException {
-    JSONArray keys = new JSONArray();
-    keys.put("a");
-    keys.put("b");
-
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    values.put(null);
-
-    // null values are stripped!
-    JSONObject object = values.toJSONObject(keys);
-    assertEquals(1, object.length());
-    assertFalse(object.has("b"));
-    assertEquals("{\"a\":5.5}", object.toString());
-  }
-
-  @Test
-  public void testToJSONObjectMoreNamesThanValues() throws JSONException {
-    JSONArray keys = new JSONArray();
-    keys.put("a");
-    keys.put("b");
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    JSONObject object = values.toJSONObject(keys);
-    assertEquals(1, object.length());
-    assertEquals(5.5d, object.get("a"));
-  }
-
-  @Test
-  public void testToJSONObjectMoreValuesThanNames() throws JSONException {
-    JSONArray keys = new JSONArray();
-    keys.put("a");
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    values.put(11.0d);
-    JSONObject object = values.toJSONObject(keys);
-    assertEquals(1, object.length());
-    assertEquals(5.5d, object.get("a"));
-  }
-
-  @Test
-  public void testToJSONObjectNullKey() throws JSONException {
-    JSONArray keys = new JSONArray();
-    keys.put(JSONObject.NULL);
-    JSONArray values = new JSONArray();
-    values.put(5.5d);
-    JSONObject object = values.toJSONObject(keys);
-    assertEquals(1, object.length());
-    assertEquals(5.5d, object.get("null"));
-  }
-
-  @Test
-  public void testPutUnsupportedNumbers() throws JSONException {
-    JSONArray array = new JSONArray();
-
-    try {
-      array.put(Double.NaN);
-      fail();
-    } catch (JSONException e) {
-      // expected
-    }
-    try {
-      array.put(0, Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException e) {
-      // expected
-    }
-    try {
-      array.put(0, Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException e) {
-      // expected
-    }
-  }
-
-  @Test
-  public void testPutUnsupportedNumbersAsObject() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(Double.valueOf(Double.NaN));
-    array.put(Double.valueOf(Double.NEGATIVE_INFINITY));
-    array.put(Double.valueOf(Double.POSITIVE_INFINITY));
-    assertEquals(null, array.toString());
-  }
-
-  /**
-   * Although JSONArray is usually defensive about which numbers it accepts, it doesn't check inputs
-   * in its constructor.
-   */
-  @Test
-  public void testCreateWithUnsupportedNumbers() throws JSONException {
-    JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
-    assertEquals(2, array.length());
-    assertEquals(5.5, array.getDouble(0), 0);
-    assertEquals(Double.NaN, array.getDouble(1), 0);
-  }
-
-  @Test
-  public void testToStringWithUnsupportedNumbers() throws JSONException {
-    // when the array contains an unsupported number, toString returns null!
-    JSONArray array = new JSONArray(Arrays.asList(5.5, Double.NaN));
-    assertNull(array.toString());
-  }
-
-  @Test
-  public void testListConstructorCopiesContents() throws JSONException {
-    // have to use asList instead of Collections.singleton() to allow mutation
-    // noinspection ArraysAsListWithZeroOrOneArgument
-    List<Object> contents = Arrays.<Object>asList(5);
-    JSONArray array = new JSONArray(contents);
-    contents.set(0, 10);
-    assertEquals(5, array.get(0));
-  }
-
-  @Test
-  public void testTokenerConstructor() throws JSONException {
-    JSONArray object = new JSONArray(new JSONTokener("[false]"));
-    assertEquals(1, object.length());
-    assertEquals(false, object.get(0));
-  }
-
-  @Test
-  public void testTokenerConstructorWrongType() throws JSONException {
-    try {
-      new JSONArray(new JSONTokener("{\"foo\": false}"));
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testTokenerConstructorNull() throws JSONException {
-    try {
-      new JSONArray((JSONTokener) null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  @Test
-  public void testTokenerConstructorParseFail() {
-    try {
-      new JSONArray(new JSONTokener("["));
-      fail();
-    } catch (JSONException ignored) {
-    } catch (StackOverflowError e) {
-      fail("Stack overflowed on input: \"[\"");
-    }
-  }
-
-  @Test
-  public void testStringConstructor() throws JSONException {
-    JSONArray object = new JSONArray("[false]");
-    assertEquals(1, object.length());
-    assertEquals(false, object.get(0));
-  }
-
-  @Test
-  public void testStringConstructorWrongType() throws JSONException {
-    try {
-      new JSONArray("{\"foo\": false}");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testStringConstructorNull() throws JSONException {
-    try {
-      new JSONArray((String) null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  @Test
-  public void testStringConstructorParseFail() {
-    try {
-      new JSONArray("[");
-      fail();
-    } catch (JSONException ignored) {
-    } catch (StackOverflowError e) {
-      fail("Stack overflowed on input: \"[\"");
-    }
-  }
-
-  @Test
-  public void testCreate() throws JSONException {
-    JSONArray array = new JSONArray(Arrays.asList(5.5, true));
-    assertEquals(2, array.length());
-    assertEquals(5.5, array.getDouble(0), 0.0);
-    assertEquals(true, array.get(1));
-    assertEquals("[5.5,true]", array.toString());
-  }
-
-  @Test
-  public void testAccessOutOfBounds() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put("foo");
-    assertEquals(null, array.opt(3));
-    assertEquals(null, array.opt(-3));
-    assertEquals("", array.optString(3));
-    assertEquals("", array.optString(-3));
-    try {
-      array.get(3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.get(-3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.getString(3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      array.getString(-3);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void test_remove() throws Exception {
-    JSONArray a = new JSONArray();
-    assertEquals(null, a.remove(-1));
-    assertEquals(null, a.remove(0));
-
-    a.put("hello");
-    assertEquals(null, a.remove(-1));
-    assertEquals(null, a.remove(1));
-    assertEquals("hello", a.remove(0));
-    assertEquals(null, a.remove(0));
-  }
-
-  enum MyEnum {
-    A, B, C
-  }
-
-  // https://code.google.com/p/android/issues/detail?id=62539
-  // but changed in open-json to return toString for all enums
-  @Test
-  public void testEnums() throws Exception {
-    // This works because it's in java.* and any class in there falls back to toString.
-    JSONArray a1 = new JSONArray(java.lang.annotation.RetentionPolicy.values());
-    assertEquals("[\"SOURCE\",\"CLASS\",\"RUNTIME\"]", a1.toString());
-
-    // This doesn't because it's not.
-    JSONArray a2 = new JSONArray(MyEnum.values());
-    assertEquals("[\"A\",\"B\",\"C\"]", a2.toString());
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONFunctionTestObject.java b/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
deleted file mode 100755
index 9d24487..0000000
--- a/geode-json/src/test/java/org/json/JSONFunctionTestObject.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.json;
-
-/**
- * Class to test the function hack
- */
-public class JSONFunctionTestObject {
-  private String value;
-
-  public JSONFunctionTestObject(String value) {
-    this.value = value;
-  }
-
-  @Override
-  public String toString() {
-    return value;
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/JSONObjectTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONObjectTest.java b/geode-json/src/test/java/org/json/JSONObjectTest.java
deleted file mode 100755
index c795551..0000000
--- a/geode-json/src/test/java/org/json/JSONObjectTest.java
+++ /dev/null
@@ -1,1190 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import org.junit.Test;
-
-import java.beans.IntrospectionException;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Objects;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.*;
-
-/**
- * This black box test was written without inspecting the non-free org.json sourcecode.
- */
-public class JSONObjectTest {
-  @Test
-  public void testKeyset() throws Exception {
-    JSONObject x = new JSONObject("{'a':1, 'b':2, 'c':3}");
-    Set<String> k = new TreeSet<String>();
-    for (String kx : Arrays.asList("a", "b", "c")) {
-      k.add(kx);
-    }
-    assertEquals(x.keySet(), k);
-    x = new JSONObject("{}");
-    assertEquals(x.keySet().size(), 0);
-  }
-
-  @Test
-  public void testEmptyObject() throws JSONException {
-    JSONObject object = new JSONObject();
-    assertEquals(0, object.length());
-
-    // bogus (but documented) behaviour: returns null rather than the empty object!
-    assertNull(object.names());
-
-    // returns null rather than an empty array!
-    assertNull(object.toJSONArray(new JSONArray()));
-    assertEquals("{}", object.toString());
-    assertEquals("{}", object.toString(5));
-    try {
-      object.get("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getBoolean("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getDouble("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getInt("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getJSONArray("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getJSONObject("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getLong("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getString("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertFalse(object.has("foo"));
-    assertTrue(object.isNull("foo")); // isNull also means "is not present"
-    assertNull(object.opt("foo"));
-    assertEquals(false, object.optBoolean("foo"));
-    assertEquals(true, object.optBoolean("foo", true));
-    assertEquals(Double.NaN, object.optDouble("foo"), 0);
-    assertEquals(5.0, object.optDouble("foo", 5.0), 0);
-    assertEquals(0, object.optInt("foo"));
-    assertEquals(5, object.optInt("foo", 5));
-    assertEquals(null, object.optJSONArray("foo"));
-    assertEquals(null, object.optJSONObject("foo"));
-    assertEquals(0, object.optLong("foo"));
-    assertEquals(Long.MAX_VALUE - 1, object.optLong("foo", Long.MAX_VALUE - 1));
-    assertEquals("", object.optString("foo")); // empty string is default!
-    assertEquals("bar", object.optString("foo", "bar"));
-    assertNull(object.remove("foo"));
-  }
-
-  @Test
-  public void testEqualsAndHashCode() throws JSONException {
-    JSONObject a = new JSONObject();
-    JSONObject b = new JSONObject();
-
-    // JSON object doesn't override either equals or hashCode (!)
-    assertFalse(a.equals(b));
-    assertEquals(a.hashCode(), System.identityHashCode(a));
-  }
-
-  @Test
-  public void testGet() throws JSONException {
-    JSONObject object = new JSONObject();
-    Object value = new Object();
-    object.put("foo", value);
-    object.put("bar", new Object());
-    object.put("baz", new Object());
-    assertSame(value, object.get("foo"));
-    try {
-      object.get("FOO");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put(null, value);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.get(null);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testPut() throws JSONException {
-    JSONObject object = new JSONObject();
-    assertSame(object, object.put("foo", true));
-    object.put("foo", false);
-    assertEquals(false, object.get("foo"));
-
-    object.put("foo", 5.0d);
-    assertEquals(5.0d, object.get("foo"));
-    object.put("foo", 0);
-    assertEquals(0, object.get("foo"));
-    object.put("bar", Long.MAX_VALUE - 1);
-    assertEquals(Long.MAX_VALUE - 1, object.get("bar"));
-    object.put("baz", "x");
-    assertEquals("x", object.get("baz"));
-    object.put("bar", JSONObject.NULL);
-    assertSame(JSONObject.NULL, object.get("bar"));
-  }
-
-  @Test
-  public void testPutNullRemoves() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "bar");
-    object.put("foo", null);
-    assertEquals(0, object.length());
-    assertFalse(object.has("foo"));
-    try {
-      object.get("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testPutOpt() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "bar");
-    object.putOpt("foo", null);
-    assertEquals("bar", object.get("foo"));
-    object.putOpt(null, null);
-    assertEquals(1, object.length());
-    object.putOpt(null, "bar");
-    assertEquals(1, object.length());
-  }
-
-  @Test
-  public void testPutOptUnsupportedNumbers() throws JSONException {
-    JSONObject object = new JSONObject();
-    try {
-      object.putOpt("foo", Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.putOpt("foo", Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.putOpt("foo", Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testRemove() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "bar");
-    assertEquals(null, object.remove(null));
-    assertEquals(null, object.remove(""));
-    assertEquals(null, object.remove("bar"));
-    assertEquals("bar", object.remove("foo"));
-    assertEquals(null, object.remove("foo"));
-  }
-
-  @Test
-  public void testBooleans() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", true);
-    object.put("bar", false);
-    object.put("baz", "true");
-    object.put("quux", "false");
-    assertEquals(4, object.length());
-    assertEquals(true, object.getBoolean("foo"));
-    assertEquals(false, object.getBoolean("bar"));
-    assertEquals(true, object.getBoolean("baz"));
-    assertEquals(false, object.getBoolean("quux"));
-    assertFalse(object.isNull("foo"));
-    assertFalse(object.isNull("quux"));
-    assertTrue(object.has("foo"));
-    assertTrue(object.has("quux"));
-    assertFalse(object.has("missing"));
-    assertEquals(true, object.optBoolean("foo"));
-    assertEquals(false, object.optBoolean("bar"));
-    assertEquals(true, object.optBoolean("baz"));
-    assertEquals(false, object.optBoolean("quux"));
-    assertEquals(false, object.optBoolean("missing"));
-    assertEquals(true, object.optBoolean("foo", true));
-    assertEquals(false, object.optBoolean("bar", true));
-    assertEquals(true, object.optBoolean("baz", true));
-    assertEquals(false, object.optBoolean("quux", true));
-    assertEquals(true, object.optBoolean("missing", true));
-
-    object.put("foo", "truE");
-    object.put("bar", "FALSE");
-    assertEquals(true, object.getBoolean("foo"));
-    assertEquals(false, object.getBoolean("bar"));
-    assertEquals(true, object.optBoolean("foo"));
-    assertEquals(false, object.optBoolean("bar"));
-    assertEquals(true, object.optBoolean("foo", false));
-    assertEquals(false, object.optBoolean("bar", false));
-  }
-
-  // http://code.google.com/p/android/issues/detail?id=16411
-  @Test
-  public void testCoerceStringToBoolean() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "maybe");
-    try {
-      object.getBoolean("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals(false, object.optBoolean("foo"));
-    assertEquals(true, object.optBoolean("foo", true));
-  }
-
-  @Test
-  public void testNumbers() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", Double.MIN_VALUE);
-    object.put("bar", 9223372036854775806L);
-    object.put("baz", Double.MAX_VALUE);
-    object.put("quux", -0d);
-    assertEquals(4, object.length());
-
-    String toString = object.toString();
-    assertTrue(toString, toString.contains("\"foo\":4.9E-324"));
-    assertTrue(toString, toString.contains("\"bar\":9223372036854775806"));
-    assertTrue(toString, toString.contains("\"baz\":1.7976931348623157E308"));
-
-    // toString() and getString() return different values for -0d!
-    assertTrue(toString, toString.contains("\"quux\":-0}") // no trailing decimal point
-        || toString.contains("\"quux\":-0,"));
-
-    assertEquals(Double.MIN_VALUE, object.get("foo"));
-    assertEquals(9223372036854775806L, object.get("bar"));
-    assertEquals(Double.MAX_VALUE, object.get("baz"));
-    assertEquals(-0d, object.get("quux"));
-    assertEquals(Double.MIN_VALUE, object.getDouble("foo"), 0);
-    assertEquals(9.223372036854776E18, object.getDouble("bar"), 0);
-    assertEquals(Double.MAX_VALUE, object.getDouble("baz"), 0);
-    assertEquals(-0d, object.getDouble("quux"), 0);
-    assertEquals(0, object.getLong("foo"));
-    assertEquals(9223372036854775806L, object.getLong("bar"));
-    assertEquals(Long.MAX_VALUE, object.getLong("baz"));
-    assertEquals(0, object.getLong("quux"));
-    assertEquals(0, object.getInt("foo"));
-    assertEquals(-2, object.getInt("bar"));
-    assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
-    assertEquals(0, object.getInt("quux"));
-    assertEquals(Double.MIN_VALUE, object.opt("foo"));
-    assertEquals(9223372036854775806L, object.optLong("bar"));
-    assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
-    assertEquals(0, object.optInt("quux"));
-    assertEquals(Double.MIN_VALUE, object.opt("foo"));
-    assertEquals(9223372036854775806L, object.optLong("bar"));
-    assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
-    assertEquals(0, object.optInt("quux"));
-    assertEquals(Double.MIN_VALUE, object.optDouble("foo", 5.0d), 0);
-    assertEquals(9223372036854775806L, object.optLong("bar", 1L));
-    assertEquals(Long.MAX_VALUE, object.optLong("baz", 1L));
-    assertEquals(0, object.optInt("quux", -1));
-    assertEquals("4.9E-324", object.getString("foo"));
-    assertEquals("9223372036854775806", object.getString("bar"));
-    assertEquals("1.7976931348623157E308", object.getString("baz"));
-    assertEquals("-0.0", object.getString("quux"));
-  }
-
-  @Test
-  public void testFloats() throws JSONException {
-    JSONObject object = new JSONObject();
-    try {
-      object.put("foo", (Float) Float.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", (Float) Float.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", (Float) Float.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testOtherNumbers() throws JSONException {
-    Number nan = new Number() {
-      public int intValue() {
-        throw new UnsupportedOperationException();
-      }
-
-      public long longValue() {
-        throw new UnsupportedOperationException();
-      }
-
-      public float floatValue() {
-        throw new UnsupportedOperationException();
-      }
-
-      public double doubleValue() {
-        return Double.NaN;
-      }
-
-      @Override
-      public String toString() {
-        return "x";
-      }
-    };
-
-    JSONObject object = new JSONObject();
-    try {
-      object.put("foo", nan);
-      fail("Object.put() accepted a NaN (via a custom Number class)");
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testForeignObjects() throws JSONException {
-    Object foreign = new Object() {
-      @Override
-      public String toString() {
-        return "x";
-      }
-    };
-
-    // foreign object types are accepted and treated as Strings!
-    JSONObject object = new JSONObject();
-    object.put("foo", foreign);
-    assertEquals("{\"foo\":\"x\"}", object.toString());
-  }
-
-  @Test
-  public void testNullKeys() {
-    try {
-      new JSONObject().put(null, false);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONObject().put(null, 0.0d);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONObject().put(null, 5);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONObject().put(null, 5L);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONObject().put(null, "foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testStrings() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "true");
-    object.put("bar", "5.5");
-    object.put("baz", "9223372036854775806");
-    object.put("quux", "null");
-    object.put("height", "5\"8' tall");
-
-    assertTrue(object.toString().contains("\"foo\":\"true\""));
-    assertTrue(object.toString().contains("\"bar\":\"5.5\""));
-    assertTrue(object.toString().contains("\"baz\":\"9223372036854775806\""));
-    assertTrue(object.toString().contains("\"quux\":\"null\""));
-    assertTrue(object.toString().contains("\"height\":\"5\\\"8' tall\""));
-
-    assertEquals("true", object.get("foo"));
-    assertEquals("null", object.getString("quux"));
-    assertEquals("5\"8' tall", object.getString("height"));
-    assertEquals("true", object.opt("foo"));
-    assertEquals("5.5", object.optString("bar"));
-    assertEquals("true", object.optString("foo", "x"));
-    assertFalse(object.isNull("foo"));
-
-    assertEquals(true, object.getBoolean("foo"));
-    assertEquals(true, object.optBoolean("foo"));
-    assertEquals(true, object.optBoolean("foo", false));
-    assertEquals(0, object.optInt("foo"));
-    assertEquals(-2, object.optInt("foo", -2));
-
-    assertEquals(5.5d, object.getDouble("bar"), 0);
-    assertEquals(5L, object.getLong("bar"));
-    assertEquals(5, object.getInt("bar"));
-    assertEquals(5, object.optInt("bar", 3));
-
-    // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
-    // double and then converting that to a long. This is consistent with JavaScript.
-    assertEquals(9223372036854775807L, object.getLong("baz"));
-    assertEquals(9.223372036854776E18, object.getDouble("baz"), 0);
-    assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
-
-    assertFalse(object.isNull("quux"));
-    try {
-      object.getDouble("quux");
-      fail();
-    } catch (JSONException e) {
-      // expected
-    }
-    assertEquals(Double.NaN, object.optDouble("quux"), 0);
-    assertEquals(-1.0d, object.optDouble("quux", -1.0d), 0);
-
-    object.put("foo", "TRUE");
-    assertEquals(true, object.getBoolean("foo"));
-  }
-
-  @Test
-  public void testJSONObjects() throws JSONException {
-    JSONObject object = new JSONObject();
-
-    JSONArray a = new JSONArray();
-    JSONObject b = new JSONObject();
-    object.put("foo", a);
-    object.put("bar", b);
-
-    assertSame(a, object.getJSONArray("foo"));
-    assertSame(b, object.getJSONObject("bar"));
-    try {
-      object.getJSONObject("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.getJSONArray("bar");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals(a, object.optJSONArray("foo"));
-    assertEquals(b, object.optJSONObject("bar"));
-    assertEquals(null, object.optJSONArray("bar"));
-    assertEquals(null, object.optJSONObject("foo"));
-  }
-
-  @Test
-  public void testNullCoercionToString() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", JSONObject.NULL);
-    assertEquals("null", object.getString("foo"));
-  }
-
-  @Test
-  public void testArrayCoercion() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "[true]");
-    try {
-      object.getJSONArray("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testObjectCoercion() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "{}");
-    try {
-      object.getJSONObject("foo");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testAccumulateValueChecking() throws JSONException {
-    JSONObject object = new JSONObject();
-    try {
-      object.accumulate("foo", Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    object.accumulate("foo", 1);
-    try {
-      object.accumulate("foo", Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    object.accumulate("foo", 2);
-    try {
-      object.accumulate("foo", Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testToJSONArray() throws JSONException {
-    JSONObject object = new JSONObject();
-    Object value = new Object();
-    object.put("foo", true);
-    object.put("bar", 5.0d);
-    object.put("baz", -0.0d);
-    object.put("quux", value);
-
-    JSONArray names = new JSONArray();
-    names.put("baz");
-    names.put("quux");
-    names.put("foo");
-
-    JSONArray array = object.toJSONArray(names);
-    assertEquals(-0.0d, array.get(0));
-    assertEquals(value, array.get(1));
-    assertEquals(true, array.get(2));
-
-    object.put("foo", false);
-    assertEquals(true, array.get(2));
-  }
-
-  @Test
-  public void testToJSONArrayMissingNames() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", true);
-    object.put("bar", 5.0d);
-    object.put("baz", JSONObject.NULL);
-
-    JSONArray names = new JSONArray();
-    names.put("bar");
-    names.put("foo");
-    names.put("quux");
-    names.put("baz");
-
-    JSONArray array = object.toJSONArray(names);
-    assertEquals(4, array.length());
-
-    assertEquals(5.0d, array.get(0));
-    assertEquals(true, array.get(1));
-    try {
-      array.get(2);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals(JSONObject.NULL, array.get(3));
-  }
-
-  @Test
-  public void testToJSONArrayNull() throws JSONException {
-    JSONObject object = new JSONObject();
-    assertEquals(null, object.toJSONArray(null));
-    object.put("foo", 5);
-    try {
-      object.toJSONArray(null);
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testToJSONArrayEndsUpEmpty() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    JSONArray array = new JSONArray();
-    array.put("bar");
-    assertEquals(1, object.toJSONArray(array).length());
-  }
-
-  @Test
-  public void testToJSONArrayNonString() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    object.put("null", 10);
-    object.put("false", 15);
-
-    JSONArray names = new JSONArray();
-    names.put(JSONObject.NULL);
-    names.put(false);
-    names.put("foo");
-
-    // array elements are converted to strings to do name lookups on the map!
-    JSONArray array = object.toJSONArray(names);
-    assertEquals(3, array.length());
-    assertEquals(10, array.get(0));
-    assertEquals(15, array.get(1));
-    assertEquals(5, array.get(2));
-  }
-
-  @Test
-  public void testPutUnsupportedNumbers() throws JSONException {
-    JSONObject object = new JSONObject();
-    try {
-      object.put("foo", Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testPutUnsupportedNumbersAsObjects() throws JSONException {
-    JSONObject object = new JSONObject();
-    try {
-      object.put("foo", (Double) Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", (Double) Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      object.put("foo", (Double) Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  /**
-   * Although JSONObject is usually defensive about which numbers it accepts, it doesn't check
-   * inputs in its constructor.
-   */
-  @Test
-  public void testCreateWithUnsupportedNumbers() throws JSONException {
-    Map<String, Object> contents = new HashMap<String, Object>();
-    contents.put("foo", Double.NaN);
-    contents.put("bar", Double.NEGATIVE_INFINITY);
-    contents.put("baz", Double.POSITIVE_INFINITY);
-
-    JSONObject object = new JSONObject(contents);
-    assertEquals(Double.NaN, object.get("foo"));
-    assertEquals(Double.NEGATIVE_INFINITY, object.get("bar"));
-    assertEquals(Double.POSITIVE_INFINITY, object.get("baz"));
-  }
-
-  @Test
-  public void testToStringWithUnsupportedNumbers() {
-    // when the object contains an unsupported number, toString returns null!
-    JSONObject object = new JSONObject(Collections.singletonMap("foo", Double.NaN));
-    assertEquals(null, object.toString());
-  }
-
-  @Test
-  public void testMapConstructorCopiesContents() throws JSONException {
-    Map<String, Object> contents = new HashMap<String, Object>();
-    contents.put("foo", 5);
-    JSONObject object = new JSONObject(contents);
-    contents.put("foo", 10);
-    assertEquals(5, object.get("foo"));
-  }
-
-  @Test
-  public void testMapConstructorWithBogusEntries() {
-    Map<Object, Object> contents = new HashMap<Object, Object>();
-    contents.put(5, 5);
-
-    try {
-      new JSONObject(contents);
-      fail("JSONObject constructor doesn't validate its input!");
-    } catch (Exception ignored) {
-    }
-  }
-
-  @Test
-  public void testTokenerConstructor() throws JSONException {
-    JSONObject object = new JSONObject(new JSONTokener("{\"foo\": false}"));
-    assertEquals(1, object.length());
-    assertEquals(false, object.get("foo"));
-  }
-
-  @Test
-  public void testTokenerConstructorWrongType() throws JSONException {
-    try {
-      new JSONObject(new JSONTokener("[\"foo\", false]"));
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testTokenerConstructorNull() throws JSONException {
-    try {
-      new JSONObject((JSONTokener) null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  @Test
-  public void testTokenerConstructorParseFail() {
-    try {
-      new JSONObject(new JSONTokener("{"));
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testStringConstructor() throws JSONException {
-    JSONObject object = new JSONObject("{\"foo\": false}");
-    assertEquals(1, object.length());
-    assertEquals(false, object.get("foo"));
-  }
-
-  @Test
-  public void testStringConstructorWrongType() throws JSONException {
-    try {
-      new JSONObject("[\"foo\", false]");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testStringConstructorNull() throws JSONException {
-    try {
-      new JSONObject((String) null);
-      fail();
-    } catch (NullPointerException ignored) {
-    }
-  }
-
-  @Test
-  public void testStringConstructorParseFail() {
-    try {
-      new JSONObject("{");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testCopyConstructor() throws JSONException {
-    JSONObject source = new JSONObject();
-    source.put("a", JSONObject.NULL);
-    source.put("b", false);
-    source.put("c", 5);
-
-    JSONObject copy = new JSONObject(source, new String[] {"a", "c"});
-    assertEquals(2, copy.length());
-    assertEquals(JSONObject.NULL, copy.get("a"));
-    assertEquals(5, copy.get("c"));
-    assertEquals(null, copy.opt("b"));
-  }
-
-  @Test
-  public void testCopyConstructorMissingName() throws JSONException {
-    JSONObject source = new JSONObject();
-    source.put("a", JSONObject.NULL);
-    source.put("b", false);
-    source.put("c", 5);
-
-    JSONObject copy = new JSONObject(source, new String[] {"a", "c", "d"});
-    assertEquals(2, copy.length());
-    assertEquals(JSONObject.NULL, copy.get("a"));
-    assertEquals(5, copy.get("c"));
-    assertEquals(0, copy.optInt("b"));
-  }
-
-  @Test
-  public void testAccumulateMutatesInPlace() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    object.accumulate("foo", 6);
-    JSONArray array = object.getJSONArray("foo");
-    assertEquals("[5,6]", array.toString());
-    object.accumulate("foo", 7);
-    assertEquals("[5,6,7]", array.toString());
-  }
-
-  @Test
-  public void testAccumulateExistingArray() throws JSONException {
-    JSONArray array = new JSONArray();
-    JSONObject object = new JSONObject();
-    object.put("foo", array);
-    object.accumulate("foo", 5);
-    assertEquals("[5]", array.toString());
-  }
-
-  @Test
-  public void testAccumulatePutArray() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.accumulate("foo", 5);
-    assertEquals("{\"foo\":5}", object.toString());
-    object.accumulate("foo", new JSONArray());
-    assertEquals("{\"foo\":[5,[]]}", object.toString());
-  }
-
-  @Test
-  public void testAccumulateNull() {
-    JSONObject object = new JSONObject();
-    try {
-      object.accumulate(null, 5);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testEmptyStringKey() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("", 5);
-    assertEquals(5, object.get(""));
-    assertEquals("{\"\":5}", object.toString());
-  }
-
-  @Test
-  public void testNullValue() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", JSONObject.NULL);
-    object.put("bar", null);
-
-    // there are two ways to represent null; each behaves differently!
-    assertTrue(object.has("foo"));
-    assertFalse(object.has("bar"));
-    assertTrue(object.isNull("foo"));
-    assertTrue(object.isNull("bar"));
-  }
-
-  @Test
-  public void testNullValue_equalsAndHashCode() {
-    // noinspection ObjectEqualsNull
-    assertTrue(JSONObject.NULL.equals(null)); // guaranteed by javadoc
-    // not guaranteed by javadoc, but seems like a good idea
-    assertEquals(Objects.hashCode(null), JSONObject.NULL.hashCode());
-  }
-
-  @Test
-  public void testHas() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    assertTrue(object.has("foo"));
-    assertFalse(object.has("bar"));
-    assertFalse(object.has(null));
-  }
-
-  @Test
-  public void testOptNull() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", "bar");
-    assertEquals(null, object.opt(null));
-    assertEquals(false, object.optBoolean(null));
-    assertEquals(Double.NaN, object.optDouble(null), 0);
-    assertEquals(0, object.optInt(null));
-    assertEquals(0L, object.optLong(null));
-    assertEquals(null, object.optJSONArray(null));
-    assertEquals(null, object.optJSONObject(null));
-    assertEquals("", object.optString(null));
-    assertEquals(true, object.optBoolean(null, true));
-    assertEquals(0.0d, object.optDouble(null, 0.0d), 0);
-    assertEquals(1, object.optInt(null, 1));
-    assertEquals(1L, object.optLong(null, 1L));
-    assertEquals("baz", object.optString(null, "baz"));
-  }
-
-  @Test
-  public void testToStringWithIndentFactor() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", new JSONArray(Arrays.asList(5, 6)));
-    object.put("bar", new JSONObject());
-    String foobar = "{\n" + "     \"foo\": [\n" + "          5,\n" + "          6\n" + "     ],\n"
-        + "     \"bar\": {}\n" + "}";
-    String barfoo = "{\n" + "     \"bar\": {},\n" + "     \"foo\": [\n" + "          5,\n"
-        + "          6\n" + "     ]\n" + "}";
-    String string = object.toString(5);
-    assertTrue(string, foobar.equals(string) || barfoo.equals(string));
-  }
-
-  @Test
-  public void testNames() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    object.put("bar", 6);
-    object.put("baz", 7);
-    JSONArray array = object.names();
-    assertTrue(array.toString().contains("foo"));
-    assertTrue(array.toString().contains("bar"));
-    assertTrue(array.toString().contains("baz"));
-  }
-
-  @Test
-  public void testKeysEmptyObject() {
-    JSONObject object = new JSONObject();
-    assertFalse(object.keys().hasNext());
-    try {
-      object.keys().next();
-      fail();
-    } catch (NoSuchElementException ignored) {
-    }
-  }
-
-  @Test
-  public void testKeys() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    object.put("bar", 6);
-    object.put("foo", 7);
-
-    @SuppressWarnings("unchecked")
-    Iterator<String> keys = object.keys();
-    Set<String> result = new HashSet<String>();
-    assertTrue(keys.hasNext());
-    result.add(keys.next());
-    assertTrue(keys.hasNext());
-    result.add(keys.next());
-    assertFalse(keys.hasNext());
-    assertEquals(new HashSet<String>(Arrays.asList("foo", "bar")), result);
-
-    try {
-      keys.next();
-      fail();
-    } catch (NoSuchElementException ignored) {
-    }
-  }
-
-  @Test
-  public void testMutatingKeysMutatesObject() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    Iterator keys = object.keys();
-    keys.next();
-    keys.remove();
-    assertEquals(0, object.length());
-  }
-
-  @Test
-  public void testQuote() {
-    // covered by JSONStringerTest.testEscaping
-  }
-
-  @Test
-  public void testQuoteNull() throws JSONException {
-    assertEquals("\"\"", JSONObject.quote(null));
-  }
-
-  @Test
-  public void testNumberToString() throws JSONException {
-    assertEquals("5", JSONObject.numberToString(5));
-    assertEquals("-0", JSONObject.numberToString(-0.0d));
-    assertEquals("9223372036854775806", JSONObject.numberToString(9223372036854775806L));
-    assertEquals("4.9E-324", JSONObject.numberToString(Double.MIN_VALUE));
-    assertEquals("1.7976931348623157E308", JSONObject.numberToString(Double.MAX_VALUE));
-    try {
-      JSONObject.numberToString(Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      JSONObject.numberToString(Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      JSONObject.numberToString(Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    assertEquals("0.001", JSONObject.numberToString(new BigDecimal("0.001")));
-    assertEquals("9223372036854775806",
-        JSONObject.numberToString(new BigInteger("9223372036854775806")));
-    try {
-      JSONObject.numberToString(null);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void test_wrap() throws Exception {
-    assertEquals(JSONObject.NULL, JSONObject.wrap(null));
-
-    JSONArray a = new JSONArray();
-    assertEquals(a, JSONObject.wrap(a));
-
-    JSONObject o = new JSONObject();
-    assertEquals(o, JSONObject.wrap(o));
-
-    assertEquals(JSONObject.NULL, JSONObject.wrap(JSONObject.NULL));
-
-    assertTrue(JSONObject.wrap(new byte[0]) instanceof JSONArray);
-    assertTrue(JSONObject.wrap(new ArrayList<String>()) instanceof JSONArray);
-    assertTrue(JSONObject.wrap(new HashMap<String, String>()) instanceof JSONObject);
-    assertTrue(JSONObject.wrap(0.0) instanceof Double);
-    assertTrue(JSONObject.wrap("hello") instanceof String);
-  }
-
-  // https://code.google.com/p/android/issues/detail?id=55114
-  @Test
-  public void test_toString_listAsMapValue() throws Exception {
-    ArrayList<Object> list = new ArrayList<Object>();
-    list.add("a");
-    list.add(new ArrayList<String>());
-    Map<String, Object> map = new TreeMap<String, Object>();
-    map.put("x", "l");
-    map.put("y", list);
-    assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
-  }
-
-  @Test
-  public void testAppendExistingInvalidKey() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("foo", 5);
-    try {
-      object.append("foo", 6);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testAppendExistingArray() throws JSONException {
-    JSONArray array = new JSONArray();
-    JSONObject object = new JSONObject();
-    object.put("foo", array);
-    object.append("foo", 5);
-    assertEquals("[5]", array.toString());
-  }
-
-  @Test
-  public void testAppendPutArray() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.append("foo", 5);
-    assertEquals("{\"foo\":[5]}", object.toString());
-    object.append("foo", new JSONArray());
-    assertEquals("{\"foo\":[5,[]]}", object.toString());
-  }
-
-  @Test
-  public void testAppendNull() {
-    JSONObject object = new JSONObject();
-    try {
-      object.append(null, 5);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  // https://code.google.com/p/android/issues/detail?id=103641
-  @Test
-  public void testInvalidUnicodeEscape() {
-    try {
-      new JSONObject("{\"q\":\"\\u\", \"r\":[]}");
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testBeanThings()
-      throws IllegalAccessException, IntrospectionException, InvocationTargetException {
-    Foo f = new Foo();
-    assertEquals("{\"a\":1,\"b\":1,\"c\":\"c\",\"d\":[{\"e\":\"echo\"}]}",
-        new JSONObject(f).toString());
-  }
-
-  @Test
-  public void testGetNames() throws Exception {
-    assertArrayEquals(new String[] {"a", "b", "c", "d"},
-        JSONObject.getNames(new JSONObject(new Foo())));
-  }
-
-  private static class Foo {
-    public double getA() {
-      return 1.0;
-    }
-
-    public int getB() {
-      return 1;
-    }
-
-    public String getC() {
-      return "c";
-    }
-
-    public List<Bar> getD() {
-      ArrayList<Bar> r = new ArrayList<Bar>();
-      r.add(new Bar());
-      return r;
-    }
-  }
-
-  private static class Bar {
-    public String getE() {
-      return "echo";
-    }
-  }
-
-  @Test
-  public void testEnumWrapper() throws Exception {
-    Object y = JSONObject.wrap(E.A);
-    assertEquals("A", y);
-    assertTrue(y instanceof String);
-  }
-
-  enum E {
-    A {
-      int key() {
-        return 1;
-      }
-    },
-    B {
-      int key() {
-        return 2;
-      }
-    };
-    int key() {
-      return -1;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/abeaa244/geode-json/src/test/java/org/json/JSONStringerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONStringerTest.java b/geode-json/src/test/java/org/json/JSONStringerTest.java
deleted file mode 100755
index b3a8188..0000000
--- a/geode-json/src/test/java/org/json/JSONStringerTest.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * 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
- *
- * 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.
- */
-
-package org.json;
-
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.*;
-
-/**
- * This black box test was written without inspecting the non-free org.json sourcecode.
- */
-public class JSONStringerTest {
-
-  @Test
-  public void testJSONFunctionHackTest() {
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.key("key");
-    stringer.value(new JSONFunctionTestObject("window.test('foo' + \"bar\")"));
-    stringer.endObject();
-    assertEquals("{\"key\":window.test('foo' + \"bar\")}", stringer.toString());
-  }
-
-  @Test
-  public void testEmptyStringer() {
-    // why isn't this the empty string?
-    assertNull(new JSONStringer().toString());
-  }
-
-  @Test
-  public void testValueJSONNull() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(JSONObject.NULL);
-    stringer.endArray();
-    assertEquals("[null]", stringer.toString());
-  }
-
-  @Test
-  public void testEmptyObject() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.endObject();
-    assertEquals("{}", stringer.toString());
-  }
-
-  @Test
-  public void testEmptyArray() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.endArray();
-    assertEquals("[]", stringer.toString());
-  }
-
-  @Test
-  public void testArray() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(false);
-    stringer.value(5.0);
-    stringer.value(5L);
-    stringer.value("five");
-    stringer.value(null);
-    stringer.endArray();
-    assertEquals("[false,5,5,\"five\",null]", stringer.toString());
-  }
-
-  @Test
-  public void testValueObjectMethods() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(Boolean.FALSE);
-    stringer.value(Double.valueOf(5.0));
-    stringer.value(Long.valueOf(5L));
-    stringer.endArray();
-    assertEquals("[false,5,5]", stringer.toString());
-  }
-
-  @Test
-  public void testKeyValue() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.key("a").value(false);
-    stringer.key("b").value(5.0);
-    stringer.key("c").value(5L);
-    stringer.key("d").value("five");
-    stringer.key("e").value(null);
-    stringer.endObject();
-    assertEquals("{\"a\":false," + "\"b\":5," + "\"c\":5," + "\"d\":\"five\"," + "\"e\":null}",
-        stringer.toString());
-  }
-
-  /**
-   * Test what happens when extreme values are emitted. Such values are likely to be rounded during
-   * parsing.
-   */
-  @Test
-  public void testNumericRepresentations() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(Long.MAX_VALUE);
-    stringer.value(Double.MIN_VALUE);
-    stringer.endArray();
-    assertEquals("[9223372036854775807,4.9E-324]", stringer.toString());
-  }
-
-  @Test
-  public void testWeirdNumbers() throws JSONException {
-    try {
-      new JSONStringer().array().value(Double.NaN);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().array().value(Double.NEGATIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().array().value(Double.POSITIVE_INFINITY);
-      fail();
-    } catch (JSONException ignored) {
-    }
-
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(-0.0d);
-    stringer.value(0.0d);
-    stringer.endArray();
-    assertEquals("[-0,0]", stringer.toString());
-  }
-
-  @Test
-  public void testMismatchedScopes() {
-    try {
-      new JSONStringer().key("a");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().value("a");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().endObject();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().endArray();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().array().endObject();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().object().endArray();
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().object().key("a").key("a");
-      fail();
-    } catch (JSONException ignored) {
-    }
-    try {
-      new JSONStringer().object().value(false);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testNullKey() {
-    try {
-      new JSONStringer().object().key(null);
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testRepeatedKey() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.key("a").value(true);
-    stringer.key("a").value(false);
-    stringer.endObject();
-    // JSONStringer doesn't attempt to detect duplicates
-    assertEquals("{\"a\":true,\"a\":false}", stringer.toString());
-  }
-
-  @Test
-  public void testEmptyKey() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.key("").value(false);
-    stringer.endObject();
-    assertEquals("{\"\":false}", stringer.toString()); // legit behaviour!
-  }
-
-  @Test
-  public void testEscaping() throws JSONException {
-    assertEscapedAllWays("a", "a");
-    assertEscapedAllWays("a\\\"", "a\"");
-    assertEscapedAllWays("\\\"", "\"");
-    assertEscapedAllWays(":", ":");
-    assertEscapedAllWays(",", ",");
-    assertEscapedAllWays("\\b", "\b");
-    assertEscapedAllWays("\\f", "\f");
-    assertEscapedAllWays("\\n", "\n");
-    assertEscapedAllWays("\\r", "\r");
-    assertEscapedAllWays("\\t", "\t");
-    assertEscapedAllWays(" ", " ");
-    assertEscapedAllWays("\\\\", "\\");
-    assertEscapedAllWays("{", "{");
-    assertEscapedAllWays("}", "}");
-    assertEscapedAllWays("[", "[");
-    assertEscapedAllWays("]", "]");
-    assertEscapedAllWays("\\u0000", "\0");
-    assertEscapedAllWays("\\u0019", "\u0019");
-    assertEscapedAllWays(" ", "\u0020");
-    assertEscapedAllWays("<\\/foo>", "</foo>");
-  }
-
-  private void assertEscapedAllWays(String escaped, String original) throws JSONException {
-    assertEquals("{\"" + escaped + "\":false}",
-        new JSONStringer().object().key(original).value(false).endObject().toString());
-    assertEquals("{\"a\":\"" + escaped + "\"}",
-        new JSONStringer().object().key("a").value(original).endObject().toString());
-    assertEquals("[\"" + escaped + "\"]",
-        new JSONStringer().array().value(original).endArray().toString());
-    assertEquals("\"" + escaped + "\"", JSONObject.quote(original));
-  }
-
-  @Test
-  public void testJSONArrayAsValue() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(false);
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.value(array);
-    stringer.endArray();
-    assertEquals("[[false]]", stringer.toString());
-  }
-
-  @Test
-  public void testJSONObjectAsValue() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("a", false);
-    JSONStringer stringer = new JSONStringer();
-    stringer.object();
-    stringer.key("b").value(object);
-    stringer.endObject();
-    assertEquals("{\"b\":{\"a\":false}}", stringer.toString());
-  }
-
-  @Test
-  public void testArrayNestingMaxDepthSupports20() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.array();
-    }
-    for (int i = 0; i < 20; i++) {
-      stringer.endArray();
-    }
-    assertEquals("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]", stringer.toString());
-
-    stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.array();
-    }
-  }
-
-  @Test
-  public void testObjectNestingMaxDepthSupports20() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.object();
-      stringer.key("a");
-    }
-    stringer.value(false);
-    for (int i = 0; i < 20; i++) {
-      stringer.endObject();
-    }
-    assertEquals("{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":"
-        + "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":false"
-        + "}}}}}}}}}}}}}}}}}}}}", stringer.toString());
-
-    stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.object();
-      stringer.key("a");
-    }
-  }
-
-  @Test
-  public void testMixedMaxDepthSupports20() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    for (int i = 0; i < 20; i += 2) {
-      stringer.array();
-      stringer.object();
-      stringer.key("a");
-    }
-    stringer.value(false);
-    for (int i = 0; i < 20; i += 2) {
-      stringer.endObject();
-      stringer.endArray();
-    }
-    assertEquals("[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":"
-        + "[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":false" + "}]}]}]}]}]}]}]}]}]}]",
-        stringer.toString());
-
-    stringer = new JSONStringer();
-    for (int i = 0; i < 20; i += 2) {
-      stringer.array();
-      stringer.object();
-      stringer.key("a");
-    }
-  }
-
-  @Test
-  public void testMaxDepthWithArrayValue() throws JSONException {
-    JSONArray array = new JSONArray();
-    array.put(false);
-
-    JSONStringer stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.array();
-    }
-    stringer.value(array);
-    for (int i = 0; i < 20; i++) {
-      stringer.endArray();
-    }
-    assertEquals("[[[[[[[[[[[[[[[[[[[[[false]]]]]]]]]]]]]]]]]]]]]", stringer.toString());
-  }
-
-  @Test
-  public void testMaxDepthWithObjectValue() throws JSONException {
-    JSONObject object = new JSONObject();
-    object.put("a", false);
-    JSONStringer stringer = new JSONStringer();
-    for (int i = 0; i < 20; i++) {
-      stringer.object();
-      stringer.key("b");
-    }
-    stringer.value(object);
-    for (int i = 0; i < 20; i++) {
-      stringer.endObject();
-    }
-    assertEquals("{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":"
-        + "{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":"
-        + "{\"a\":false}}}}}}}}}}}}}}}}}}}}}", stringer.toString());
-  }
-
-  @Test
-  public void testMultipleRoots() throws JSONException {
-    JSONStringer stringer = new JSONStringer();
-    stringer.array();
-    stringer.endArray();
-    try {
-      stringer.object();
-      fail();
-    } catch (JSONException ignored) {
-    }
-  }
-
-  @Test
-  public void testEnums() {
-    JSONObject x = new JSONObject();
-    x.put("a", TimeUnit.SECONDS);
-    x.put("b", "xyx");
-    JSONStringer s = new JSONStringer();
-    s.array();
-    s.value(x);
-    s.endArray();
-    assertEquals("[{\"a\":\"SECONDS\",\"b\":\"xyx\"}]", s.toString());
-  }
-
-  @Test
-  public void testJsonString() {
-    JSONObject x = new JSONObject();
-    x.put("a", new Goo());
-    JSONStringer s = new JSONStringer();
-    s.array();
-    s.value(x);
-    s.endArray();
-    // note lack of quotes
-    assertEquals("[{\"a\":fffooo}]", s.toString());
-  }
-
-  private static class Goo implements JSONString {
-    @Override
-    public String toJSONString() {
-      return "fffooo";
-    }
-  }
-}


[26/34] geode git commit: GEODE-2142: Removing JSON licence stuff from NOTICE files

Posted by kl...@apache.org.
GEODE-2142: Removing JSON licence stuff from NOTICE files


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/f2262d13
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/f2262d13
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/f2262d13

Branch: refs/heads/GEODE-4160-mockito
Commit: f2262d13a81c59918f06a78c1073c76062e7f238
Parents: abeaa24
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Wed Feb 22 15:41:45 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:19:32 2017 -0800

----------------------------------------------------------------------
 geode-assembly/src/main/dist/NOTICE           | 2 --
 geode-pulse/src/main/webapp/META-INF/NOTICE   | 2 --
 geode-web-api/src/main/webapp/META-INF/NOTICE | 2 --
 geode-web/src/main/webapp/META-INF/NOTICE     | 2 --
 4 files changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/f2262d13/geode-assembly/src/main/dist/NOTICE
----------------------------------------------------------------------
diff --git a/geode-assembly/src/main/dist/NOTICE b/geode-assembly/src/main/dist/NOTICE
index 097bd7f..2cdda71 100644
--- a/geode-assembly/src/main/dist/NOTICE
+++ b/geode-assembly/src/main/dist/NOTICE
@@ -20,8 +20,6 @@ Copyright 2016 AddThis
 This product includes software developed by the MX4J
 project (http://mx4j.sourceforge.net).
 
-This project includes software licensed under the JSON license.
-
 Java ClassMate library was originally written by Tatu Saloranta (tatu.saloranta@iki.fi)
 
   Other developers who have contributed code are:

http://git-wip-us.apache.org/repos/asf/geode/blob/f2262d13/geode-pulse/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/geode-pulse/src/main/webapp/META-INF/NOTICE b/geode-pulse/src/main/webapp/META-INF/NOTICE
index dbbba76..166a9ee 100644
--- a/geode-pulse/src/main/webapp/META-INF/NOTICE
+++ b/geode-pulse/src/main/webapp/META-INF/NOTICE
@@ -20,8 +20,6 @@ Copyright 2016 AddThis
 This product includes software developed by the MX4J
 project (http://mx4j.sourceforge.net).
 
-This project includes software licensed under the JSON license.
-
 Jackson Core 2.8.0
 
   # Jackson JSON processor

http://git-wip-us.apache.org/repos/asf/geode/blob/f2262d13/geode-web-api/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/webapp/META-INF/NOTICE b/geode-web-api/src/main/webapp/META-INF/NOTICE
index 67ccc2c..8e1775b 100644
--- a/geode-web-api/src/main/webapp/META-INF/NOTICE
+++ b/geode-web-api/src/main/webapp/META-INF/NOTICE
@@ -20,8 +20,6 @@ Copyright 2016 AddThis
 This product includes software developed by the MX4J
 project (http://mx4j.sourceforge.net).
 
-This project includes software licensed under the JSON license.
-
 Java ClassMate library was originally written by Tatu Saloranta (tatu.saloranta@iki.fi)
 
   Other developers who have contributed code are:

http://git-wip-us.apache.org/repos/asf/geode/blob/f2262d13/geode-web/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/geode-web/src/main/webapp/META-INF/NOTICE b/geode-web/src/main/webapp/META-INF/NOTICE
index 2591148..8a36d55 100644
--- a/geode-web/src/main/webapp/META-INF/NOTICE
+++ b/geode-web/src/main/webapp/META-INF/NOTICE
@@ -20,8 +20,6 @@ Copyright 2016 AddThis
 This product includes software developed by the MX4J
 project (http://mx4j.sourceforge.net).
 
-This project includes software licensed under the JSON license.
-
 Spring Framework 4.3.6.RELEASE
 Copyright (c) 2002-2017 Pivotal, Inc.
 


[27/34] geode git commit: GEODE-2515: Disabling BaseLineAndCompareQueryPerfJUnitTest

Posted by kl...@apache.org.
GEODE-2515: Disabling BaseLineAndCompareQueryPerfJUnitTest

This is a performance test, it should not be run as part of precheckin.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/8ff2fd40
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/8ff2fd40
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/8ff2fd40

Branch: refs/heads/GEODE-4160-mockito
Commit: 8ff2fd4017ade81510e7705bf0f3254154a8805d
Parents: f2262d1
Author: Dan Smith <up...@apache.org>
Authored: Fri Feb 24 17:09:29 2017 -0800
Committer: Dan Smith <up...@apache.org>
Committed: Mon Feb 27 08:59:50 2017 -0800

----------------------------------------------------------------------
 .../geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/8ff2fd40/geode-core/src/test/java/org/apache/geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java
index 50a57c4..a46e1c4 100755
--- a/geode-core/src/test/java/org/apache/geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/BaseLineAndCompareQueryPerfJUnitTest.java
@@ -29,15 +29,18 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
 import java.util.*;
 import java.io.*;
 
+import org.apache.geode.test.junit.categories.PerformanceTest;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 /**
  * This test is to baseline and compare the performance figures for index usage benchmarks.
  */
-@Category(IntegrationTest.class)
+@Category(PerformanceTest.class)
+@Ignore("Performance tests should not be run as part of precheckin")
 public class BaseLineAndCompareQueryPerfJUnitTest {
 
   /** Creates a new instance of BaseLineAndCompareQueryPerfJUnitTest */


[29/34] geode git commit: GEODE-2404: Added support for destroying lucene indexes

Posted by kl...@apache.org.
GEODE-2404: Added support for destroying lucene indexes


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/11521a82
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/11521a82
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/11521a82

Branch: refs/heads/GEODE-4160-mockito
Commit: 11521a824f31ff03db13d0e59cb0fbf29e592151
Parents: c4a5ab2
Author: Barry Oglesby <bo...@pivotal.io>
Authored: Mon Feb 13 17:01:13 2017 -0800
Committer: Barry Oglesby <bo...@pivotal.io>
Committed: Mon Feb 27 10:06:48 2017 -0800

----------------------------------------------------------------------
 .../internal/AsyncEventQueueImpl.java           |   9 +
 .../geode/internal/DataSerializableFixedID.java |   2 +-
 .../geode/internal/i18n/LocalizedStrings.java   |   4 +
 .../geode/cache/lucene/LuceneService.java       |  14 +-
 .../internal/DestroyLuceneIndexMessage.java     | 109 ++++++++
 .../lucene/internal/InternalLuceneIndex.java    |   5 +
 .../LuceneIndexForPartitionedRegion.java        | 109 +++++++-
 .../cache/lucene/internal/LuceneIndexImpl.java  |  16 ++
 .../cache/lucene/internal/LuceneRawIndex.java   |   2 +
 .../lucene/internal/LuceneServiceImpl.java      |  57 ++++-
 .../lucene/internal/cli/LuceneCliStrings.java   |  28 ++-
 .../cli/LuceneFunctionSerializable.java         |  36 +++
 .../internal/cli/LuceneIndexCommands.java       | 113 +++++++--
 .../lucene/internal/cli/LuceneIndexDetails.java |  16 +-
 .../lucene/internal/cli/LuceneIndexInfo.java    |  15 +-
 .../lucene/internal/cli/LuceneQueryInfo.java    |  15 +-
 .../functions/LuceneDestroyIndexFunction.java   |  57 +++++
 .../lucene/LuceneIndexDestroyDUnitTest.java     | 247 +++++++++++++++++++
 .../cli/LuceneIndexCommandsDUnitTest.java       |  50 +++-
 .../cli/LuceneIndexCommandsJUnitTest.java       |  53 ++++
 .../LuceneDestroyIndexFunctionJUnitTest.java    |  93 +++++++
 .../LuceneClusterConfigurationDUnitTest.java    |  99 +++++++-
 22 files changed, 1068 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-core/src/main/java/org/apache/geode/cache/asyncqueue/internal/AsyncEventQueueImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/asyncqueue/internal/AsyncEventQueueImpl.java b/geode-core/src/main/java/org/apache/geode/cache/asyncqueue/internal/AsyncEventQueueImpl.java
index 3b99f1c..a44b9e4 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/asyncqueue/internal/AsyncEventQueueImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/asyncqueue/internal/AsyncEventQueueImpl.java
@@ -25,6 +25,7 @@ import org.apache.geode.cache.wan.GatewayEventFilter;
 import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter;
 import org.apache.geode.cache.wan.GatewaySender;
 import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.RegionQueue;
 import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
 import org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor;
@@ -191,8 +192,16 @@ public class AsyncEventQueueImpl implements AsyncEventQueue {
     return ((AbstractGatewaySender) sender).getIsMetaQueue();
   }
 
+  public void stop() {
+    if (this.sender.isRunning()) {
+      this.sender.stop();
+    }
+  }
+
   public void destroy() {
+    GemFireCacheImpl gfci = (GemFireCacheImpl) ((AbstractGatewaySender) this.sender).getCache();
     this.sender.destroy();
+    gfci.removeAsyncEventQueue(this);
   }
 
   public boolean isBucketSorted() {

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
index 74e40e9..4e45646 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
@@ -809,8 +809,8 @@ public interface DataSerializableFixedID extends SerializationVersions {
   public static final short LUCENE_ENTRY_SCORE = 2174;
   public static final short LUCENE_TOP_ENTRIES = 2175;
   public static final short LUCENE_TOP_ENTRIES_COLLECTOR = 2176;
-
   public static final short WAIT_UNTIL_FLUSHED_FUNCTION_CONTEXT = 2177;
+  public static final short DESTROY_LUCENE_INDEX_MESSAGE = 2178;
 
   // NOTE, codes > 65535 will take 4 bytes to serialize
 

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
index d855e29..fa63437 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
@@ -7674,6 +7674,10 @@ public class LocalizedStrings {
       new StringId(6650,
           "Caught the following exception attempting waitUntilFlushed and will return:");
 
+  public static final StringId LuceneService_INDEX_0_NOT_FOUND_IN_REGION_1 =
+      new StringId(6651, "Lucene index {0} was not found in region {1}.");
+  public static final StringId LuceneService_DESTROYED_INDEX_0_FROM_REGION_1 =
+      new StringId(6652, "Destroyed Lucene index {0} from region {1}.");
   /** Testing strings, messageId 90000-99999 **/
 
   /**

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneService.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneService.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneService.java
index d273760..5cfae59 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneService.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/LuceneService.java
@@ -101,10 +101,18 @@ public interface LuceneService {
 
   /**
    * Destroy the lucene index
-   * 
-   * @param index index object
+   *
+   * @param indexName the name of the index to destroy
+   * @param regionPath the path of the region whose index to destroy
+   */
+  public void destroyIndex(String indexName, String regionPath);
+
+  /**
+   * Destroy all the lucene indexes for the region
+   *
+   * @param regionPath The path of the region on which to destroy the indexes
    */
-  public void destroyIndex(LuceneIndex index);
+  public void destroyIndexes(String regionPath);
 
   /**
    * Get the lucene index object specified by region name and index name

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/DestroyLuceneIndexMessage.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/DestroyLuceneIndexMessage.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/DestroyLuceneIndexMessage.java
new file mode 100644
index 0000000..8bdef9b
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/DestroyLuceneIndexMessage.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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
+ *
+ * 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.apache.geode.cache.lucene.internal;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.lucene.LuceneServiceProvider;
+import org.apache.geode.distributed.internal.*;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Collection;
+
+public class DestroyLuceneIndexMessage extends PooledDistributionMessage
+    implements MessageWithReply {
+
+  private int processorId;
+
+  private String regionPath;
+
+  private String indexName;
+
+  private static final Logger logger = LogService.getLogger();
+
+  /* For serialization */
+  public DestroyLuceneIndexMessage() {}
+
+  protected DestroyLuceneIndexMessage(Collection recipients, int processorId, String regionPath,
+      String indexName) {
+    super();
+    setRecipients(recipients);
+    this.processorId = processorId;
+    this.regionPath = regionPath;
+    this.indexName = indexName;
+  }
+
+  @Override
+  protected void process(DistributionManager dm) {
+    ReplyException replyException = null;
+    try {
+      if (logger.isDebugEnabled()) {
+        logger.debug("DestroyLuceneIndexMessage: Destroying regionPath=" + this.regionPath
+            + "; indexName=" + this.indexName);
+      }
+      try {
+        Cache cache = GemFireCacheImpl.getInstance();
+        LuceneServiceImpl impl = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
+        impl.destroyIndex(this.indexName, this.regionPath, false);
+        if (logger.isDebugEnabled()) {
+          logger.debug("DestroyLuceneIndexMessage: Destroyed regionPath=" + this.regionPath
+              + "; indexName=" + this.indexName);
+        }
+      } catch (Throwable e) {
+        replyException = new ReplyException(e);
+        if (logger.isDebugEnabled()) {
+          logger.debug(
+              "DestroyLuceneIndexMessage: Caught the following exception attempting to destroy indexName="
+                  + this.indexName + "; regionPath=" + this.regionPath + ":",
+              e);
+        }
+      }
+    } finally {
+      ReplyMessage replyMsg = new ReplyMessage();
+      replyMsg.setRecipient(getSender());
+      replyMsg.setProcessorId(this.processorId);
+      if (replyException != null) {
+        replyMsg.setException(replyException);
+      }
+      dm.putOutgoing(replyMsg);
+    }
+  }
+
+  @Override
+  public int getDSFID() {
+    return DESTROY_LUCENE_INDEX_MESSAGE;
+  }
+
+  @Override
+  public void toData(DataOutput out) throws IOException {
+    super.toData(out);
+    out.writeInt(this.processorId);
+    DataSerializer.writeString(this.regionPath, out);
+    DataSerializer.writeString(this.indexName, out);
+  }
+
+  @Override
+  public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+    super.fromData(in);
+    this.processorId = in.readInt();
+    this.regionPath = DataSerializer.readString(in);
+    this.indexName = DataSerializer.readString(in);
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneIndex.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneIndex.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneIndex.java
index 2800f49..c28fcdc 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneIndex.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/InternalLuceneIndex.java
@@ -27,4 +27,9 @@ public interface InternalLuceneIndex extends LuceneIndex {
    */
   public void dumpFiles(String directory);
 
+  /**
+   * Destroy the index
+   */
+  public void destroy(boolean initiator);
+
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index 9a39b39..f45d94d 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -15,6 +15,7 @@
 
 package org.apache.geode.cache.lucene.internal;
 
+import org.apache.geode.CancelException;
 import org.apache.geode.cache.AttributesFactory;
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.FixedPartitionResolver;
@@ -24,6 +25,7 @@ import org.apache.geode.cache.PartitionResolver;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.lucene.internal.directory.DumpDirectoryFiles;
@@ -36,15 +38,23 @@ import org.apache.geode.cache.lucene.internal.repository.RepositoryManager;
 import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
 import org.apache.geode.cache.partition.PartitionListener;
 import org.apache.geode.distributed.internal.DM;
+import org.apache.geode.distributed.internal.ReplyException;
+import org.apache.geode.distributed.internal.ReplyProcessor21;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.PartitionedRegion;
 
+import java.util.Set;
+
 /* wrapper of IndexWriter */
 public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   protected Region<String, File> fileRegion;
   protected Region<ChunkKey, byte[]> chunkRegion;
   protected final FileSystemStats fileSystemStats;
 
+  public static final String FILES_REGION_SUFFIX = ".files";
+  public static final String CHUNKS_REGION_SUFFIX = ".chunks";
+
   public LuceneIndexForPartitionedRegion(String indexName, String regionPath, Cache cache) {
     super(indexName, regionPath, cache);
 
@@ -123,7 +133,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   }
 
   public String createFileRegionName() {
-    return LuceneServiceImpl.getUniqueIndexName(indexName, regionPath) + ".files";
+    return LuceneServiceImpl.getUniqueIndexRegionName(indexName, regionPath, FILES_REGION_SUFFIX);
   }
 
   boolean chunkRegionExists(String chunkRegionName) {
@@ -139,7 +149,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   }
 
   public String createChunkRegionName() {
-    return LuceneServiceImpl.getUniqueIndexName(indexName, regionPath) + ".chunks";
+    return LuceneServiceImpl.getUniqueIndexRegionName(indexName, regionPath, CHUNKS_REGION_SUFFIX);
   }
 
   private PartitionAttributesFactory configureLuceneRegionAttributesFactory(
@@ -192,4 +202,99 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
         .withArgs(new String[] {directory, indexName}).execute(DumpDirectoryFiles.ID);
     results.getResult();
   }
+
+  @Override
+  public void destroy(boolean initiator) {
+    if (logger.isDebugEnabled()) {
+      logger.debug("Destroying index regionPath=" + regionPath + "; indexName=" + indexName
+          + "; initiator=" + initiator);
+    }
+
+    // Invoke super destroy to remove the extension
+    super.destroy(initiator);
+
+    // Destroy the AsyncEventQueue
+    PartitionedRegion pr = (PartitionedRegion) getDataRegion();
+    destroyAsyncEventQueue(pr);
+
+    // Destroy the chunk region (colocated with the file region)
+    // localDestroyRegion can't be used because locally destroying regions is not supported on
+    // colocated regions
+    if (!chunkRegion.isDestroyed()) {
+      chunkRegion.destroyRegion();
+      if (logger.isDebugEnabled()) {
+        logger.debug("Destroyed chunkRegion=" + chunkRegion.getName());
+      }
+    }
+
+    // Destroy the file region (colocated with the application region)
+    // localDestroyRegion can't be used because locally destroying regions is not supported on
+    // colocated regions
+    if (!fileRegion.isDestroyed()) {
+      fileRegion.destroyRegion();
+      if (logger.isDebugEnabled()) {
+        logger.debug("Destroyed fileRegion=" + fileRegion.getName());
+      }
+    }
+
+    // Destroy index on remote members if necessary
+    if (initiator) {
+      destroyOnRemoteMembers(pr);
+    }
+
+    if (logger.isDebugEnabled()) {
+      logger.debug("Destroyed index regionPath=" + regionPath + "; indexName=" + indexName
+          + "; initiator=" + initiator);
+    }
+  }
+
+  private void destroyAsyncEventQueue(PartitionedRegion pr) {
+    String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, regionPath);
+
+    // Get the AsyncEventQueue
+    AsyncEventQueueImpl aeq = (AsyncEventQueueImpl) cache.getAsyncEventQueue(aeqId);
+
+    // Stop the AsyncEventQueue (this stops the AsyncEventQueue's underlying GatewaySender)
+    aeq.stop();
+
+    // Remove the id from the dataRegion's AsyncEventQueue ids
+    // Note: The region may already have been destroyed by a remote member
+    if (!pr.isDestroyed()) {
+      pr.getAttributesMutator().removeAsyncEventQueueId(aeqId);
+    }
+
+    // Destroy the aeq (this also removes it from the GemFireCacheImpl)
+    aeq.destroy();
+    if (logger.isDebugEnabled()) {
+      logger.debug("Destroyed aeqId=" + aeqId);
+    }
+  }
+
+  private void destroyOnRemoteMembers(PartitionedRegion pr) {
+    DM dm = pr.getDistributionManager();
+    Set<InternalDistributedMember> recipients = pr.getRegionAdvisor().adviseDataStore();
+    if (!recipients.isEmpty()) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("LuceneIndexForPartitionedRegion: About to send destroy message recipients="
+            + recipients);
+      }
+      ReplyProcessor21 processor = new ReplyProcessor21(dm, recipients);
+      DestroyLuceneIndexMessage message = new DestroyLuceneIndexMessage(recipients,
+          processor.getProcessorId(), regionPath, indexName);
+      dm.putOutgoing(message);
+      if (logger.isDebugEnabled()) {
+        logger.debug("LuceneIndexForPartitionedRegion: Sent message recipients=" + recipients);
+      }
+      try {
+        processor.waitForReplies();
+      } catch (ReplyException e) {
+        if (!(e.getCause() instanceof CancelException)) {
+          throw e;
+        }
+      } catch (InterruptedException e) {
+        dm.getCancelCriterion().checkCancelInProgress(e);
+        Thread.currentThread().interrupt();
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
index 42ccc84..cf519be 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.geode.internal.cache.extension.Extension;
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -203,6 +204,21 @@ public abstract class LuceneIndexImpl implements InternalLuceneIndex {
     dataRegion.getExtensionPoint().addExtension(creation);
   }
 
+  public void destroy(boolean initiator) {
+    // Find and delete the appropriate extension
+    Extension extensionToDelete = null;
+    for (Extension extension : getDataRegion().getExtensionPoint().getExtensions()) {
+      LuceneIndexCreation index = (LuceneIndexCreation) extension;
+      if (index.getName().equals(indexName)) {
+        extensionToDelete = extension;
+        break;
+      }
+    }
+    if (extensionToDelete != null) {
+      getDataRegion().getExtensionPoint().removeExtension(extensionToDelete);
+    }
+  }
+
   protected <K, V> Region<K, V> createRegion(final String regionName,
       final RegionAttributes<K, V> attributes) {
     // Create InternalRegionArguments to set isUsedForMetaRegion true to suppress xml generation

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
index a4e48ad..f4518aa 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
@@ -36,4 +36,6 @@ public class LuceneRawIndex extends LuceneIndexImpl {
     return;
   }
 
+  @Override
+  public void destroy(boolean initiator) {}
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index cf7b2c9..a608dd9 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -114,6 +114,11 @@ public class LuceneServiceImpl implements InternalLuceneService {
     return name;
   }
 
+  public static String getUniqueIndexRegionName(String indexName, String regionPath,
+      String regionSuffix) {
+    return getUniqueIndexName(indexName, regionPath) + regionSuffix;
+  }
+
   @Override
   public void createIndex(String indexName, String regionPath, String... fields) {
     if (fields == null || fields.length == 0) {
@@ -256,10 +261,53 @@ public class LuceneServiceImpl implements InternalLuceneService {
   }
 
   @Override
-  public void destroyIndex(LuceneIndex index) {
-    LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
+  public void destroyIndex(String indexName, String regionPath) {
+    destroyIndex(indexName, regionPath, true);
+  }
+
+  protected void destroyIndex(String indexName, String regionPath, boolean initiator) {
+    if (!regionPath.startsWith("/")) {
+      regionPath = "/" + regionPath;
+    }
+    LuceneIndexImpl indexImpl = (LuceneIndexImpl) getIndex(indexName, regionPath);
+    if (indexImpl == null) {
+      throw new IllegalArgumentException(
+          LocalizedStrings.LuceneService_INDEX_0_NOT_FOUND_IN_REGION_1.toLocalizedString(indexName,
+              regionPath));
+    } else {
+      indexImpl.destroy(initiator);
+      removeFromIndexMap(indexImpl);
+      logger.info(LocalizedStrings.LuceneService_DESTROYED_INDEX_0_FROM_REGION_1
+          .toLocalizedString(indexName, regionPath));
+    }
+  }
+
+  @Override
+  public void destroyIndexes(String regionPath) {
+    destroyIndexes(regionPath, true);
+  }
+
+  protected void destroyIndexes(String regionPath, boolean initiator) {
+    if (!regionPath.startsWith("/")) {
+      regionPath = "/" + regionPath;
+    }
+    List<LuceneIndexImpl> indexesToDestroy = new ArrayList<>();
+    for (LuceneIndex index : getAllIndexes()) {
+      if (index.getRegionPath().equals(regionPath)) {
+        LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
+        indexImpl.destroy(initiator);
+        indexesToDestroy.add(indexImpl);
+      }
+    }
+    for (LuceneIndex index : indexesToDestroy) {
+      removeFromIndexMap(index);
+      logger.info(LocalizedStrings.LuceneService_DESTROYED_INDEX_0_FROM_REGION_1
+          .toLocalizedString(index.getName(), regionPath));
+    }
+  }
+
+  private void removeFromIndexMap(LuceneIndex index) {
     indexMap.remove(getUniqueIndexName(index.getName(), index.getRegionPath()));
-    // indexImpl.close();
   }
 
   @Override
@@ -320,6 +368,9 @@ public class LuceneServiceImpl implements InternalLuceneService {
 
     DSFIDFactory.registerDSFID(DataSerializableFixedID.WAIT_UNTIL_FLUSHED_FUNCTION_CONTEXT,
         WaitUntilFlushedFunctionContext.class);
+
+    DSFIDFactory.registerDSFID(DataSerializableFixedID.DESTROY_LUCENE_INDEX_MESSAGE,
+        DestroyLuceneIndexMessage.class);
   }
 
   public Collection<LuceneIndexCreationProfile> getAllDefinedIndexes() {

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneCliStrings.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneCliStrings.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneCliStrings.java
index 36f5aeb..fbb70d2 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneCliStrings.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneCliStrings.java
@@ -37,7 +37,7 @@ public class LuceneCliStrings {
   public static final String LUCENE_CREATE_INDEX__NAME__HELP =
       "Name of the lucene index to create.";
   public static final String LUCENE_CREATE_INDEX__REGION_HELP =
-      "Name/Path of the region where the lucene index is created on.";
+      "Name/Path of the region on which to create the lucene index.";
   public static final String LUCENE_CREATE_INDEX__FIELD = "field";
   public static final String LUCENE_CREATE_INDEX__FIELD_HELP =
       "fields on the region values which are stored in the lucene index.";
@@ -61,14 +61,13 @@ public class LuceneCliStrings {
   // Describe lucene index commands
   public static final String LUCENE_DESCRIBE_INDEX = "describe lucene index";
   public static final String LUCENE_DESCRIBE_INDEX__HELP =
-      "Display the describe of lucene indexes created for all members.";
+      "Display the description of lucene indexes created for all members.";
   public static final String LUCENE_DESCRIBE_INDEX__ERROR_MESSAGE =
       "An error occurred while collecting lucene index information across the Geode cluster: %1$s";
   public static final String LUCENE_DESCRIBE_INDEX__NAME__HELP =
       "Name of the lucene index to describe.";
   public static final String LUCENE_DESCRIBE_INDEX__REGION_HELP =
-      "Name/Path of the region where the lucene index to be described exists.";
-
+      "Name/Path of the region defining the lucene index to be described.";
 
   // Search lucene index commands
   public static final String LUCENE_SEARCH_INDEX = "search lucene";
@@ -78,7 +77,7 @@ public class LuceneCliStrings {
   public static final String LUCENE_SEARCH_INDEX__NAME__HELP =
       "Name of the lucene index to search.";
   public static final String LUCENE_SEARCH_INDEX__REGION_HELP =
-      "Name/Path of the region where the lucene index exists.";
+      "Name/Path of the region defining the lucene index to be searched.";
   public static final String LUCENE_SEARCH_INDEX__QUERY_STRING = "queryStrings";
   public static final String LUCENE_SEARCH_INDEX__LIMIT = "limit";
   public static final String LUCENE_SEARCH_INDEX__LIMIT__HELP = "Number of search results needed";
@@ -95,4 +94,23 @@ public class LuceneCliStrings {
   public static final String LUCENE_SEARCH_INDEX__KEYSONLY__HELP =
       "Return only keys of search results.";
 
+  // Destroy lucene index command
+  public static final String LUCENE_DESTROY_INDEX = "destroy lucene index";
+  public static final String LUCENE_DESTROY_INDEX__HELP = "Destroy the lucene index.";
+  public static final String LUCENE_DESTROY_INDEX__EXCEPTION_MESSAGE =
+      "An unexpected exception occurred while destroying lucene index:";
+  public static final String LUCENE_DESTROY_INDEX__NAME__HELP =
+      "Name of the lucene index to destroy.";
+  public static final String LUCENE_DESTROY_INDEX__REGION_HELP =
+      "Name of the region defining the lucene index to be destroyed.";
+  public static final String LUCENE_DESTROY_INDEX__MSG__REGION_CANNOT_BE_EMPTY =
+      "Region cannot be empty.";
+  public static final String LUCENE_DESTROY_INDEX__MSG__INDEX_CANNOT_BE_EMPTY =
+      "Index cannot be empty.";
+  public static final String LUCENE_DESTROY_INDEX__MSG__COULDNOT_FIND_MEMBERS_FOR_REGION_0 =
+      "Could not find any members defining region {0}.";
+  public static final String LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FOR_REGION_0 =
+      "Successfully destroyed all lucene indexes for region {0}";
+  public static final String LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEX_0_FOR_REGION_1 =
+      "Successfully destroyed lucene index {0} for region {1}";
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneFunctionSerializable.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneFunctionSerializable.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneFunctionSerializable.java
new file mode 100644
index 0000000..1390e22
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneFunctionSerializable.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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
+ *
+ * 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.apache.geode.cache.lucene.internal.cli;
+
+import java.io.Serializable;
+
+public class LuceneFunctionSerializable implements Serializable {
+
+  protected final String indexName;
+  protected final String regionPath;
+
+  public LuceneFunctionSerializable(final String indexName, final String regionPath) {
+    this.indexName = indexName;
+    this.regionPath = regionPath;
+  }
+
+  public String getIndexName() {
+    return indexName;
+  }
+
+  public String getRegionPath() {
+    return regionPath;
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
index b84246c..e2d85a6 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
@@ -16,16 +16,12 @@ package org.apache.geode.cache.lucene.internal.cli;
 
 import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.execute.Execution;
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionInvocationTargetException;
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.cache.lucene.internal.cli.functions.LuceneCreateIndexFunction;
-import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction;
-import org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction;
-import org.apache.geode.cache.lucene.internal.cli.functions.LuceneSearchIndexFunction;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.execute.*;
+import org.apache.geode.cache.lucene.internal.cli.functions.*;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.internal.cache.execute.AbstractExecution;
+import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.security.IntegratedSecurityService;
 import org.apache.geode.internal.security.SecurityService;
 import org.apache.geode.management.cli.CliMetaData;
@@ -70,6 +66,8 @@ public class LuceneIndexCommands extends AbstractCommandsSupport {
       new LuceneDescribeIndexFunction();
   private static final LuceneSearchIndexFunction searchIndexFunction =
       new LuceneSearchIndexFunction();
+  private static final LuceneDestroyIndexFunction destroyIndexFunction =
+      new LuceneDestroyIndexFunction();
   private List<LuceneSearchResults> searchResults = null;
 
   private SecurityService securityService = IntegratedSecurityService.getSecurityService();
@@ -316,6 +314,74 @@ public class LuceneIndexCommands extends AbstractCommandsSupport {
     }
   }
 
+  @CliCommand(value = LuceneCliStrings.LUCENE_DESTROY_INDEX,
+      help = LuceneCliStrings.LUCENE_DESTROY_INDEX__HELP)
+  @CliMetaData(shellOnly = false,
+      relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})
+  @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
+  public Result destroyIndex(
+      @CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = false,
+          help = LuceneCliStrings.LUCENE_DESTROY_INDEX__NAME__HELP) final String indexName,
+
+      @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true,
+          optionContext = ConverterHint.REGIONPATH,
+          help = LuceneCliStrings.LUCENE_DESTROY_INDEX__REGION_HELP) final String regionPath) {
+    if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
+      return ResultBuilder.createInfoResult(
+          CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__REGION_CANNOT_BE_EMPTY));
+    }
+
+    if (StringUtils.isEmpty(indexName)) {
+      return ResultBuilder.createInfoResult(
+          CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__INDEX_CANNOT_BE_EMPTY));
+    }
+
+    this.securityService.authorizeRegionManage(regionPath);
+
+    Result result = null;
+    try {
+      LuceneIndexInfo indexInfo = new LuceneIndexInfo(indexName, regionPath);
+      ResultCollector<?, ?> rc = executeFunction(destroyIndexFunction, indexInfo, false);
+      List<CliFunctionResult> functionResults = (List<CliFunctionResult>) rc.getResult();
+      CliFunctionResult cliFunctionResult = functionResults.get(0);
+
+      final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
+      tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
+      if (cliFunctionResult.isSuccessful()) {
+        tabularResult.accumulate("Status",
+            indexName == null
+                ? CliStrings.format(
+                    LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FOR_REGION_0,
+                    new Object[] {regionPath})
+                : CliStrings.format(
+                    LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEX_0_FOR_REGION_1,
+                    new Object[] {indexName, regionPath}));
+      } else {
+        tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
+      }
+      result = ResultBuilder.buildResult(tabularResult);
+      if (cliFunctionResult.isSuccessful()) {
+        persistClusterConfiguration(result, () -> {
+          // Update the xml entity (region entity) to remove the async event id(s) and index(es)
+          getSharedConfiguration().addXmlEntity((XmlEntity) cliFunctionResult.getXmlEntity(), null);
+        });
+      }
+    } catch (FunctionInvocationTargetException ignore) {
+      result = ResultBuilder.createGemFireErrorResult(CliStrings.format(
+          CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, LuceneCliStrings.LUCENE_DESTROY_INDEX));
+    } catch (VirtualMachineError e) {
+      SystemFailure.initiateFailure(e);
+      throw e;
+    } catch (IllegalArgumentException e) {
+      result = ResultBuilder.createInfoResult(e.getMessage());
+    } catch (Throwable t) {
+      SystemFailure.checkFailure();
+      getCache().getLogger().warning(LuceneCliStrings.LUCENE_DESTROY_INDEX__EXCEPTION_MESSAGE, t);
+      result = ResultBuilder.createGemFireErrorResult(t.getMessage());
+    }
+    return result;
+  }
+
   private Result displayResults(int pageSize, boolean keysOnly) throws Exception {
     if (searchResults.size() == 0) {
       return ResultBuilder
@@ -428,25 +494,30 @@ public class LuceneIndexCommands extends AbstractCommandsSupport {
 
   protected ResultCollector<?, ?> executeFunctionOnGroups(FunctionAdapter function, String[] groups,
       final LuceneIndexInfo indexInfo) throws IllegalArgumentException, CommandResultException {
-    final Set<DistributedMember> targetMembers;
+    ResultCollector<?, ?> results = null;
     if (function != createIndexFunction) {
-      targetMembers =
-          CliUtil.getMembersForeRegionViaFunction(getCache(), indexInfo.getRegionPath(), true);
-      if (targetMembers.isEmpty()) {
-        throw new IllegalArgumentException("Region not found.");
-      }
+      results = executeFunction(function, indexInfo, true);
     } else {
-      targetMembers = CliUtil.findMembersOrThrow(groups, null);
+      Set<DistributedMember> targetMembers = CliUtil.findMembersOrThrow(groups, null);
+      results = CliUtil.executeFunction(function, indexInfo, targetMembers);
     }
-    return CliUtil.executeFunction(function, indexInfo, targetMembers);
+    return results;
   }
 
   protected ResultCollector<?, ?> executeSearch(final LuceneQueryInfo queryInfo) throws Exception {
-    final Set<DistributedMember> targetMembers =
-        CliUtil.getMembersForeRegionViaFunction(getCache(), queryInfo.getRegionPath(), false);
-    if (targetMembers.isEmpty())
-      throw new IllegalArgumentException("Region not found.");
-    return CliUtil.executeFunction(searchIndexFunction, queryInfo, targetMembers);
+    return executeFunction(searchIndexFunction, queryInfo, false);
+  }
+
+  protected ResultCollector<?, ?> executeFunction(Function function,
+      LuceneFunctionSerializable functionArguments, boolean returnAllMembers) {
+    Set<DistributedMember> targetMembers = CliUtil.getMembersForeRegionViaFunction(getCache(),
+        functionArguments.getRegionPath(), returnAllMembers);
+    if (targetMembers.isEmpty()) {
+      throw new IllegalArgumentException(CliStrings.format(
+          LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__COULDNOT_FIND_MEMBERS_FOR_REGION_0,
+          new Object[] {functionArguments.getRegionPath()}));
+    }
+    return CliUtil.executeFunction(function, functionArguments, targetMembers);
   }
 
   @CliAvailabilityIndicator({LuceneCliStrings.LUCENE_SEARCH_INDEX,

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
index 02a19a1..b2b0466 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexDetails.java
@@ -29,10 +29,9 @@ import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
 
 import org.apache.lucene.analysis.Analyzer;
 
-public class LuceneIndexDetails implements Comparable<LuceneIndexDetails>, Serializable {
+public class LuceneIndexDetails extends LuceneFunctionSerializable
+    implements Comparable<LuceneIndexDetails> {
   private static final long serialVersionUID = 1L;
-  private final String indexName;
-  private final String regionPath;
   private final String serverName;
   private final String[] searchableFieldNames;
   private Map<String, String> fieldAnalyzers = null;
@@ -42,8 +41,7 @@ public class LuceneIndexDetails implements Comparable<LuceneIndexDetails>, Seria
   public LuceneIndexDetails(final String indexName, final String regionPath,
       final String[] searchableFieldNames, final Map<String, Analyzer> fieldAnalyzers,
       LuceneIndexStats indexStats, boolean initialized, final String serverName) {
-    this.indexName = indexName;
-    this.regionPath = regionPath;
+    super(indexName, regionPath);
     this.serverName = serverName;
     this.searchableFieldNames = searchableFieldNames;
     this.fieldAnalyzers = getFieldAnalyzerStrings(fieldAnalyzers);
@@ -141,14 +139,6 @@ public class LuceneIndexDetails implements Comparable<LuceneIndexDetails>, Seria
     return initialized;
   }
 
-  public String getIndexName() {
-    return indexName;
-  }
-
-  public String getRegionPath() {
-    return regionPath;
-  }
-
   private static <T extends Comparable<T>> int compare(final T obj1, final T obj2) {
     return (obj1 == null && obj2 == null ? 0
         : (obj1 == null ? 1 : (obj2 == null ? -1 : obj1.compareTo(obj2))));

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo.java
index b714ff1..41b066e 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexInfo.java
@@ -24,18 +24,15 @@ import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
 
 import org.apache.lucene.analysis.Analyzer;
 
-public class LuceneIndexInfo implements Serializable {
+public class LuceneIndexInfo extends LuceneFunctionSerializable {
   private static final long serialVersionUID = 1L;
 
-  private final String indexName;
-  private final String regionPath;
   private final String[] searchableFieldNames;
   private final String[] fieldAnalyzers;
 
   public LuceneIndexInfo(final String indexName, final String regionPath,
       final String[] searchableFieldNames, String[] fieldAnalyzers) {
-    this.indexName = indexName;
-    this.regionPath = regionPath;
+    super(indexName, regionPath);
     this.searchableFieldNames = searchableFieldNames;
     this.fieldAnalyzers = fieldAnalyzers;
   }
@@ -44,14 +41,6 @@ public class LuceneIndexInfo implements Serializable {
     this(indexName, regionPath, null, null);
   }
 
-  public String getIndexName() {
-    return indexName;
-  }
-
-  public String getRegionPath() {
-    return regionPath;
-  }
-
   public String[] getSearchableFieldNames() {
     return searchableFieldNames;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo.java
index 8d34e2e..e57badb 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneQueryInfo.java
@@ -19,10 +19,8 @@ import java.io.Serializable;
 
 import org.apache.geode.cache.lucene.LuceneQueryFactory;
 
-public class LuceneQueryInfo implements Serializable {
+public class LuceneQueryInfo extends LuceneFunctionSerializable {
   private static final long serialVersionUID = 1L;
-  private String indexName;
-  private String regionPath;
   private String queryString;
   private String defaultField;
   private int limit;
@@ -30,22 +28,13 @@ public class LuceneQueryInfo implements Serializable {
 
   public LuceneQueryInfo(final String indexName, final String regionPath, final String queryString,
       final String defaultField, final int limit, final boolean keysOnly) {
-    this.indexName = indexName;
-    this.regionPath = regionPath;
+    super(indexName, regionPath);
     this.queryString = queryString;
     this.defaultField = defaultField;
     this.limit = limit;
     this.keysOnly = keysOnly;
   }
 
-  public String getIndexName() {
-    return indexName;
-  }
-
-  public String getRegionPath() {
-    return regionPath;
-  }
-
   public String getQueryString() {
     return queryString;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunction.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunction.java
new file mode 100644
index 0000000..1535637
--- /dev/null
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunction.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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
+ *
+ * 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.apache.geode.cache.lucene.internal.cli.functions;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.lucene.LuceneService;
+import org.apache.geode.cache.lucene.LuceneServiceProvider;
+import org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo;
+import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
+import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+
+public class LuceneDestroyIndexFunction implements Function, InternalEntity {
+
+  public void execute(final FunctionContext context) {
+    String memberId = getCache().getDistributedSystem().getDistributedMember().getId();
+    try {
+      LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
+      String indexName = indexInfo.getIndexName();
+      String regionPath = indexInfo.getRegionPath();
+      LuceneService service = LuceneServiceProvider.get(getCache());
+      if (indexName == null) {
+        service.destroyIndexes(regionPath);
+      } else {
+        service.destroyIndex(indexName, regionPath);
+      }
+      context.getResultSender()
+          .lastResult(new CliFunctionResult(memberId, getXmlEntity(regionPath)));
+    } catch (Exception e) {
+      context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
+    }
+  }
+
+  protected XmlEntity getXmlEntity(String regionPath) {
+    return new XmlEntity(CacheXml.REGION, "name", regionPath);
+  }
+
+  protected Cache getCache() {
+    return CacheFactory.getAnyInstance();
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
new file mode 100644
index 0000000..6260075
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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
+ *
+ * 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.apache.geode.cache.lucene;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.test.TestObject;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.awaitility.Awaitility;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+import static org.apache.geode.internal.Assert.fail;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+@Category(DistributedTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class LuceneIndexDestroyDUnitTest extends LuceneDUnitTest {
+
+  private volatile boolean STOP_PUTS = false;
+
+  private final Object[] parametersForIndexDestroys() {
+    String[] destroyDataRegionParameters = {"true", "false"};
+    RegionTestableType[] regionTestTypes = getListOfRegionTestTypes();
+    return parameterCombiner(destroyDataRegionParameters, regionTestTypes);
+  }
+
+  @Test
+  @Parameters(method = "parametersForIndexDestroys")
+  public void verifyDestroySingleIndex(boolean destroyDataRegion, RegionTestableType regionType) {
+    // Create index and region
+    dataStore1.invoke(() -> initDataStore(createIndex(), regionType));
+    dataStore2.invoke(() -> initDataStore(createIndex(), regionType));
+
+    // Verify index created
+    dataStore1.invoke(() -> verifyIndexCreated());
+    dataStore2.invoke(() -> verifyIndexCreated());
+
+    // Attempt to destroy data region (should fail)
+    if (destroyDataRegion) {
+      dataStore1.invoke(() -> destroyDataRegion(false));
+    }
+
+    // Destroy index (only needs to be done on one member)
+    dataStore1.invoke(() -> destroyIndex());
+
+    // Verify index destroyed
+    dataStore1.invoke(() -> verifyIndexDestroyed());
+    dataStore2.invoke(() -> verifyIndexDestroyed());
+
+    // Attempt to destroy data region (should succeed)
+    if (destroyDataRegion) {
+      dataStore1.invoke(() -> destroyDataRegion(true));
+    }
+  }
+
+  @Test
+  @Parameters(method = "parametersForIndexDestroys")
+  public void verifyDestroyAllIndexes(boolean destroyDataRegion, RegionTestableType regionType) {
+    // Create indexes and region
+    dataStore1.invoke(() -> initDataStore(createIndexes(), regionType));
+    dataStore2.invoke(() -> initDataStore(createIndexes(), regionType));
+
+    // Verify indexes created
+    dataStore1.invoke(() -> verifyIndexesCreated());
+    dataStore2.invoke(() -> verifyIndexesCreated());
+
+    // Attempt to destroy data region (should fail)
+    if (destroyDataRegion) {
+      dataStore1.invoke(() -> destroyDataRegion(false));
+    }
+
+    // Destroy indexes (only needs to be done on one member)
+    dataStore1.invoke(() -> destroyIndexes());
+
+    // Verify indexes destroyed
+    dataStore1.invoke(() -> verifyIndexesDestroyed());
+    dataStore2.invoke(() -> verifyIndexesDestroyed());
+
+    // Attempt to destroy data region (should succeed)
+    if (destroyDataRegion) {
+      dataStore1.invoke(() -> destroyDataRegion(true));
+    }
+  }
+
+  @Ignore
+  // Destroying an index while puts are occurring currently fails with a
+  // GatewaySenderConfigurationException.
+  @Parameters(method = "getListOfServerRegionTestTypes")
+  public void verifyDestroySingleIndexWhileDoingPuts(RegionTestableType regionType)
+      throws Exception {
+    // Create index and region
+    dataStore1.invoke(() -> initDataStore(createIndex(), regionType));
+    dataStore2.invoke(() -> initDataStore(createIndex(), regionType));
+
+    // Verify index created
+    dataStore1.invoke(() -> verifyIndexCreated());
+    dataStore2.invoke(() -> verifyIndexCreated());
+
+    // Start puts
+    AsyncInvocation putter = dataStore1.invokeAsync(() -> doPuts());
+
+    // Wait until puts have started
+    dataStore1.invoke(() -> waitUntilPutsHaveStarted());
+
+    // Destroy index (only needs to be done on one member)
+    dataStore1.invoke(() -> destroyIndex());
+
+    // Verify index destroyed
+    dataStore1.invoke(() -> verifyIndexDestroyed());
+    dataStore2.invoke(() -> verifyIndexDestroyed());
+
+    // End puts
+    dataStore1.invoke(() -> stopPuts());
+    putter.join();
+  }
+
+
+  private SerializableRunnableIF createIndex() {
+    return () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndex(INDEX_NAME, REGION_NAME, "text");
+    };
+  }
+
+  private SerializableRunnableIF createIndexes() {
+    return () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndex(INDEX_NAME + "0", REGION_NAME, "text");
+      luceneService.createIndex(INDEX_NAME + "1", REGION_NAME, "text");
+    };
+  }
+
+  private void verifyIndexCreated() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    assertNotNull(luceneService.getIndex(INDEX_NAME, REGION_NAME));
+  }
+
+  private void verifyIndexesCreated() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    assertNotNull(luceneService.getIndex(INDEX_NAME + "0", REGION_NAME));
+    assertNotNull(luceneService.getIndex(INDEX_NAME + "1", REGION_NAME));
+  }
+
+  private void doPuts() throws Exception {
+    Region region = getCache().getRegion(REGION_NAME);
+    int i = 0;
+    while (!STOP_PUTS) {
+      region.put(i++, new TestObject());
+      // Thread.sleep(50);
+    }
+  }
+
+  private void stopPuts() {
+    STOP_PUTS = true;
+  }
+
+  private void waitUntilPutsHaveStarted() {
+    Awaitility.waitAtMost(30, TimeUnit.SECONDS)
+        .until(() -> getCache().getRegion(REGION_NAME).size() > 0);
+  }
+
+  private void destroyDataRegion(boolean shouldSucceed) {
+    Region region = getCache().getRegion(REGION_NAME);
+    assertNotNull(region);
+    try {
+      region.destroyRegion();
+      if (!shouldSucceed) {
+        fail("should not have been able to destroy data region named " + region.getFullPath());
+      }
+    } catch (IllegalStateException e) {
+      if (shouldSucceed) {
+        fail(e);
+      }
+    }
+  }
+
+  private void destroyIndex() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    luceneService.destroyIndex(INDEX_NAME, REGION_NAME);
+  }
+
+  private void destroyIndexes() {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+    luceneService.destroyIndexes(REGION_NAME);
+  }
+
+  private void verifyIndexDestroyed() {
+    verifyIndexDestroyed(INDEX_NAME);
+  }
+
+  private void verifyIndexesDestroyed() {
+    verifyIndexDestroyed(INDEX_NAME + "0");
+    verifyIndexDestroyed(INDEX_NAME + "1");
+  }
+
+  private void verifyIndexDestroyed(String indexName) {
+    LuceneService luceneService = LuceneServiceProvider.get(getCache());
+
+    // Verify the index itself no longer exists
+    assertNull(luceneService.getIndex(indexName, REGION_NAME));
+
+    // Verify the underlying files region no longer exists
+    String filesRegionName = LuceneServiceImpl.getUniqueIndexRegionName(indexName, REGION_NAME,
+        LuceneIndexForPartitionedRegion.FILES_REGION_SUFFIX);
+    assertNull(getCache().getRegion(filesRegionName));
+
+    // Verify the underlying chunks region no longer exists
+    String chunksRegionName = LuceneServiceImpl.getUniqueIndexRegionName(indexName, REGION_NAME,
+        LuceneIndexForPartitionedRegion.CHUNKS_REGION_SUFFIX);
+    assertNull(getCache().getRegion(chunksRegionName));
+
+    // Verify the underlying AsyncEventQueue no longer exists
+    String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, REGION_NAME);
+    assertNull(getCache().getAsyncEventQueue(aeqId));
+
+    // Verify the data region extension no longer exists
+    LocalRegion region = (LocalRegion) getCache().getRegion(REGION_NAME);
+    assertFalse(region.getExtensionPoint().getExtensions().iterator().hasNext());
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 49aa057..efc11ab 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -28,6 +28,7 @@ import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.CommandManager;
 import org.apache.geode.management.internal.cli.commands.CliCommandTestBase;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.result.TabularResultData;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
@@ -349,7 +350,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "notAnIndex");
     csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
     String resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString.contains("Region not found"));
+    assertTrue(resultAsString.contains(getRegionNotFoundErrorMessage(REGION_NAME)));
   }
 
   @Test
@@ -498,7 +499,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD, "field2");
 
     String resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString.contains("Region not found"));
+    assertTrue(resultAsString.contains(getRegionNotFoundErrorMessage(REGION_NAME)));
   }
 
   @Test
@@ -552,6 +553,45 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
 
   }
 
+  @Test
+  public void destroySingleIndexOnRegion() throws Exception {
+    final VM vm1 = Host.getHost(0).getVM(1);
+    createIndex(vm1);
+    CommandManager.getInstance().add(LuceneIndexCommands.class.newInstance());
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_DESTROY_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    String resultAsString = executeCommandAndLogResult(csb);
+    String expectedStatus = CliStrings.format(
+        LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEX_0_FOR_REGION_1,
+        new Object[] {INDEX_NAME, REGION_NAME});
+    assertTrue(resultAsString.contains(expectedStatus));
+  }
+
+  @Test
+  public void destroyAllIndexesOnRegion() throws Exception {
+    final VM vm1 = Host.getHost(0).getVM(1);
+    createIndex(vm1);
+    CommandManager.getInstance().add(LuceneIndexCommands.class.newInstance());
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_DESTROY_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    String resultAsString = executeCommandAndLogResult(csb);
+    String expectedStatus = CliStrings.format(
+        LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FOR_REGION_0,
+        new Object[] {REGION_NAME});
+    assertTrue(resultAsString.contains(expectedStatus));
+  }
+
+  @Test
+  public void destroyIndexWithoutRegionShouldReturnError() throws Exception {
+    final VM vm1 = Host.getHost(0).getVM(1);
+    createIndexWithoutRegion(vm1);
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_DESTROY_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    String resultAsString = executeCommandAndLogResult(csb);
+    assertTrue(resultAsString.contains(getRegionNotFoundErrorMessage(REGION_NAME)));
+  }
+
   private void createRegion() {
     getCache().createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
   }
@@ -628,6 +668,12 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     });
   }
 
+  private String getRegionNotFoundErrorMessage(String regionPath) {
+    return CliStrings.format(
+        LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__COULDNOT_FIND_MEMBERS_FOR_REGION_0,
+        new Object[] {regionPath});
+  }
+
   protected class TestObject implements Serializable {
     private String field1;
     private String field2;

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
index 6ddef9e..9e8d7a9 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsJUnitTest.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.core.KeywordAnalyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -41,6 +42,7 @@ import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneCreateIndexFunction;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction;
+import org.apache.geode.cache.lucene.internal.cli.functions.LuceneDestroyIndexFunction;
 import org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.internal.cache.execute.AbstractExecution;
@@ -401,6 +403,57 @@ public class LuceneIndexCommandsJUnitTest {
     assertEquals(queryResults.size(), data.retrieveAllValues("key").size());
   }
 
+  @Test
+  public void testDestroySingleIndexOnRegion() throws Exception {
+    LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
+    String indexName = "index";
+    String regionPath = "regionPath";
+    CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
+    String expectedMember = "member";
+    String expectedStatus = CliStrings.format(
+        LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEX_0_FOR_REGION_1,
+        new Object[] {indexName, regionPath});
+    verifyDestroyIndexCommandResult(result, expectedMember, expectedStatus);
+  }
+
+  @Test
+  public void testDestroyAllIndexesOnRegion() throws Exception {
+    LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
+    String indexName = null;
+    String regionPath = "regionPath";
+    CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
+    String expectedMember = "member";
+    String expectedStatus = CliStrings.format(
+        LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FOR_REGION_0,
+        new Object[] {regionPath});
+    verifyDestroyIndexCommandResult(result, expectedMember, expectedStatus);
+  }
+
+  private LuceneIndexCommands createTestLuceneIndexCommandsForDestroyIndex() {
+    final Cache mockCache = mock(Cache.class);
+    final ResultCollector mockResultCollector = mock(ResultCollector.class);
+    final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
+
+    final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
+    cliFunctionResults.add(new CliFunctionResult("member", true, "Index Destroyed"));
+
+    doReturn(mockResultCollector).when(commands).executeFunction(
+        isA(LuceneDestroyIndexFunction.class), any(LuceneIndexInfo.class), eq(false));
+    doReturn(cliFunctionResults).when(mockResultCollector).getResult();
+    return commands;
+  }
+
+  private void verifyDestroyIndexCommandResult(CommandResult result, String expectedMember,
+      String expectedStatus) {
+    assertEquals(Status.OK, result.getStatus());
+    TabularResultData data = (TabularResultData) result.getResultData();
+    List<String> members = data.retrieveAllValues("Member");
+    List<String> status = data.retrieveAllValues("Status");
+    assertTrue(members.size() == 1);
+    assertEquals(expectedMember, members.get(0));
+    assertEquals(expectedStatus, status.get(0));
+  }
+
   private String getPage(final LuceneSearchResults[] expectedResults, int[] indexList) {
     final TabularResultData data = ResultBuilder.createTabularResultData();
     for (int i : indexList) {

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
new file mode 100644
index 0000000..f86f4a1
--- /dev/null
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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
+ *
+ * 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.apache.geode.cache.lucene.internal.cli.functions;
+
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.cache.lucene.internal.InternalLuceneService;
+import org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+import org.apache.geode.test.fake.Fakes;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+@Category(UnitTest.class)
+public class LuceneDestroyIndexFunctionJUnitTest {
+
+  private InternalLuceneService service;
+  private GemFireCacheImpl cache;
+  private String member;
+  private FunctionContext context;
+  private ResultSender resultSender;
+
+  @Before
+  public void prepare() {
+    this.cache = Fakes.cache();
+    this.member = Fakes.distributedSystem().getDistributedMember().getId();
+    this.service = mock(InternalLuceneService.class);
+    when(this.cache.getService(InternalLuceneService.class)).thenReturn(this.service);
+    this.context = mock(FunctionContext.class);
+    this.resultSender = mock(ResultSender.class);
+    when(this.context.getResultSender()).thenReturn(this.resultSender);
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testExecuteWithRegionAndIndex() throws Throwable {
+    LuceneIndexInfo indexInfo = new LuceneIndexInfo("index1", "/region1");
+    when(this.context.getArguments()).thenReturn(indexInfo);
+    LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
+    function = spy(function);
+    doReturn(this.cache).when(function).getCache();
+    doReturn(mock(XmlEntity.class)).when(function).getXmlEntity(any());
+    function.execute(this.context);
+    verify(this.service).destroyIndex(eq("index1"), eq("/region1"));
+    verify(this.service, never()).destroyIndexes(eq("/region1"));
+    ArgumentCaptor<CliFunctionResult> resultCaptor =
+        ArgumentCaptor.forClass(CliFunctionResult.class);
+    verify(resultSender).lastResult(resultCaptor.capture());
+    CliFunctionResult result = resultCaptor.getValue();
+    assertEquals(this.member, result.getMemberIdOrName());
+    assertEquals(true, result.isSuccessful());
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testExecuteWithRegion() throws Throwable {
+    LuceneIndexInfo indexInfo = new LuceneIndexInfo(null, "/region1");
+    when(this.context.getArguments()).thenReturn(indexInfo);
+    LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
+    function = spy(function);
+    doReturn(this.cache).when(function).getCache();
+    doReturn(mock(XmlEntity.class)).when(function).getXmlEntity(any());
+    function.execute(this.context);
+    verify(this.service).destroyIndexes(eq("/region1"));
+    verify(this.service, never()).destroyIndex(any(), eq("/region1"));
+    ArgumentCaptor<CliFunctionResult> resultCaptor =
+        ArgumentCaptor.forClass(CliFunctionResult.class);
+    verify(resultSender).lastResult(resultCaptor.capture());
+    CliFunctionResult result = resultCaptor.getValue();
+    assertEquals(this.member, result.getMemberIdOrName());
+    assertEquals(true, result.isSuccessful());
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/11521a82/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
index 875422c..1a344db 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
@@ -17,10 +17,7 @@ package org.apache.geode.cache.lucene.internal.configuration;
 import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
 import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
 import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
 
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.lucene.LuceneIndex;
@@ -28,9 +25,14 @@ import org.apache.geode.cache.lucene.LuceneService;
 import org.apache.geode.cache.lucene.LuceneServiceProvider;
 import org.apache.geode.cache.lucene.internal.cli.LuceneCliStrings;
 import org.apache.geode.cache.lucene.internal.cli.LuceneIndexCommands;
+import org.apache.geode.cache.lucene.internal.xml.LuceneXmlConstants;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
+import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.management.internal.cli.CommandManager;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
@@ -231,6 +233,78 @@ public class LuceneClusterConfigurationDUnitTest {
     });
   }
 
+  @Test
+  public void verifyClusterConfigurationAfterDestroyIndex() throws Exception {
+    Member vm1 = startNodeUsingClusterConfiguration(1, false);
+
+    // Connect Gfsh to locator.
+    gfshConnector.connectAndVerify(locator);
+
+    // Create and add indexes
+    createAndAddIndexes();
+
+    // Destroy one index
+    destroyLuceneIndexUsingGfsh(INDEX_NAME + "0");
+
+    // Destroy other index
+    destroyLuceneIndexUsingGfsh(INDEX_NAME + "1");
+
+    // Verify cluster configuration no longer contains any indexes
+    locator.invoke(verifyClusterConfiguration(false));
+  }
+
+  @Test
+  public void verifyClusterConfigurationAfterDestroyIndexes() throws Exception {
+    Member vm1 = startNodeUsingClusterConfiguration(1, false);
+
+    // Connect Gfsh to locator.
+    gfshConnector.connectAndVerify(locator);
+
+    // Create and add indexes
+    createAndAddIndexes();
+
+    // Destroy all indexes
+    destroyLuceneIndexUsingGfsh(null);
+
+    // Verify cluster configuration no longer contains indexes
+    locator.invoke(verifyClusterConfiguration(false));
+  }
+
+  private void createAndAddIndexes() throws Exception {
+    // Create lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "0", false);
+
+    // Create another lucene index.
+    createLuceneIndexUsingGfsh(INDEX_NAME + "1", false);
+
+    // Create region
+    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
+
+    // Verify cluster configuration contains the indexes
+    locator.invoke(verifyClusterConfiguration(true));
+  }
+
+  private SerializableRunnableIF verifyClusterConfiguration(boolean verifyIndexesExist) {
+    return () -> {
+      InternalLocator internalLocator = LocatorServerStartupRule.locatorStarter.locator;
+      ClusterConfigurationService sc = internalLocator.getSharedConfiguration();
+      Configuration config = sc.getConfiguration(ClusterConfigurationService.CLUSTER_CONFIG);
+      String xmlContent = config.getCacheXmlContent();
+      String luceneIndex0Config = "<" + LuceneXmlConstants.PREFIX + ":" + LuceneXmlConstants.INDEX
+          + " xmlns:lucene=\"" + LuceneXmlConstants.NAMESPACE + "\" " + LuceneXmlConstants.NAME
+          + "=\"" + INDEX_NAME + "0" + "\">";
+      String luceneIndex1Config = "<" + LuceneXmlConstants.PREFIX + ":" + LuceneXmlConstants.INDEX
+          + " xmlns:lucene=\"" + LuceneXmlConstants.NAMESPACE + "\" " + LuceneXmlConstants.NAME
+          + "=\"" + INDEX_NAME + "1" + "\">";
+      if (verifyIndexesExist) {
+        assertTrue(xmlContent.contains(luceneIndex0Config));
+        assertTrue(xmlContent.contains(luceneIndex1Config));
+      } else {
+        assertFalse(xmlContent.contains(luceneIndex0Config));
+        assertFalse(xmlContent.contains(luceneIndex1Config));
+      }
+    };
+  }
 
   private Member startNodeUsingClusterConfiguration(int vmIndex, boolean addGroup)
       throws Exception {
@@ -242,10 +316,14 @@ public class LuceneClusterConfigurationDUnitTest {
   }
 
   private void createLuceneIndexUsingGfsh(boolean addGroup) throws Exception {
+    createLuceneIndexUsingGfsh(INDEX_NAME, addGroup);
+  }
+
+  private void createLuceneIndexUsingGfsh(String indexName, boolean addGroup) throws Exception {
     // Execute Gfsh command to create lucene index.
     CommandManager.getInstance().add(LuceneIndexCommands.class.newInstance());
     CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
-    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, indexName);
     csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
     if (addGroup) {
       csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__GROUP, groupName);
@@ -273,6 +351,17 @@ public class LuceneClusterConfigurationDUnitTest {
     gfshConnector.executeAndVerifyCommand(csb.toString());
   }
 
+  private void destroyLuceneIndexUsingGfsh(String indexName) throws Exception {
+    // Execute Gfsh command to destroy lucene index.
+    CommandManager.getInstance().add(LuceneIndexCommands.class.newInstance());
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_DESTROY_INDEX);
+    if (indexName != null) {
+      csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, indexName);
+    }
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    gfshConnector.executeAndVerifyCommand(csb.toString());
+  }
+
   private void createRegionUsingGfsh(String regionName, RegionShortcut regionShortCut, String group)
       throws Exception {
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);


[22/34] geode git commit: GEODE-2142: Adding JSON library from the https://github.com/tdunning/open-json project

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/JSONObjectTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONObjectTest.java b/geode-json/src/test/java/org/json/JSONObjectTest.java
new file mode 100755
index 0000000..393a2d0
--- /dev/null
+++ b/geode-json/src/test/java/org/json/JSONObjectTest.java
@@ -0,0 +1,1198 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import org.junit.Test;
+
+import java.beans.IntrospectionException;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Objects;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.*;
+
+/**
+ * This black box test was written without inspecting the non-free org.json sourcecode.
+ */
+public class JSONObjectTest {
+    @Test
+    public void testKeyset() throws Exception {
+        JSONObject x = new JSONObject("{'a':1, 'b':2, 'c':3}");
+        Set<String> k = new TreeSet<String>();
+        for (String kx : Arrays.asList("a", "b", "c")) {
+            k.add(kx);
+        }
+        assertEquals(x.keySet(), k);
+        x = new JSONObject("{}");
+        assertEquals(x.keySet().size(), 0);
+    }
+
+    @Test
+    public void testEmptyObject() throws JSONException {
+        JSONObject object = new JSONObject();
+        assertEquals(0, object.length());
+
+        // bogus (but documented) behaviour: returns null rather than the empty object!
+        assertNull(object.names());
+
+        // returns null rather than an empty array!
+        assertNull(object.toJSONArray(new JSONArray()));
+        assertEquals("{}", object.toString());
+        assertEquals("{}", object.toString(5));
+        try {
+            object.get("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getBoolean("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getDouble("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getInt("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getJSONArray("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getJSONObject("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getLong("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getString("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertFalse(object.has("foo"));
+        assertTrue(object.isNull("foo")); // isNull also means "is not present"
+        assertNull(object.opt("foo"));
+        assertEquals(false, object.optBoolean("foo"));
+        assertEquals(true, object.optBoolean("foo", true));
+        assertEquals(Double.NaN, object.optDouble("foo"), 0);
+        assertEquals(5.0, object.optDouble("foo", 5.0), 0);
+        assertEquals(0, object.optInt("foo"));
+        assertEquals(5, object.optInt("foo", 5));
+        assertEquals(null, object.optJSONArray("foo"));
+        assertEquals(null, object.optJSONObject("foo"));
+        assertEquals(0, object.optLong("foo"));
+        assertEquals(Long.MAX_VALUE - 1, object.optLong("foo", Long.MAX_VALUE - 1));
+        assertEquals("", object.optString("foo")); // empty string is default!
+        assertEquals("bar", object.optString("foo", "bar"));
+        assertNull(object.remove("foo"));
+    }
+
+    @Test
+    public void testEqualsAndHashCode() throws JSONException {
+        JSONObject a = new JSONObject();
+        JSONObject b = new JSONObject();
+
+        // JSON object doesn't override either equals or hashCode (!)
+        assertFalse(a.equals(b));
+        assertEquals(a.hashCode(), System.identityHashCode(a));
+    }
+
+    @Test
+    public void testGet() throws JSONException {
+        JSONObject object = new JSONObject();
+        Object value = new Object();
+        object.put("foo", value);
+        object.put("bar", new Object());
+        object.put("baz", new Object());
+        assertSame(value, object.get("foo"));
+        try {
+            object.get("FOO");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put(null, value);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.get(null);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testPut() throws JSONException {
+        JSONObject object = new JSONObject();
+        assertSame(object, object.put("foo", true));
+        object.put("foo", false);
+        assertEquals(false, object.get("foo"));
+
+        object.put("foo", 5.0d);
+        assertEquals(5.0d, object.get("foo"));
+        object.put("foo", 0);
+        assertEquals(0, object.get("foo"));
+        object.put("bar", Long.MAX_VALUE - 1);
+        assertEquals(Long.MAX_VALUE - 1, object.get("bar"));
+        object.put("baz", "x");
+        assertEquals("x", object.get("baz"));
+        object.put("bar", JSONObject.NULL);
+        assertSame(JSONObject.NULL, object.get("bar"));
+    }
+
+    @Test
+    public void testPutNullRemoves() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "bar");
+        object.put("foo", null);
+        assertEquals(0, object.length());
+        assertFalse(object.has("foo"));
+        try {
+            object.get("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testPutOpt() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "bar");
+        object.putOpt("foo", null);
+        assertEquals("bar", object.get("foo"));
+        object.putOpt(null, null);
+        assertEquals(1, object.length());
+        object.putOpt(null, "bar");
+        assertEquals(1, object.length());
+    }
+
+    @Test
+    public void testPutOptUnsupportedNumbers() throws JSONException {
+        JSONObject object = new JSONObject();
+        try {
+            object.putOpt("foo", Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.putOpt("foo", Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.putOpt("foo", Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testRemove() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "bar");
+        assertEquals(null, object.remove(null));
+        assertEquals(null, object.remove(""));
+        assertEquals(null, object.remove("bar"));
+        assertEquals("bar", object.remove("foo"));
+        assertEquals(null, object.remove("foo"));
+    }
+
+    @Test
+    public void testBooleans() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", true);
+        object.put("bar", false);
+        object.put("baz", "true");
+        object.put("quux", "false");
+        assertEquals(4, object.length());
+        assertEquals(true, object.getBoolean("foo"));
+        assertEquals(false, object.getBoolean("bar"));
+        assertEquals(true, object.getBoolean("baz"));
+        assertEquals(false, object.getBoolean("quux"));
+        assertFalse(object.isNull("foo"));
+        assertFalse(object.isNull("quux"));
+        assertTrue(object.has("foo"));
+        assertTrue(object.has("quux"));
+        assertFalse(object.has("missing"));
+        assertEquals(true, object.optBoolean("foo"));
+        assertEquals(false, object.optBoolean("bar"));
+        assertEquals(true, object.optBoolean("baz"));
+        assertEquals(false, object.optBoolean("quux"));
+        assertEquals(false, object.optBoolean("missing"));
+        assertEquals(true, object.optBoolean("foo", true));
+        assertEquals(false, object.optBoolean("bar", true));
+        assertEquals(true, object.optBoolean("baz", true));
+        assertEquals(false, object.optBoolean("quux", true));
+        assertEquals(true, object.optBoolean("missing", true));
+
+        object.put("foo", "truE");
+        object.put("bar", "FALSE");
+        assertEquals(true, object.getBoolean("foo"));
+        assertEquals(false, object.getBoolean("bar"));
+        assertEquals(true, object.optBoolean("foo"));
+        assertEquals(false, object.optBoolean("bar"));
+        assertEquals(true, object.optBoolean("foo", false));
+        assertEquals(false, object.optBoolean("bar", false));
+    }
+
+    // http://code.google.com/p/android/issues/detail?id=16411
+    @Test
+    public void testCoerceStringToBoolean() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "maybe");
+        try {
+            object.getBoolean("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals(false, object.optBoolean("foo"));
+        assertEquals(true, object.optBoolean("foo", true));
+    }
+
+    @Test
+    public void testNumbers() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", Double.MIN_VALUE);
+        object.put("bar", 9223372036854775806L);
+        object.put("baz", Double.MAX_VALUE);
+        object.put("quux", -0d);
+        assertEquals(4, object.length());
+
+        String toString = object.toString();
+        assertTrue(toString, toString.contains("\"foo\":4.9E-324"));
+        assertTrue(toString, toString.contains("\"bar\":9223372036854775806"));
+        assertTrue(toString, toString.contains("\"baz\":1.7976931348623157E308"));
+
+        // toString() and getString() return different values for -0d!
+        assertTrue(toString, toString.contains("\"quux\":-0}") // no trailing decimal point
+                || toString.contains("\"quux\":-0,"));
+
+        assertEquals(Double.MIN_VALUE, object.get("foo"));
+        assertEquals(9223372036854775806L, object.get("bar"));
+        assertEquals(Double.MAX_VALUE, object.get("baz"));
+        assertEquals(-0d, object.get("quux"));
+        assertEquals(Double.MIN_VALUE, object.getDouble("foo"), 0);
+        assertEquals(9.223372036854776E18, object.getDouble("bar"), 0);
+        assertEquals(Double.MAX_VALUE, object.getDouble("baz"), 0);
+        assertEquals(-0d, object.getDouble("quux"), 0);
+        assertEquals(0, object.getLong("foo"));
+        assertEquals(9223372036854775806L, object.getLong("bar"));
+        assertEquals(Long.MAX_VALUE, object.getLong("baz"));
+        assertEquals(0, object.getLong("quux"));
+        assertEquals(0, object.getInt("foo"));
+        assertEquals(-2, object.getInt("bar"));
+        assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
+        assertEquals(0, object.getInt("quux"));
+        assertEquals(Double.MIN_VALUE, object.opt("foo"));
+        assertEquals(9223372036854775806L, object.optLong("bar"));
+        assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
+        assertEquals(0, object.optInt("quux"));
+        assertEquals(Double.MIN_VALUE, object.opt("foo"));
+        assertEquals(9223372036854775806L, object.optLong("bar"));
+        assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
+        assertEquals(0, object.optInt("quux"));
+        assertEquals(Double.MIN_VALUE, object.optDouble("foo", 5.0d), 0);
+        assertEquals(9223372036854775806L, object.optLong("bar", 1L));
+        assertEquals(Long.MAX_VALUE, object.optLong("baz", 1L));
+        assertEquals(0, object.optInt("quux", -1));
+        assertEquals("4.9E-324", object.getString("foo"));
+        assertEquals("9223372036854775806", object.getString("bar"));
+        assertEquals("1.7976931348623157E308", object.getString("baz"));
+        assertEquals("-0.0", object.getString("quux"));
+    }
+
+    @Test
+    public void testFloats() throws JSONException {
+        JSONObject object = new JSONObject();
+        try {
+            object.put("foo", (Float) Float.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", (Float) Float.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", (Float) Float.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testOtherNumbers() throws JSONException {
+        Number nan = new Number() {
+            public int intValue() {
+                throw new UnsupportedOperationException();
+            }
+
+            public long longValue() {
+                throw new UnsupportedOperationException();
+            }
+
+            public float floatValue() {
+                throw new UnsupportedOperationException();
+            }
+
+            public double doubleValue() {
+                return Double.NaN;
+            }
+
+            @Override
+            public String toString() {
+                return "x";
+            }
+        };
+
+        JSONObject object = new JSONObject();
+        try {
+            object.put("foo", nan);
+            fail("Object.put() accepted a NaN (via a custom Number class)");
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testForeignObjects() throws JSONException {
+        Object foreign = new Object() {
+            @Override
+            public String toString() {
+                return "x";
+            }
+        };
+
+        // foreign object types are accepted and treated as Strings!
+        JSONObject object = new JSONObject();
+        object.put("foo", foreign);
+        assertEquals("{\"foo\":\"x\"}", object.toString());
+    }
+
+    @Test
+    public void testNullKeys() {
+        try {
+            new JSONObject().put(null, false);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONObject().put(null, 0.0d);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONObject().put(null, 5);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONObject().put(null, 5L);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONObject().put(null, "foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testStrings() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "true");
+        object.put("bar", "5.5");
+        object.put("baz", "9223372036854775806");
+        object.put("quux", "null");
+        object.put("height", "5\"8' tall");
+
+        assertTrue(object.toString().contains("\"foo\":\"true\""));
+        assertTrue(object.toString().contains("\"bar\":\"5.5\""));
+        assertTrue(object.toString().contains("\"baz\":\"9223372036854775806\""));
+        assertTrue(object.toString().contains("\"quux\":\"null\""));
+        assertTrue(object.toString().contains("\"height\":\"5\\\"8' tall\""));
+
+        assertEquals("true", object.get("foo"));
+        assertEquals("null", object.getString("quux"));
+        assertEquals("5\"8' tall", object.getString("height"));
+        assertEquals("true", object.opt("foo"));
+        assertEquals("5.5", object.optString("bar"));
+        assertEquals("true", object.optString("foo", "x"));
+        assertFalse(object.isNull("foo"));
+
+        assertEquals(true, object.getBoolean("foo"));
+        assertEquals(true, object.optBoolean("foo"));
+        assertEquals(true, object.optBoolean("foo", false));
+        assertEquals(0, object.optInt("foo"));
+        assertEquals(-2, object.optInt("foo", -2));
+
+        assertEquals(5.5d, object.getDouble("bar"), 0);
+        assertEquals(5L, object.getLong("bar"));
+        assertEquals(5, object.getInt("bar"));
+        assertEquals(5, object.optInt("bar", 3));
+
+        // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
+        // double and then converting that to a long. This is consistent with JavaScript.
+        assertEquals(9223372036854775807L, object.getLong("baz"));
+        assertEquals(9.223372036854776E18, object.getDouble("baz"), 0);
+        assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
+
+        assertFalse(object.isNull("quux"));
+        try {
+            object.getDouble("quux");
+            fail();
+        } catch (JSONException e) {
+            // expected
+        }
+        assertEquals(Double.NaN, object.optDouble("quux"), 0);
+        assertEquals(-1.0d, object.optDouble("quux", -1.0d), 0);
+
+        object.put("foo", "TRUE");
+        assertEquals(true, object.getBoolean("foo"));
+    }
+
+    @Test
+    public void testJSONObjects() throws JSONException {
+        JSONObject object = new JSONObject();
+
+        JSONArray a = new JSONArray();
+        JSONObject b = new JSONObject();
+        object.put("foo", a);
+        object.put("bar", b);
+
+        assertSame(a, object.getJSONArray("foo"));
+        assertSame(b, object.getJSONObject("bar"));
+        try {
+            object.getJSONObject("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.getJSONArray("bar");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals(a, object.optJSONArray("foo"));
+        assertEquals(b, object.optJSONObject("bar"));
+        assertEquals(null, object.optJSONArray("bar"));
+        assertEquals(null, object.optJSONObject("foo"));
+    }
+
+    @Test
+    public void testNullCoercionToString() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", JSONObject.NULL);
+        assertEquals("null", object.getString("foo"));
+    }
+
+    @Test
+    public void testArrayCoercion() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "[true]");
+        try {
+            object.getJSONArray("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testObjectCoercion() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "{}");
+        try {
+            object.getJSONObject("foo");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testAccumulateValueChecking() throws JSONException {
+        JSONObject object = new JSONObject();
+        try {
+            object.accumulate("foo", Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        object.accumulate("foo", 1);
+        try {
+            object.accumulate("foo", Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        object.accumulate("foo", 2);
+        try {
+            object.accumulate("foo", Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testToJSONArray() throws JSONException {
+        JSONObject object = new JSONObject();
+        Object value = new Object();
+        object.put("foo", true);
+        object.put("bar", 5.0d);
+        object.put("baz", -0.0d);
+        object.put("quux", value);
+
+        JSONArray names = new JSONArray();
+        names.put("baz");
+        names.put("quux");
+        names.put("foo");
+
+        JSONArray array = object.toJSONArray(names);
+        assertEquals(-0.0d, array.get(0));
+        assertEquals(value, array.get(1));
+        assertEquals(true, array.get(2));
+
+        object.put("foo", false);
+        assertEquals(true, array.get(2));
+    }
+
+    @Test
+    public void testToJSONArrayMissingNames() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", true);
+        object.put("bar", 5.0d);
+        object.put("baz", JSONObject.NULL);
+
+        JSONArray names = new JSONArray();
+        names.put("bar");
+        names.put("foo");
+        names.put("quux");
+        names.put("baz");
+
+        JSONArray array = object.toJSONArray(names);
+        assertEquals(4, array.length());
+
+        assertEquals(5.0d, array.get(0));
+        assertEquals(true, array.get(1));
+        try {
+            array.get(2);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals(JSONObject.NULL, array.get(3));
+    }
+
+    @Test
+    public void testToJSONArrayNull() throws JSONException {
+        JSONObject object = new JSONObject();
+        assertEquals(null, object.toJSONArray(null));
+        object.put("foo", 5);
+        try {
+            object.toJSONArray(null);
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testToJSONArrayEndsUpEmpty() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        JSONArray array = new JSONArray();
+        array.put("bar");
+        assertEquals(1, object.toJSONArray(array).length());
+    }
+
+    @Test
+    public void testToJSONArrayNonString() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        object.put("null", 10);
+        object.put("false", 15);
+
+        JSONArray names = new JSONArray();
+        names.put(JSONObject.NULL);
+        names.put(false);
+        names.put("foo");
+
+        // array elements are converted to strings to do name lookups on the map!
+        JSONArray array = object.toJSONArray(names);
+        assertEquals(3, array.length());
+        assertEquals(10, array.get(0));
+        assertEquals(15, array.get(1));
+        assertEquals(5, array.get(2));
+    }
+
+    @Test
+    public void testPutUnsupportedNumbers() throws JSONException {
+        JSONObject object = new JSONObject();
+        try {
+            object.put("foo", Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testPutUnsupportedNumbersAsObjects() throws JSONException {
+        JSONObject object = new JSONObject();
+        try {
+            object.put("foo", (Double) Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", (Double) Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            object.put("foo", (Double) Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    /**
+     * Although JSONObject is usually defensive about which numbers it accepts,
+     * it doesn't check inputs in its constructor.
+     */
+    @Test
+    public void testCreateWithUnsupportedNumbers() throws JSONException {
+        Map<String, Object> contents = new HashMap<String, Object>();
+        contents.put("foo", Double.NaN);
+        contents.put("bar", Double.NEGATIVE_INFINITY);
+        contents.put("baz", Double.POSITIVE_INFINITY);
+
+        JSONObject object = new JSONObject(contents);
+        assertEquals(Double.NaN, object.get("foo"));
+        assertEquals(Double.NEGATIVE_INFINITY, object.get("bar"));
+        assertEquals(Double.POSITIVE_INFINITY, object.get("baz"));
+    }
+
+    @Test
+    public void testToStringWithUnsupportedNumbers() {
+        // when the object contains an unsupported number, toString returns null!
+        JSONObject object = new JSONObject(Collections.singletonMap("foo", Double.NaN));
+        assertEquals(null, object.toString());
+    }
+
+    @Test
+    public void testMapConstructorCopiesContents() throws JSONException {
+        Map<String, Object> contents = new HashMap<String, Object>();
+        contents.put("foo", 5);
+        JSONObject object = new JSONObject(contents);
+        contents.put("foo", 10);
+        assertEquals(5, object.get("foo"));
+    }
+
+    @Test
+    public void testMapConstructorWithBogusEntries() {
+        Map<Object, Object> contents = new HashMap<Object, Object>();
+        contents.put(5, 5);
+
+        try {
+            new JSONObject(contents);
+            fail("JSONObject constructor doesn't validate its input!");
+        } catch (Exception ignored) {
+        }
+    }
+
+    @Test
+    public void testTokenerConstructor() throws JSONException {
+        JSONObject object = new JSONObject(new JSONTokener("{\"foo\": false}"));
+        assertEquals(1, object.length());
+        assertEquals(false, object.get("foo"));
+    }
+
+    @Test
+    public void testTokenerConstructorWrongType() throws JSONException {
+        try {
+            new JSONObject(new JSONTokener("[\"foo\", false]"));
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testTokenerConstructorNull() throws JSONException {
+        try {
+            new JSONObject((JSONTokener) null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    @Test
+    public void testTokenerConstructorParseFail() {
+        try {
+            new JSONObject(new JSONTokener("{"));
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testStringConstructor() throws JSONException {
+        JSONObject object = new JSONObject("{\"foo\": false}");
+        assertEquals(1, object.length());
+        assertEquals(false, object.get("foo"));
+    }
+
+    @Test
+    public void testStringConstructorWrongType() throws JSONException {
+        try {
+            new JSONObject("[\"foo\", false]");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testStringConstructorNull() throws JSONException {
+        try {
+            new JSONObject((String) null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    @Test
+    public void testStringConstructorParseFail() {
+        try {
+            new JSONObject("{");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testCopyConstructor() throws JSONException {
+        JSONObject source = new JSONObject();
+        source.put("a", JSONObject.NULL);
+        source.put("b", false);
+        source.put("c", 5);
+
+        JSONObject copy = new JSONObject(source, new String[]{"a", "c"});
+        assertEquals(2, copy.length());
+        assertEquals(JSONObject.NULL, copy.get("a"));
+        assertEquals(5, copy.get("c"));
+        assertEquals(null, copy.opt("b"));
+    }
+
+    @Test
+    public void testCopyConstructorMissingName() throws JSONException {
+        JSONObject source = new JSONObject();
+        source.put("a", JSONObject.NULL);
+        source.put("b", false);
+        source.put("c", 5);
+
+        JSONObject copy = new JSONObject(source, new String[]{"a", "c", "d"});
+        assertEquals(2, copy.length());
+        assertEquals(JSONObject.NULL, copy.get("a"));
+        assertEquals(5, copy.get("c"));
+        assertEquals(0, copy.optInt("b"));
+    }
+
+    @Test
+    public void testAccumulateMutatesInPlace() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        object.accumulate("foo", 6);
+        JSONArray array = object.getJSONArray("foo");
+        assertEquals("[5,6]", array.toString());
+        object.accumulate("foo", 7);
+        assertEquals("[5,6,7]", array.toString());
+    }
+
+    @Test
+    public void testAccumulateExistingArray() throws JSONException {
+        JSONArray array = new JSONArray();
+        JSONObject object = new JSONObject();
+        object.put("foo", array);
+        object.accumulate("foo", 5);
+        assertEquals("[5]", array.toString());
+    }
+
+    @Test
+    public void testAccumulatePutArray() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.accumulate("foo", 5);
+        assertEquals("{\"foo\":5}", object.toString());
+        object.accumulate("foo", new JSONArray());
+        assertEquals("{\"foo\":[5,[]]}", object.toString());
+    }
+
+    @Test
+    public void testAccumulateNull() {
+        JSONObject object = new JSONObject();
+        try {
+            object.accumulate(null, 5);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testEmptyStringKey() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("", 5);
+        assertEquals(5, object.get(""));
+        assertEquals("{\"\":5}", object.toString());
+    }
+
+    @Test
+    public void testNullValue() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", JSONObject.NULL);
+        object.put("bar", null);
+
+        // there are two ways to represent null; each behaves differently!
+        assertTrue(object.has("foo"));
+        assertFalse(object.has("bar"));
+        assertTrue(object.isNull("foo"));
+        assertTrue(object.isNull("bar"));
+    }
+
+    @Test
+    public void testNullValue_equalsAndHashCode() {
+        //noinspection ObjectEqualsNull
+        assertTrue(JSONObject.NULL.equals(null)); // guaranteed by javadoc
+        // not guaranteed by javadoc, but seems like a good idea
+        assertEquals(Objects.hashCode(null), JSONObject.NULL.hashCode());
+    }
+
+    @Test
+    public void testHas() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        assertTrue(object.has("foo"));
+        assertFalse(object.has("bar"));
+        assertFalse(object.has(null));
+    }
+
+    @Test
+    public void testOptNull() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", "bar");
+        assertEquals(null, object.opt(null));
+        assertEquals(false, object.optBoolean(null));
+        assertEquals(Double.NaN, object.optDouble(null), 0);
+        assertEquals(0, object.optInt(null));
+        assertEquals(0L, object.optLong(null));
+        assertEquals(null, object.optJSONArray(null));
+        assertEquals(null, object.optJSONObject(null));
+        assertEquals("", object.optString(null));
+        assertEquals(true, object.optBoolean(null, true));
+        assertEquals(0.0d, object.optDouble(null, 0.0d), 0);
+        assertEquals(1, object.optInt(null, 1));
+        assertEquals(1L, object.optLong(null, 1L));
+        assertEquals("baz", object.optString(null, "baz"));
+    }
+
+    @Test
+    public void testToStringWithIndentFactor() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", new JSONArray(Arrays.asList(5, 6)));
+        object.put("bar", new JSONObject());
+        String foobar = "{\n" +
+                "     \"foo\": [\n" +
+                "          5,\n" +
+                "          6\n" +
+                "     ],\n" +
+                "     \"bar\": {}\n" +
+                "}";
+        String barfoo = "{\n" +
+                "     \"bar\": {},\n" +
+                "     \"foo\": [\n" +
+                "          5,\n" +
+                "          6\n" +
+                "     ]\n" +
+                "}";
+        String string = object.toString(5);
+        assertTrue(string, foobar.equals(string) || barfoo.equals(string));
+    }
+
+    @Test
+    public void testNames() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        object.put("bar", 6);
+        object.put("baz", 7);
+        JSONArray array = object.names();
+        assertTrue(array.toString().contains("foo"));
+        assertTrue(array.toString().contains("bar"));
+        assertTrue(array.toString().contains("baz"));
+    }
+
+    @Test
+    public void testKeysEmptyObject() {
+        JSONObject object = new JSONObject();
+        assertFalse(object.keys().hasNext());
+        try {
+            object.keys().next();
+            fail();
+        } catch (NoSuchElementException ignored) {
+        }
+    }
+
+    @Test
+    public void testKeys() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        object.put("bar", 6);
+        object.put("foo", 7);
+
+        @SuppressWarnings("unchecked")
+        Iterator<String> keys = object.keys();
+        Set<String> result = new HashSet<String>();
+        assertTrue(keys.hasNext());
+        result.add(keys.next());
+        assertTrue(keys.hasNext());
+        result.add(keys.next());
+        assertFalse(keys.hasNext());
+        assertEquals(new HashSet<String>(Arrays.asList("foo", "bar")), result);
+
+        try {
+            keys.next();
+            fail();
+        } catch (NoSuchElementException ignored) {
+        }
+    }
+
+    @Test
+    public void testMutatingKeysMutatesObject() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        Iterator keys = object.keys();
+        keys.next();
+        keys.remove();
+        assertEquals(0, object.length());
+    }
+
+    @Test
+    public void testQuote() {
+        // covered by JSONStringerTest.testEscaping
+    }
+
+    @Test
+    public void testQuoteNull() throws JSONException {
+        assertEquals("\"\"", JSONObject.quote(null));
+    }
+
+    @Test
+    public void testNumberToString() throws JSONException {
+        assertEquals("5", JSONObject.numberToString(5));
+        assertEquals("-0", JSONObject.numberToString(-0.0d));
+        assertEquals("9223372036854775806", JSONObject.numberToString(9223372036854775806L));
+        assertEquals("4.9E-324", JSONObject.numberToString(Double.MIN_VALUE));
+        assertEquals("1.7976931348623157E308", JSONObject.numberToString(Double.MAX_VALUE));
+        try {
+            JSONObject.numberToString(Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            JSONObject.numberToString(Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            JSONObject.numberToString(Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals("0.001", JSONObject.numberToString(new BigDecimal("0.001")));
+        assertEquals("9223372036854775806",
+                JSONObject.numberToString(new BigInteger("9223372036854775806")));
+        try {
+            JSONObject.numberToString(null);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void test_wrap() throws Exception {
+        assertEquals(JSONObject.NULL, JSONObject.wrap(null));
+
+        JSONArray a = new JSONArray();
+        assertEquals(a, JSONObject.wrap(a));
+
+        JSONObject o = new JSONObject();
+        assertEquals(o, JSONObject.wrap(o));
+
+        assertEquals(JSONObject.NULL, JSONObject.wrap(JSONObject.NULL));
+
+        assertTrue(JSONObject.wrap(new byte[0]) instanceof JSONArray);
+        assertTrue(JSONObject.wrap(new ArrayList<String>()) instanceof JSONArray);
+        assertTrue(JSONObject.wrap(new HashMap<String, String>()) instanceof JSONObject);
+        assertTrue(JSONObject.wrap(0.0) instanceof Double);
+        assertTrue(JSONObject.wrap("hello") instanceof String);
+    }
+
+    // https://code.google.com/p/android/issues/detail?id=55114
+    @Test
+    public void test_toString_listAsMapValue() throws Exception {
+        ArrayList<Object> list = new ArrayList<Object>();
+        list.add("a");
+        list.add(new ArrayList<String>());
+        Map<String, Object> map = new TreeMap<String, Object>();
+        map.put("x", "l");
+        map.put("y", list);
+        assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
+    }
+
+    @Test
+    public void testAppendExistingInvalidKey() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("foo", 5);
+        try {
+            object.append("foo", 6);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testAppendExistingArray() throws JSONException {
+        JSONArray array = new JSONArray();
+        JSONObject object = new JSONObject();
+        object.put("foo", array);
+        object.append("foo", 5);
+        assertEquals("[5]", array.toString());
+    }
+
+    @Test
+    public void testAppendPutArray() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.append("foo", 5);
+        assertEquals("{\"foo\":[5]}", object.toString());
+        object.append("foo", new JSONArray());
+        assertEquals("{\"foo\":[5,[]]}", object.toString());
+    }
+
+    @Test
+    public void testAppendNull() {
+        JSONObject object = new JSONObject();
+        try {
+            object.append(null, 5);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    // https://code.google.com/p/android/issues/detail?id=103641
+    @Test
+    public void testInvalidUnicodeEscape() {
+        try {
+            new JSONObject("{\"q\":\"\\u\", \"r\":[]}");
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testBeanThings() throws IllegalAccessException, IntrospectionException, InvocationTargetException {
+        Foo f = new Foo();
+        assertEquals("{\"a\":1,\"b\":1,\"c\":\"c\",\"d\":[{\"e\":\"echo\"}]}", new JSONObject(f).toString());
+    }
+
+    @Test
+    public void testGetNames() throws Exception {
+        assertArrayEquals(new String[]{"a", "b", "c", "d"}, JSONObject.getNames(new JSONObject(new Foo())));
+    }
+
+    private static class Foo {
+        public double getA() {
+            return 1.0;
+        }
+
+        public int getB() {
+            return 1;
+        }
+
+        public String getC() {
+            return "c";
+        }
+
+        public List<Bar> getD() {
+            ArrayList<Bar> r = new ArrayList<Bar>();
+            r.add(new Bar());
+            return r;
+        }
+    }
+
+    private static class Bar {
+        public String getE() {
+            return "echo";
+        }
+    }
+
+    @Test
+    public void testEnumWrapper() throws Exception {
+        Object y = JSONObject.wrap(E.A);
+        assertEquals("A", y);
+        assertTrue(y instanceof String);
+    }
+
+    enum E {
+        A {
+            int key() {
+                return 1;
+            }
+        }, B {
+            int key() {
+                return 2;
+            }
+        };
+        int key() {
+            return -1;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/JSONStringerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONStringerTest.java b/geode-json/src/test/java/org/json/JSONStringerTest.java
new file mode 100755
index 0000000..7c7362d
--- /dev/null
+++ b/geode-json/src/test/java/org/json/JSONStringerTest.java
@@ -0,0 +1,421 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.*;
+
+/**
+ * This black box test was written without inspecting the non-free org.json sourcecode.
+ */
+public class JSONStringerTest {
+
+    @Test
+    public void testJSONFunctionHackTest() {
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.key("key");
+        stringer.value(new JSONFunctionTestObject("window.test('foo' + \"bar\")"));
+        stringer.endObject();
+        assertEquals("{\"key\":window.test('foo' + \"bar\")}", stringer.toString());
+    }
+
+    @Test
+    public void testEmptyStringer() {
+        // why isn't this the empty string?
+        assertNull(new JSONStringer().toString());
+    }
+
+    @Test
+    public void testValueJSONNull() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(JSONObject.NULL);
+        stringer.endArray();
+        assertEquals("[null]", stringer.toString());
+    }
+
+    @Test
+    public void testEmptyObject() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.endObject();
+        assertEquals("{}", stringer.toString());
+    }
+
+    @Test
+    public void testEmptyArray() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.endArray();
+        assertEquals("[]", stringer.toString());
+    }
+
+    @Test
+    public void testArray() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(false);
+        stringer.value(5.0);
+        stringer.value(5L);
+        stringer.value("five");
+        stringer.value(null);
+        stringer.endArray();
+        assertEquals("[false,5,5,\"five\",null]", stringer.toString());
+    }
+
+    @Test
+    public void testValueObjectMethods() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(Boolean.FALSE);
+        stringer.value(Double.valueOf(5.0));
+        stringer.value(Long.valueOf(5L));
+        stringer.endArray();
+        assertEquals("[false,5,5]", stringer.toString());
+    }
+
+    @Test
+    public void testKeyValue() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.key("a").value(false);
+        stringer.key("b").value(5.0);
+        stringer.key("c").value(5L);
+        stringer.key("d").value("five");
+        stringer.key("e").value(null);
+        stringer.endObject();
+        assertEquals("{\"a\":false," +
+                "\"b\":5," +
+                "\"c\":5," +
+                "\"d\":\"five\"," +
+                "\"e\":null}", stringer.toString());
+    }
+
+    /**
+     * Test what happens when extreme values are emitted. Such values are likely
+     * to be rounded during parsing.
+     */
+    @Test
+    public void testNumericRepresentations() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(Long.MAX_VALUE);
+        stringer.value(Double.MIN_VALUE);
+        stringer.endArray();
+        assertEquals("[9223372036854775807,4.9E-324]", stringer.toString());
+    }
+
+    @Test
+    public void testWeirdNumbers() throws JSONException {
+        try {
+            new JSONStringer().array().value(Double.NaN);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().array().value(Double.NEGATIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().array().value(Double.POSITIVE_INFINITY);
+            fail();
+        } catch (JSONException ignored) {
+        }
+
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(-0.0d);
+        stringer.value(0.0d);
+        stringer.endArray();
+        assertEquals("[-0,0]", stringer.toString());
+    }
+
+    @Test
+    public void testMismatchedScopes() {
+        try {
+            new JSONStringer().key("a");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().value("a");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().endObject();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().endArray();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().array().endObject();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().object().endArray();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().object().key("a").key("a");
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONStringer().object().value(false);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testNullKey() {
+        try {
+            new JSONStringer().object().key(null);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testRepeatedKey() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.key("a").value(true);
+        stringer.key("a").value(false);
+        stringer.endObject();
+        // JSONStringer doesn't attempt to detect duplicates
+        assertEquals("{\"a\":true,\"a\":false}", stringer.toString());
+    }
+
+    @Test
+    public void testEmptyKey() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.key("").value(false);
+        stringer.endObject();
+        assertEquals("{\"\":false}", stringer.toString()); // legit behaviour!
+    }
+
+    @Test
+    public void testEscaping() throws JSONException {
+        assertEscapedAllWays("a", "a");
+        assertEscapedAllWays("a\\\"", "a\"");
+        assertEscapedAllWays("\\\"", "\"");
+        assertEscapedAllWays(":", ":");
+        assertEscapedAllWays(",", ",");
+        assertEscapedAllWays("\\b", "\b");
+        assertEscapedAllWays("\\f", "\f");
+        assertEscapedAllWays("\\n", "\n");
+        assertEscapedAllWays("\\r", "\r");
+        assertEscapedAllWays("\\t", "\t");
+        assertEscapedAllWays(" ", " ");
+        assertEscapedAllWays("\\\\", "\\");
+        assertEscapedAllWays("{", "{");
+        assertEscapedAllWays("}", "}");
+        assertEscapedAllWays("[", "[");
+        assertEscapedAllWays("]", "]");
+        assertEscapedAllWays("\\u0000", "\0");
+        assertEscapedAllWays("\\u0019", "\u0019");
+        assertEscapedAllWays(" ", "\u0020");
+        assertEscapedAllWays("<\\/foo>", "</foo>");
+    }
+
+    private void assertEscapedAllWays(String escaped, String original) throws JSONException {
+        assertEquals("{\"" + escaped + "\":false}",
+                new JSONStringer().object().key(original).value(false).endObject().toString());
+        assertEquals("{\"a\":\"" + escaped + "\"}",
+                new JSONStringer().object().key("a").value(original).endObject().toString());
+        assertEquals("[\"" + escaped + "\"]",
+                new JSONStringer().array().value(original).endArray().toString());
+        assertEquals("\"" + escaped + "\"", JSONObject.quote(original));
+    }
+
+    @Test
+    public void testJSONArrayAsValue() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(false);
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.value(array);
+        stringer.endArray();
+        assertEquals("[[false]]", stringer.toString());
+    }
+
+    @Test
+    public void testJSONObjectAsValue() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("a", false);
+        JSONStringer stringer = new JSONStringer();
+        stringer.object();
+        stringer.key("b").value(object);
+        stringer.endObject();
+        assertEquals("{\"b\":{\"a\":false}}", stringer.toString());
+    }
+
+    @Test
+    public void testArrayNestingMaxDepthSupports20() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.array();
+        }
+        for (int i = 0; i < 20; i++) {
+            stringer.endArray();
+        }
+        assertEquals("[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]", stringer.toString());
+
+        stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.array();
+        }
+    }
+
+    @Test
+    public void testObjectNestingMaxDepthSupports20() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.object();
+            stringer.key("a");
+        }
+        stringer.value(false);
+        for (int i = 0; i < 20; i++) {
+            stringer.endObject();
+        }
+        assertEquals("{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":" +
+                "{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":{\"a\":false" +
+                "}}}}}}}}}}}}}}}}}}}}", stringer.toString());
+
+        stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.object();
+            stringer.key("a");
+        }
+    }
+
+    @Test
+    public void testMixedMaxDepthSupports20() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        for (int i = 0; i < 20; i += 2) {
+            stringer.array();
+            stringer.object();
+            stringer.key("a");
+        }
+        stringer.value(false);
+        for (int i = 0; i < 20; i += 2) {
+            stringer.endObject();
+            stringer.endArray();
+        }
+        assertEquals("[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":" +
+                "[{\"a\":[{\"a\":[{\"a\":[{\"a\":[{\"a\":false" +
+                "}]}]}]}]}]}]}]}]}]}]", stringer.toString());
+
+        stringer = new JSONStringer();
+        for (int i = 0; i < 20; i += 2) {
+            stringer.array();
+            stringer.object();
+            stringer.key("a");
+        }
+    }
+
+    @Test
+    public void testMaxDepthWithArrayValue() throws JSONException {
+        JSONArray array = new JSONArray();
+        array.put(false);
+
+        JSONStringer stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.array();
+        }
+        stringer.value(array);
+        for (int i = 0; i < 20; i++) {
+            stringer.endArray();
+        }
+        assertEquals("[[[[[[[[[[[[[[[[[[[[[false]]]]]]]]]]]]]]]]]]]]]", stringer.toString());
+    }
+
+    @Test
+    public void testMaxDepthWithObjectValue() throws JSONException {
+        JSONObject object = new JSONObject();
+        object.put("a", false);
+        JSONStringer stringer = new JSONStringer();
+        for (int i = 0; i < 20; i++) {
+            stringer.object();
+            stringer.key("b");
+        }
+        stringer.value(object);
+        for (int i = 0; i < 20; i++) {
+            stringer.endObject();
+        }
+        assertEquals("{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":" +
+                "{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":{\"b\":" +
+                "{\"a\":false}}}}}}}}}}}}}}}}}}}}}", stringer.toString());
+    }
+
+    @Test
+    public void testMultipleRoots() throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.array();
+        stringer.endArray();
+        try {
+            stringer.object();
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    @Test
+    public void testEnums() {
+        JSONObject x = new JSONObject();
+        x.put("a", TimeUnit.SECONDS);
+        x.put("b", "xyx");
+        JSONStringer s = new JSONStringer();
+        s.array();
+        s.value(x);
+        s.endArray();
+        assertEquals("[{\"a\":\"SECONDS\",\"b\":\"xyx\"}]", s.toString());
+    }
+
+    @Test
+    public void testJsonString() {
+        JSONObject x = new JSONObject();
+        x.put("a", new Goo());
+        JSONStringer s = new JSONStringer();
+        s.array();
+        s.value(x);
+        s.endArray();
+        // note lack of quotes
+        assertEquals("[{\"a\":fffooo}]", s.toString());
+    }
+
+    private static class Goo implements JSONString {
+        @Override
+        public String toJSONString() {
+            return "fffooo";
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/test/java/org/json/JSONTokenerTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONTokenerTest.java b/geode-json/src/test/java/org/json/JSONTokenerTest.java
new file mode 100755
index 0000000..9975177
--- /dev/null
+++ b/geode-json/src/test/java/org/json/JSONTokenerTest.java
@@ -0,0 +1,621 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+/**
+ * This black box test was written without inspecting the non-free org.json sourcecode.
+ */
+public class JSONTokenerTest extends TestCase {
+
+    public void testNulls() throws JSONException {
+        // JSONTokener accepts null, only to fail later on almost all APIs!
+        new JSONTokener((String) null).back();
+
+        try {
+            new JSONTokener((String) null).more();
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).next();
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).next(3);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).next('A');
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).nextClean();
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).nextString('"');
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).nextTo('A');
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).nextTo("ABC");
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).nextValue();
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).skipPast("ABC");
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        try {
+            new JSONTokener((String) null).skipTo('A');
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+
+        //noinspection ThrowableResultOfMethodCallIgnored
+        assertEquals("foo! at character 0 of null",
+                new JSONTokener((String) null).syntaxError("foo!").getMessage());
+
+        assertEquals(" at character 0 of null", new JSONTokener((String) null).toString());
+    }
+
+    public void testEmptyString() throws JSONException {
+        JSONTokener backTokener = new JSONTokener("");
+        backTokener.back();
+        assertEquals(" at character 0 of ", backTokener.toString());
+        assertFalse(new JSONTokener("").more());
+        assertEquals('\0', new JSONTokener("").next());
+        try {
+            new JSONTokener("").next(3);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONTokener("").next('A');
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals('\0', new JSONTokener("").nextClean());
+        try {
+            new JSONTokener("").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals("", new JSONTokener("").nextTo('A'));
+        assertEquals("", new JSONTokener("").nextTo("ABC"));
+        try {
+            new JSONTokener("").nextValue();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        new JSONTokener("").skipPast("ABC");
+        assertEquals('\0', new JSONTokener("").skipTo('A'));
+        //noinspection ThrowableResultOfMethodCallIgnored
+        assertEquals("foo! at character 0 of ",
+                new JSONTokener("").syntaxError("foo!").getMessage());
+        assertEquals(" at character 0 of ", new JSONTokener("").toString());
+    }
+
+    public void testCharacterNavigation() throws JSONException {
+        JSONTokener abcdeTokener = new JSONTokener("ABCDE");
+        assertEquals('A', abcdeTokener.next());
+        assertEquals('B', abcdeTokener.next('B'));
+        assertEquals("CD", abcdeTokener.next(2));
+        try {
+            abcdeTokener.next(2);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals('E', abcdeTokener.nextClean());
+        assertEquals('\0', abcdeTokener.next());
+        assertFalse(abcdeTokener.more());
+        abcdeTokener.back();
+        assertTrue(abcdeTokener.more());
+        assertEquals('E', abcdeTokener.next());
+    }
+
+    public void testBackNextAndMore() throws JSONException {
+        JSONTokener abcTokener = new JSONTokener("ABC");
+        assertTrue(abcTokener.more());
+        abcTokener.next();
+        abcTokener.next();
+        assertTrue(abcTokener.more());
+        abcTokener.next();
+        assertFalse(abcTokener.more());
+        abcTokener.back();
+        assertTrue(abcTokener.more());
+        abcTokener.next();
+        assertFalse(abcTokener.more());
+        abcTokener.back();
+        abcTokener.back();
+        abcTokener.back();
+        abcTokener.back(); // you can back up before the beginning of a String!
+        assertEquals('A', abcTokener.next());
+    }
+
+    public void testNextMatching() throws JSONException {
+        JSONTokener abcdTokener = new JSONTokener("ABCD");
+        assertEquals('A', abcdTokener.next('A'));
+        try {
+            abcdTokener.next('C'); // although it failed, this op consumes a character of input
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals('C', abcdTokener.next('C'));
+        assertEquals('D', abcdTokener.next('D'));
+        try {
+            abcdTokener.next('E');
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    public void testNextN() throws JSONException {
+        JSONTokener abcdeTokener = new JSONTokener("ABCDEF");
+        assertEquals("", abcdeTokener.next(0));
+        try {
+            abcdeTokener.next(7);
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals("ABC", abcdeTokener.next(3));
+        try {
+            abcdeTokener.next(4);
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    public void testNextNWithAllRemaining() throws JSONException {
+        JSONTokener tokener = new JSONTokener("ABCDEF");
+        tokener.next(3);
+        try {
+            tokener.next(3);
+        } catch (JSONException e) {
+            AssertionFailedError error = new AssertionFailedError("off-by-one error?");
+            error.initCause(e);
+            throw error;
+        }
+    }
+
+    public void testNext0() throws JSONException {
+        JSONTokener tokener = new JSONTokener("ABCDEF");
+        tokener.next(5);
+        tokener.next();
+        try {
+            tokener.next(0);
+        } catch (JSONException e) {
+            Error error = new AssertionFailedError("Returning an empty string should be valid");
+            error.initCause(e);
+            throw error;
+        }
+    }
+
+    public void testNextCleanComments() throws JSONException {
+        JSONTokener tokener = new JSONTokener(
+                "  A  /*XX*/B/*XX//XX\n//XX\nXX*/C//X//X//X\nD/*X*///X\n");
+        assertEquals('A', tokener.nextClean());
+        assertEquals('B', tokener.nextClean());
+        assertEquals('C', tokener.nextClean());
+        assertEquals('D', tokener.nextClean());
+        assertEquals('\0', tokener.nextClean());
+    }
+
+    public void testNextCleanNestedCStyleComments() throws JSONException {
+        JSONTokener tokener = new JSONTokener("A /* B /* C */ D */ E");
+        assertEquals('A', tokener.nextClean());
+        assertEquals('D', tokener.nextClean());
+        assertEquals('*', tokener.nextClean());
+        assertEquals('/', tokener.nextClean());
+        assertEquals('E', tokener.nextClean());
+    }
+
+    /**
+     * Some applications rely on parsing '#' to lead an end-of-line comment.
+     * http://b/2571423
+     */
+    public void testNextCleanHashComments() throws JSONException {
+        JSONTokener tokener = new JSONTokener("A # B */ /* C */ \nD #");
+        assertEquals('A', tokener.nextClean());
+        assertEquals('D', tokener.nextClean());
+        assertEquals('\0', tokener.nextClean());
+    }
+
+    public void testNextCleanCommentsTrailingSingleSlash() throws JSONException {
+        JSONTokener tokener = new JSONTokener(" / S /");
+        assertEquals('/', tokener.nextClean());
+        assertEquals('S', tokener.nextClean());
+        assertEquals('/', tokener.nextClean());
+        assertEquals("nextClean doesn't consume a trailing slash",
+                '\0', tokener.nextClean());
+    }
+
+    public void testNextCleanTrailingOpenComment() throws JSONException {
+        try {
+            new JSONTokener("  /* ").nextClean();
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals('\0', new JSONTokener("  // ").nextClean());
+    }
+
+    public void testNextCleanNewlineDelimiters() throws JSONException {
+        assertEquals('B', new JSONTokener("  // \r\n  B ").nextClean());
+        assertEquals('B', new JSONTokener("  // \n  B ").nextClean());
+        assertEquals('B', new JSONTokener("  // \r  B ").nextClean());
+    }
+
+    public void testNextCleanSkippedWhitespace() throws JSONException {
+        assertEquals("character tabulation", 'A', new JSONTokener("\tA").nextClean());
+        assertEquals("line feed",            'A', new JSONTokener("\nA").nextClean());
+        assertEquals("carriage return",      'A', new JSONTokener("\rA").nextClean());
+        assertEquals("space",                'A', new JSONTokener(" A").nextClean());
+    }
+
+    /**
+     * Tests which characters tokener treats as ignorable whitespace. See Kevin Bourrillion's
+     * <a href="https://spreadsheets.google.com/pub?key=pd8dAQyHbdewRsnE5x5GzKQ">list
+     * of whitespace characters</a>.
+     */
+    public void testNextCleanRetainedWhitespace() throws JSONException {
+        assertNotClean("null",                      '\u0000');
+        assertNotClean("next line",                 '\u0085');
+        assertNotClean("non-breaking space",        '\u00a0');
+        assertNotClean("ogham space mark",          '\u1680');
+        assertNotClean("mongolian vowel separator", '\u180e');
+        assertNotClean("en quad",                   '\u2000');
+        assertNotClean("em quad",                   '\u2001');
+        assertNotClean("en space",                  '\u2002');
+        assertNotClean("em space",                  '\u2003');
+        assertNotClean("three-per-em space",        '\u2004');
+        assertNotClean("four-per-em space",         '\u2005');
+        assertNotClean("six-per-em space",          '\u2006');
+        assertNotClean("figure space",              '\u2007');
+        assertNotClean("punctuation space",         '\u2008');
+        assertNotClean("thin space",                '\u2009');
+        assertNotClean("hair space",                '\u200a');
+        assertNotClean("zero-width space",          '\u200b');
+        assertNotClean("left-to-right mark",        '\u200e');
+        assertNotClean("right-to-left mark",        '\u200f');
+        assertNotClean("line separator",            '\u2028');
+        assertNotClean("paragraph separator",       '\u2029');
+        assertNotClean("narrow non-breaking space", '\u202f');
+        assertNotClean("medium mathematical space", '\u205f');
+        assertNotClean("ideographic space",         '\u3000');
+        assertNotClean("line tabulation",           '\u000b');
+        assertNotClean("form feed",                 '\u000c');
+        assertNotClean("information separator 4",   '\u001c');
+        assertNotClean("information separator 3",   '\u001d');
+        assertNotClean("information separator 2",   '\u001e');
+        assertNotClean("information separator 1",   '\u001f');
+    }
+
+    private void assertNotClean(String name, char c) throws JSONException {
+        assertEquals("The character " + name + " is not whitespace according to the JSON spec.",
+                c, new JSONTokener(new String(new char[] { c, 'A' })).nextClean());
+    }
+
+    public void testNextString() throws JSONException {
+        assertEquals("", new JSONTokener("'").nextString('\''));
+        assertEquals("", new JSONTokener("\"").nextString('\"'));
+        assertEquals("ABC", new JSONTokener("ABC'DEF").nextString('\''));
+        assertEquals("ABC", new JSONTokener("ABC'''DEF").nextString('\''));
+
+        // nextString permits slash-escaping of arbitrary characters!
+        assertEquals("ABC", new JSONTokener("A\\B\\C'DEF").nextString('\''));
+
+        JSONTokener tokener = new JSONTokener(" 'abc' 'def' \"ghi\"");
+        tokener.next();
+        assertEquals('\'', tokener.next());
+        assertEquals("abc", tokener.nextString('\''));
+        tokener.next();
+        assertEquals('\'', tokener.next());
+        assertEquals("def", tokener.nextString('\''));
+        tokener.next();
+        assertEquals('"', tokener.next());
+        assertEquals("ghi", tokener.nextString('\"'));
+        assertFalse(tokener.more());
+    }
+
+    public void testNextStringNoDelimiter() throws JSONException {
+        try {
+            new JSONTokener("").nextString('\'');
+            fail();
+        } catch (JSONException ignored) {
+        }
+
+        JSONTokener tokener = new JSONTokener(" 'abc");
+        tokener.next();
+        tokener.next();
+        try {
+            tokener.next('\'');
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    public void testNextStringEscapedQuote() throws JSONException {
+        try {
+            new JSONTokener("abc\\").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+
+        // we're mixing Java escaping like \" and JavaScript escaping like \\\"
+        // which makes these tests extra tricky to read!
+        assertEquals("abc\"def", new JSONTokener("abc\\\"def\"ghi").nextString('"'));
+        assertEquals("abc\\def", new JSONTokener("abc\\\\def\"ghi").nextString('"'));
+        assertEquals("abc/def", new JSONTokener("abc\\/def\"ghi").nextString('"'));
+        assertEquals("abc\bdef", new JSONTokener("abc\\bdef\"ghi").nextString('"'));
+        assertEquals("abc\fdef", new JSONTokener("abc\\fdef\"ghi").nextString('"'));
+        assertEquals("abc\ndef", new JSONTokener("abc\\ndef\"ghi").nextString('"'));
+        assertEquals("abc\rdef", new JSONTokener("abc\\rdef\"ghi").nextString('"'));
+        assertEquals("abc\tdef", new JSONTokener("abc\\tdef\"ghi").nextString('"'));
+    }
+
+    public void testNextStringUnicodeEscaped() throws JSONException {
+        // we're mixing Java escaping like \\ and JavaScript escaping like \\u
+        assertEquals("abc def", new JSONTokener("abc\\u0020def\"ghi").nextString('"'));
+        assertEquals("abcU0020def", new JSONTokener("abc\\U0020def\"ghi").nextString('"'));
+
+        // JSON requires 4 hex characters after a unicode escape
+        try {
+            new JSONTokener("abc\\u002\"").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONTokener("abc\\u").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+        try {
+            new JSONTokener("abc\\u    \"").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+        assertEquals("abc\"def", new JSONTokener("abc\\u0022def\"ghi").nextString('"'));
+        try {
+            new JSONTokener("abc\\u000G\"").nextString('"');
+            fail();
+        } catch (JSONException ignored) {
+        }
+    }
+
+    public void testNextStringNonQuote() throws JSONException {
+        assertEquals("AB", new JSONTokener("ABC").nextString('C'));
+        assertEquals("ABCD", new JSONTokener("AB\\CDC").nextString('C'));
+        assertEquals("AB\nC", new JSONTokener("AB\\nCn").nextString('n'));
+    }
+
+    public void testNextTo() throws JSONException {
+        assertEquals("ABC", new JSONTokener("ABCDEFG").nextTo("DHI"));
+        assertEquals("ABCDEF", new JSONTokener("ABCDEF").nextTo(""));
+
+        JSONTokener tokener = new JSONTokener("ABC\rDEF\nGHI\r\nJKL");
+        assertEquals("ABC", tokener.nextTo("M"));
+        assertEquals('\r', tokener.next());
+        assertEquals("DEF", tokener.nextTo("M"));
+        assertEquals('\n', tokener.next());
+        assertEquals("GHI", tokener.nextTo("M"));
+        assertEquals('\r', tokener.next());
+        assertEquals('\n', tokener.next());
+        assertEquals("JKL", tokener.nextTo("M"));
+
+        tokener = new JSONTokener("ABCDEFGHI");
+        assertEquals("ABC", tokener.nextTo("DEF"));
+        assertEquals("", tokener.nextTo("DEF"));
+        assertEquals('D', tokener.next());
+        assertEquals("", tokener.nextTo("DEF"));
+        assertEquals('E', tokener.next());
+        assertEquals("", tokener.nextTo("DEF"));
+        assertEquals('F', tokener.next());
+        assertEquals("GHI", tokener.nextTo("DEF"));
+        assertEquals("", tokener.nextTo("DEF"));
+
+        tokener = new JSONTokener(" \t \fABC \t DEF");
+        assertEquals("ABC", tokener.nextTo("DEF"));
+        assertEquals('D', tokener.next());
+
+        tokener = new JSONTokener(" \t \fABC \n DEF");
+        assertEquals("ABC", tokener.nextTo("\n"));
+        assertEquals("", tokener.nextTo("\n"));
+
+        tokener = new JSONTokener("");
+        try {
+            tokener.nextTo(null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    public void testNextToTrimming() {
+        assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo("DE"));
+        assertEquals("ABC", new JSONTokener("\t ABC \tDEF").nextTo('D'));
+    }
+
+    public void testNextToTrailing() {
+        assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo("G"));
+        assertEquals("ABC DEF", new JSONTokener("\t ABC DEF \t").nextTo('G'));
+    }
+
+    public void testNextToDoesntStopOnNull() {
+        String message = "nextTo() shouldn't stop after \\0 characters";
+        JSONTokener tokener = new JSONTokener(" \0\t \fABC \n DEF");
+        assertEquals(message, "ABC", tokener.nextTo("D"));
+        assertEquals(message, '\n', tokener.next());
+        assertEquals(message, "", tokener.nextTo("D"));
+    }
+
+    public void testNextToConsumesNull() {
+        String message = "nextTo shouldn't consume \\0.";
+        JSONTokener tokener = new JSONTokener("ABC\0DEF");
+        assertEquals(message, "ABC", tokener.nextTo("\0"));
+        assertEquals(message, '\0', tokener.next());
+        assertEquals(message, "DEF", tokener.nextTo("\0"));
+    }
+
+    public void testSkipPast() {
+        JSONTokener tokener = new JSONTokener("ABCDEF");
+        tokener.skipPast("ABC");
+        assertEquals('D', tokener.next());
+        tokener.skipPast("EF");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABCDEF");
+        tokener.skipPast("ABCDEF");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABCDEF");
+        tokener.skipPast("G");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABC\0ABC");
+        tokener.skipPast("ABC");
+        assertEquals('\0', tokener.next());
+        assertEquals('A', tokener.next());
+
+        tokener = new JSONTokener("\0ABC");
+        tokener.skipPast("ABC");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABC\nDEF");
+        tokener.skipPast("DEF");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABC");
+        tokener.skipPast("ABCDEF");
+        assertEquals('\0', tokener.next());
+
+        tokener = new JSONTokener("ABCDABCDABCD");
+        tokener.skipPast("ABC");
+        assertEquals('D', tokener.next());
+        tokener.skipPast("ABC");
+        assertEquals('D', tokener.next());
+        tokener.skipPast("ABC");
+        assertEquals('D', tokener.next());
+
+        tokener = new JSONTokener("");
+        try {
+            tokener.skipPast(null);
+            fail();
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    public void testSkipTo() {
+        JSONTokener tokener = new JSONTokener("ABCDEF");
+        tokener.skipTo('A');
+        assertEquals('A', tokener.next());
+        tokener.skipTo('D');
+        assertEquals('D', tokener.next());
+        tokener.skipTo('G');
+        assertEquals('E', tokener.next());
+        tokener.skipTo('A');
+        assertEquals('F', tokener.next());
+
+        tokener = new JSONTokener("ABC\nDEF");
+        tokener.skipTo('F');
+        assertEquals('F', tokener.next());
+
+        tokener = new JSONTokener("ABCfDEF");
+        tokener.skipTo('F');
+        assertEquals('F', tokener.next());
+
+        tokener = new JSONTokener("ABC/* DEF */");
+        tokener.skipTo('D');
+        assertEquals('D', tokener.next());
+    }
+
+    public void testSkipToStopsOnNull() {
+        JSONTokener tokener = new JSONTokener("ABC\0DEF");
+        tokener.skipTo('F');
+        assertEquals("skipTo shouldn't stop when it sees '\\0'", 'F', tokener.next());
+    }
+
+    public void testBomIgnoredAsFirstCharacterOfDocument() throws JSONException {
+        JSONTokener tokener = new JSONTokener("\ufeff[]");
+        JSONArray array = (JSONArray) tokener.nextValue();
+        assertEquals(0, array.length());
+    }
+
+    public void testBomTreatedAsCharacterInRestOfDocument() throws JSONException {
+        JSONTokener tokener = new JSONTokener("[\ufeff]");
+        JSONArray array = (JSONArray) tokener.nextValue();
+        assertEquals(1, array.length());
+    }
+
+    public void testDehexchar() {
+        assertEquals( 0, JSONTokener.dehexchar('0'));
+        assertEquals( 1, JSONTokener.dehexchar('1'));
+        assertEquals( 2, JSONTokener.dehexchar('2'));
+        assertEquals( 3, JSONTokener.dehexchar('3'));
+        assertEquals( 4, JSONTokener.dehexchar('4'));
+        assertEquals( 5, JSONTokener.dehexchar('5'));
+        assertEquals( 6, JSONTokener.dehexchar('6'));
+        assertEquals( 7, JSONTokener.dehexchar('7'));
+        assertEquals( 8, JSONTokener.dehexchar('8'));
+        assertEquals( 9, JSONTokener.dehexchar('9'));
+        assertEquals(10, JSONTokener.dehexchar('A'));
+        assertEquals(11, JSONTokener.dehexchar('B'));
+        assertEquals(12, JSONTokener.dehexchar('C'));
+        assertEquals(13, JSONTokener.dehexchar('D'));
+        assertEquals(14, JSONTokener.dehexchar('E'));
+        assertEquals(15, JSONTokener.dehexchar('F'));
+        assertEquals(10, JSONTokener.dehexchar('a'));
+        assertEquals(11, JSONTokener.dehexchar('b'));
+        assertEquals(12, JSONTokener.dehexchar('c'));
+        assertEquals(13, JSONTokener.dehexchar('d'));
+        assertEquals(14, JSONTokener.dehexchar('e'));
+        assertEquals(15, JSONTokener.dehexchar('f'));
+
+        for (int c = 0; c <= 0xFFFF; c++) {
+            if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
+                continue;
+            }
+            assertEquals("dehexchar " + c, -1, JSONTokener.dehexchar((char) c));
+        }
+    }
+}


[24/34] geode git commit: GEODE-2142: Adding JSON library from the https://github.com/tdunning/open-json project

Posted by kl...@apache.org.
GEODE-2142: Adding JSON library from the https://github.com/tdunning/open-json project


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/b34e47ff
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/b34e47ff
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/b34e47ff

Branch: refs/heads/GEODE-4160-mockito
Commit: b34e47ffaa92007cf059ae5257e481bfb048bfb3
Parents: a2f47b7
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Fri Feb 17 14:30:37 2017 -0800
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Feb 27 07:18:55 2017 -0800

----------------------------------------------------------------------
 geode-json/build.gradle                         |   22 +
 geode-json/src/main/java/org/json/JSON.java     |  116 ++
 .../src/main/java/org/json/JSONArray.java       |  759 +++++++++++
 .../src/main/java/org/json/JSONException.java   |   57 +
 .../src/main/java/org/json/JSONObject.java      |  993 +++++++++++++++
 .../src/main/java/org/json/JSONString.java      |   18 +
 .../src/main/java/org/json/JSONStringer.java    |  470 +++++++
 .../src/main/java/org/json/JSONTokener.java     |  658 ++++++++++
 geode-json/src/test/java/org/json/FileTest.java |  287 +++++
 .../src/test/java/org/json/JSONArrayTest.java   |  608 +++++++++
 .../java/org/json/JSONFunctionTestObject.java   |   17 +
 .../src/test/java/org/json/JSONObjectTest.java  | 1198 ++++++++++++++++++
 .../test/java/org/json/JSONStringerTest.java    |  421 ++++++
 .../src/test/java/org/json/JSONTokenerTest.java |  621 +++++++++
 .../src/test/java/org/json/ParsingTest.java     |  294 +++++
 .../src/test/java/org/json/SelfUseTest.java     |  276 ++++
 geode-json/src/test/resources/sample-01.json    |  227 ++++
 17 files changed, 7042 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/build.gradle
----------------------------------------------------------------------
diff --git a/geode-json/build.gradle b/geode-json/build.gradle
new file mode 100644
index 0000000..5715685
--- /dev/null
+++ b/geode-json/build.gradle
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.
+ */
+
+dependencies {
+    compile project(':geode-core')
+    compile project(':geode-common')
+    testCompile files(project(':geode-core').sourceSets.test.output)
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/main/java/org/json/JSON.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSON.java b/geode-json/src/main/java/org/json/JSON.java
new file mode 100755
index 0000000..1b32e69
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSON.java
@@ -0,0 +1,116 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+class JSON {
+    /**
+     * Returns the input if it is a JSON-permissible value; throws otherwise.
+     */
+    static double checkDouble(double d) throws JSONException {
+        if (Double.isInfinite(d) || Double.isNaN(d)) {
+            throw new JSONException("Forbidden numeric value: " + d);
+        }
+        return d;
+    }
+
+    static Boolean toBoolean(Object value) {
+        if (value instanceof Boolean) {
+            return (Boolean) value;
+        } else if (value instanceof String) {
+            String stringValue = (String) value;
+            if ("true".equalsIgnoreCase(stringValue)) {
+                return true;
+            } else if ("false".equalsIgnoreCase(stringValue)) {
+                return false;
+            }
+        }
+        return null;
+    }
+
+    static Double toDouble(Object value) {
+        if (value instanceof Double) {
+            return (Double) value;
+        } else if (value instanceof Number) {
+            return ((Number) value).doubleValue();
+        } else if (value instanceof String) {
+            try {
+                return Double.valueOf((String) value);
+            } catch (NumberFormatException ignored) {
+            }
+        }
+        return null;
+    }
+
+    static Integer toInteger(Object value) {
+        if (value instanceof Integer) {
+            return (Integer) value;
+        } else if (value instanceof Number) {
+            return ((Number) value).intValue();
+        } else if (value instanceof String) {
+            try {
+                return (int) Double.parseDouble((String) value);
+            } catch (NumberFormatException ignored) {
+            }
+        }
+        return null;
+    }
+
+    static Long toLong(Object value) {
+        if (value instanceof Long) {
+            return (Long) value;
+        } else if (value instanceof Number) {
+            return ((Number) value).longValue();
+        } else if (value instanceof String) {
+            try {
+                return (long) Double.parseDouble((String) value);
+            } catch (NumberFormatException ignored) {
+            }
+        }
+        return null;
+    }
+
+    static String toString(Object value) {
+        if (value instanceof String) {
+            return (String) value;
+        } else if (value != null) {
+            return String.valueOf(value);
+        }
+        return null;
+    }
+
+    public static JSONException typeMismatch(Object indexOrName, Object actual,
+            String requiredType) throws JSONException {
+        if (actual == null) {
+            throw new JSONException("Value at " + indexOrName + " is null.");
+        } else {
+            throw new JSONException("Value " + actual + " at " + indexOrName
+                    + " of type " + actual.getClass().getName()
+                    + " cannot be converted to " + requiredType);
+        }
+    }
+
+    public static JSONException typeMismatch(Object actual, String requiredType)
+            throws JSONException {
+        if (actual == null) {
+            throw new JSONException("Value is null.");
+        } else {
+            throw new JSONException("Value " + actual
+                    + " of type " + actual.getClass().getName()
+                    + " cannot be converted to " + requiredType);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/main/java/org/json/JSONArray.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONArray.java b/geode-json/src/main/java/org/json/JSONArray.java
new file mode 100755
index 0000000..074624d
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONArray.java
@@ -0,0 +1,759 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+// Note: this class was written without inspecting the non-free org.json sourcecode.
+
+/**
+ * A dense indexed sequence of values. Values may be any mix of
+ * {@link JSONObject JSONObjects}, other {@link JSONArray JSONArrays}, Strings,
+ * Booleans, Integers, Longs, Doubles, {@code null} or {@link JSONObject#NULL}.
+ * Values may not be {@link Double#isNaN() NaNs}, {@link Double#isInfinite()
+ * infinities}, or of any type not listed here.
+ *
+ * {@code JSONArray} has the same type coercion behavior and
+ * optional/mandatory accessors as {@link JSONObject}. See that class'
+ * documentation for details.
+ *
+ * <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, {@code get} fails if the requested index
+ * holds the null reference, but succeeds if it holds {@code JSONObject.NULL}.
+ *
+ * Instances of this class are not thread safe. Although this class is
+ * non-final, it was not designed for inheritance and should not be subclassed.
+ * In particular, self-use by overridable 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 JSONArray {
+
+    private final List<Object> values;
+
+    /**
+     * Creates a {@code JSONArray} with no values.
+     */
+    public JSONArray() {
+        values = new ArrayList<Object>();
+    }
+
+    /**
+     * Creates a new {@code JSONArray} by copying all values from the given
+     * collection.
+     *
+     * @param copyFrom a collection whose values are of supported types.
+     *                 Unsupported values are not permitted and will yield an array in an
+     *                 inconsistent state.
+     */
+    /* Accept a raw type for API compatibility */
+    public JSONArray(Collection<?> copyFrom) {
+        this();
+        if (copyFrom != null) {
+            for (Object aCopyFrom : copyFrom) {
+                put(JSONObject.wrap(aCopyFrom));
+            }
+        }
+    }
+
+    /**
+     * Creates a new {@code JSONArray} with values from the next array in the
+     * tokener.
+     *
+     * @param readFrom a tokener whose nextValue() method will yield a
+     *                 {@code JSONArray}.
+     * @throws JSONException if the parse fails or doesn't yield a
+     *                       {@code JSONArray}.
+     */
+    public JSONArray(JSONTokener readFrom) throws JSONException {
+        /*
+         * Getting the parser to populate this could get tricky. Instead, just
+         * parse to temporary JSONArray and then steal the data from that.
+         */
+        Object object = readFrom.nextValue();
+        if (object instanceof JSONArray) {
+            values = ((JSONArray) object).values;
+        } else {
+            throw JSON.typeMismatch(object, "JSONArray");
+        }
+    }
+
+    /**
+     * Creates a new {@code JSONArray} with values from the JSON string.
+     *
+     * @param json a JSON-encoded string containing an array.
+     * @throws JSONException if the parse fails or doesn't yield a {@code
+     *                       JSONArray}.
+     */
+    public JSONArray(String json) throws JSONException {
+        this(new JSONTokener(json));
+    }
+
+    /**
+     * Creates a new {@code JSONArray} with values from the given primitive array.
+     *
+     * @param array The values to use.
+     * @throws JSONException if any of the values are non-finite double values (i.e. NaN or infinite)
+     */
+    public JSONArray(Object array) throws JSONException {
+        if (!array.getClass().isArray()) {
+            throw new JSONException("Not a primitive array: " + array.getClass());
+        }
+        final int length = Array.getLength(array);
+        values = new ArrayList<Object>(length);
+        for (int i = 0; i < length; ++i) {
+            put(JSONObject.wrap(Array.get(array, i)));
+        }
+    }
+
+    /**
+     * @return Returns the number of values in this array.
+     */
+    public int length() {
+        return values.size();
+    }
+
+    /**
+     * Appends {@code value} to the end of this array.
+     *
+     * @param value The value to append.
+     * @return this array.
+     */
+    public JSONArray put(boolean value) {
+        values.add(value);
+        return this;
+    }
+
+    /**
+     * Appends {@code value} to the end of this array.
+     *
+     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
+     *              {@link Double#isInfinite() infinities}.
+     * @return this array.
+     * @throws JSONException If the value is unacceptable.
+     */
+    public JSONArray put(double value) throws JSONException {
+        values.add(JSON.checkDouble(value));
+        return this;
+    }
+
+    /**
+     * Appends {@code value} to the end of this array.
+     *
+     * @param value The value to append.
+     * @return this array.
+     */
+    public JSONArray put(int value) {
+        values.add(value);
+        return this;
+    }
+
+    /**
+     * Appends {@code value} to the end of this array.
+     *
+     * @param value The value to append.
+     * @return this array.
+     */
+    public JSONArray put(long value) {
+        values.add(value);
+        return this;
+    }
+
+    /**
+     * Appends {@code value} wrapped by {@link JSONArray} to the end of this array.
+     *
+     * @param value any collection.
+     * @return this array.
+     */
+    public JSONArray put(Collection<?> value) {
+        if (value == null) {
+            return put((Object)null);
+        }
+        values.add(new JSONArray(value));
+        return this;
+    }
+
+    /**
+     * Appends {@code value} to the end of this array.
+     *
+     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
+     *              Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May
+     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
+     *              infinities}. Unsupported values are not permitted and will cause the
+     *              array to be in an inconsistent state.
+     * @return this array.
+     */
+    public JSONArray put(Object value) {
+        values.add(value);
+        return this;
+    }
+
+    /**
+     * Same as {@link #put}, with added validity checks.
+     *
+     * @param value The value to append.
+     */
+    void checkedPut(Object value) throws JSONException {
+        if (value instanceof Number) {
+            JSON.checkDouble(((Number) value).doubleValue());
+        }
+
+        put(value);
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value}, null padding this array
+     * to the required length if necessary. If a value already exists at {@code
+     * index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value The value to set.
+     * @return this array.
+     * @throws JSONException This should never happen.
+     */
+    public JSONArray put(int index, boolean value) throws JSONException {
+        return put(index, (Boolean) value);
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value}, null padding this array
+     * to the required length if necessary. If a value already exists at {@code
+     * index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
+     *              {@link Double#isInfinite() infinities}.
+     * @return this array.
+     * @throws JSONException If the value is not a finite value.
+     */
+    public JSONArray put(int index, double value) throws JSONException {
+        return put(index, (Double) value);
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value}, null padding this array
+     * to the required length if necessary. If a value already exists at {@code
+     * index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value The value to set.
+     * @return this array.
+     * @throws JSONException Should never actually happen.
+     */
+    public JSONArray put(int index, int value) throws JSONException {
+        return put(index, (Integer) value);
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value}, null padding this array
+     * to the required length if necessary. If a value already exists at {@code
+     * index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value The value to set.
+     * @return this array.
+     * @throws JSONException Should never actually happen.
+     */
+    public JSONArray put(int index, long value) throws JSONException {
+        return put(index, (Long) value);
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value} wrapped into {@link JSONArray},
+     * null padding this array to the required length if necessary. If a value already
+     * exists at {@code index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value The value to set.
+     * @return this array.
+     * @throws JSONException Should never actually happen.
+     */
+    public JSONArray put(int index, Collection<?> value) throws JSONException {
+        if (value == null) {
+            return put(index, (Object)null);
+        }
+        return put(index, new JSONArray(value));
+    }
+
+    /**
+     * Sets the value at {@code index} to {@code value}, null padding this array
+     * to the required length if necessary. If a value already exists at {@code
+     * index}, it will be replaced.
+     *
+     * @param index Where to put the value.
+     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
+     *              Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May
+     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
+     *              infinities}.
+     * @return this array.
+     * @throws JSONException If the value cannot be represented as a finite double value.
+     */
+    public JSONArray put(int index, Object value) throws JSONException {
+        if (value instanceof Number) {
+            // deviate from the original by checking all Numbers, not just floats & doubles
+            JSON.checkDouble(((Number) value).doubleValue());
+        }
+        while (values.size() <= index) {
+            values.add(null);
+        }
+        values.set(index, value);
+        return this;
+    }
+
+    /**
+     * Returns true if this array has no value at {@code index}, or if its value
+     * is the {@code null} reference or {@link JSONObject#NULL}.
+     *
+     * @param index Which value to check.
+     * @return true if the value is null.
+     */
+    public boolean isNull(int index) {
+        Object value = opt(index);
+        return value == null || value == JSONObject.NULL;
+    }
+
+    /**
+     * Returns the value at {@code index}.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if this array has no value at {@code index}, or if
+     *                       that value is the {@code null} reference. This method returns
+     *                       normally if the value is {@code JSONObject#NULL}.
+     */
+    public Object get(int index) throws JSONException {
+        try {
+            Object value = values.get(index);
+            if (value == null) {
+                throw new JSONException("Value at " + index + " is null.");
+            }
+            return value;
+        } catch (IndexOutOfBoundsException e) {
+            throw new JSONException("Index " + index + " out of range [0.." + values.size() + ")");
+        }
+    }
+
+    /**
+     * Returns the value at {@code index}, or null if the array has no value
+     * at {@code index}.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public Object opt(int index) {
+        if (index < 0 || index >= values.size()) {
+            return null;
+        }
+        return values.get(index);
+    }
+
+    /**
+     * Removes and returns the value at {@code index}, or null if the array has no value
+     * at {@code index}.
+     *
+     * @param index Which value to remove.
+     * @return The value previously at the specified location.
+     */
+    public Object remove(int index) {
+        if (index < 0 || index >= values.size()) {
+            return null;
+        }
+        return values.remove(index);
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a boolean or can
+     * be coerced to a boolean.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value at {@code index} doesn't exist or
+     *                       cannot be coerced to a boolean.
+     */
+    public boolean getBoolean(int index) throws JSONException {
+        Object object = get(index);
+        Boolean result = JSON.toBoolean(object);
+        if (result == null) {
+            throw JSON.typeMismatch(index, object, "boolean");
+        }
+        return result;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a boolean or can
+     * be coerced to a boolean. Returns false otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public boolean optBoolean(int index) {
+        return optBoolean(index, false);
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a boolean or can
+     * be coerced to a boolean. Returns {@code fallback} otherwise.
+     *
+     * @param index    Which value to get.
+     * @param fallback the fallback value to return if no value exists.
+     * @return the value at the specified location or the fallback value.
+     */
+    public boolean optBoolean(int index, boolean fallback) {
+        Object object = opt(index);
+        Boolean result = JSON.toBoolean(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a double or can
+     * be coerced to a double.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value at {@code index} doesn't exist or
+     *                       cannot be coerced to a double.
+     */
+    public double getDouble(int index) throws JSONException {
+        Object object = get(index);
+        Double result = JSON.toDouble(object);
+        if (result == null) {
+            throw JSON.typeMismatch(index, object, "double");
+        }
+        return result;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a double or can
+     * be coerced to a double. Returns {@code NaN} otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public double optDouble(int index) {
+        return optDouble(index, Double.NaN);
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a double or can
+     * be coerced to a double. Returns {@code fallback} otherwise.
+     *
+     * @param index    Which value to get.
+     * @param fallback The fallback value to use if no value is at the specified location.
+     * @return the value at the specified location or the fallback value.
+     */
+    public double optDouble(int index, double fallback) {
+        Object object = opt(index);
+        Double result = JSON.toDouble(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is an int or
+     * can be coerced to an int.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value at {@code index} doesn't exist or
+     *                       cannot be coerced to a int.
+     */
+    public int getInt(int index) throws JSONException {
+        Object object = get(index);
+        Integer result = JSON.toInteger(object);
+        if (result == null) {
+            throw JSON.typeMismatch(index, object, "int");
+        }
+        return result;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is an int or
+     * can be coerced to an int. Returns 0 otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public int optInt(int index) {
+        return optInt(index, 0);
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is an int or
+     * can be coerced to an int. Returns {@code fallback} otherwise.
+     *
+     * @param index    Which value to get.
+     * @param fallback The fallback value to use if no value is at the specified location.
+     * @return the value at the specified location or the fallback value.
+     */
+    public int optInt(int index, int fallback) {
+        Object object = opt(index);
+        Integer result = JSON.toInteger(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a long or
+     * can be coerced to a long.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value at {@code index} doesn't exist or
+     *                       cannot be coerced to a long.
+     */
+    public long getLong(int index) throws JSONException {
+        Object object = get(index);
+        Long result = JSON.toLong(object);
+        if (result == null) {
+            throw JSON.typeMismatch(index, object, "long");
+        }
+        return result;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a long or
+     * can be coerced to a long. Returns 0 otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public long optLong(int index) {
+        return optLong(index, 0L);
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a long or
+     * can be coerced to a long. Returns {@code fallback} otherwise.
+     *
+     * @param index    Which value to get.
+     * @param fallback The fallback value to use if no value is at the specified location.
+     * @return the value at the specified location or the fallback value.
+     */
+    public long optLong(int index, long fallback) {
+        Object object = opt(index);
+        Long result = JSON.toLong(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists, coercing it if
+     * necessary.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if no such value exists.
+     */
+    public String getString(int index) throws JSONException {
+        Object object = get(index);
+        String result = JSON.toString(object);
+        if (result == null) {
+            throw JSON.typeMismatch(index, object, "String");
+        }
+        return result;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists, coercing it if
+     * necessary. Returns the empty string if no such value exists.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public String optString(int index) {
+        return optString(index, "");
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists, coercing it if
+     * necessary. Returns {@code fallback} if no such value exists.
+     *
+     * @param index    Which value to get.
+     * @param fallback The fallback value to use if no value is at the specified location.
+     * @return the value at the specified location or the fallback value.
+     */
+    public String optString(int index, String fallback) {
+        Object object = opt(index);
+        String result = JSON.toString(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a {@code
+     * JSONArray}.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value doesn't exist or is not a {@code
+     *                       JSONArray}.
+     */
+    public JSONArray getJSONArray(int index) throws JSONException {
+        Object object = get(index);
+        if (object instanceof JSONArray) {
+            return (JSONArray) object;
+        } else {
+            throw JSON.typeMismatch(index, object, "JSONArray");
+        }
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a {@code
+     * JSONArray}. Returns null otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public JSONArray optJSONArray(int index) {
+        Object object = opt(index);
+        return object instanceof JSONArray ? (JSONArray) object : null;
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a {@code
+     * JSONObject}.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     * @throws JSONException if the value doesn't exist or is not a {@code
+     *                       JSONObject}.
+     */
+    public JSONObject getJSONObject(int index) throws JSONException {
+        Object object = get(index);
+        if (object instanceof JSONObject) {
+            return (JSONObject) object;
+        } else {
+            throw JSON.typeMismatch(index, object, "JSONObject");
+        }
+    }
+
+    /**
+     * Returns the value at {@code index} if it exists and is a {@code
+     * JSONObject}. Returns null otherwise.
+     *
+     * @param index Which value to get.
+     * @return the value at the specified location.
+     */
+    public JSONObject optJSONObject(int index) {
+        Object object = opt(index);
+        return object instanceof JSONObject ? (JSONObject) object : null;
+    }
+
+    /**
+     * Returns a new object whose values are the values in this array, and whose
+     * names are the values in {@code names}. Names and values are paired up by
+     * index from 0 through to the shorter array's length. Names that are not
+     * strings will be coerced to strings. This method returns null if either
+     * array is empty.
+     *
+     * @param names The names to apply to the returned values.
+     * @return the newly constructed object.
+     * @throws JSONException Should not be possible.
+     */
+    public JSONObject toJSONObject(JSONArray names) throws JSONException {
+        JSONObject result = new JSONObject();
+        int length = Math.min(names.length(), values.size());
+        if (length == 0) {
+            return null;
+        }
+        for (int i = 0; i < length; i++) {
+            String name = JSON.toString(names.opt(i));
+            result.put(name, opt(i));
+        }
+        return result;
+    }
+
+    /**
+     * Returns a new string by alternating this array's values with {@code
+     * separator}. This array's string values are quoted and have their special
+     * characters escaped. For example, the array containing the strings '12"
+     * pizza', 'taco' and 'soda' joined on '+' returns this:
+     * <pre>"12\" pizza"+"taco"+"soda"</pre>
+     *
+     * @param separator The string used to separate the returned values.
+     * @return the conjoined values.
+     * @throws JSONException Only if there is a coding error.
+     */
+    public String join(String separator) throws JSONException {
+        JSONStringer stringer = new JSONStringer();
+        stringer.open(JSONStringer.Scope.NULL, "");
+        for (int i = 0, size = values.size(); i < size; i++) {
+            if (i > 0) {
+                stringer.out.append(separator);
+            }
+            stringer.value(values.get(i));
+        }
+        stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
+        return stringer.out.toString();
+    }
+
+    /**
+     * Encodes this array as a compact JSON string, such as:
+     * <pre>[94043,90210]</pre>
+     *
+     * @return The string form of this array.
+     */
+    @Override
+    public String toString() {
+        try {
+            JSONStringer stringer = new JSONStringer();
+            writeTo(stringer);
+            return stringer.toString();
+        } catch (JSONException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Encodes this array as a human readable JSON string for debugging, such
+     * as:
+     * <pre>
+     * [
+     *     94043,
+     *     90210
+     * ]</pre>
+     *
+     * @param indentSpaces the number of spaces to indent for each level of
+     *                     nesting.
+     * @return The string form of this array.
+     * @throws JSONException Only if there is a coding error.
+     */
+    public String toString(int indentSpaces) throws JSONException {
+        JSONStringer stringer = new JSONStringer(indentSpaces);
+        writeTo(stringer);
+        return stringer.toString();
+    }
+
+    void writeTo(JSONStringer stringer) throws JSONException {
+        stringer.array();
+        for (Object value : values) {
+            stringer.value(value);
+        }
+        stringer.endArray();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return o instanceof JSONArray && ((JSONArray) o).values.equals(values);
+    }
+
+    @Override
+    public int hashCode() {
+        // diverge from the original, which doesn't implement hashCode
+        return values.hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/geode-json/src/main/java/org/json/JSONException.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONException.java b/geode-json/src/main/java/org/json/JSONException.java
new file mode 100755
index 0000000..1292e86
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONException.java
@@ -0,0 +1,57 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+// Note: this class was written without inspecting the non-free org.json sourcecode.
+
+/**
+ * Thrown to indicate a problem with the JSON API. Such problems include:
+ * <ul>
+ *   <li>Attempts to parse or construct malformed documents
+ *   <li>Use of null as a name
+ *   <li>Use of numeric types not available to JSON, such as {@link
+ *       Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}.
+ *   <li>Lookups using an out of range index or nonexistent name
+ *   <li>Type mismatches on lookups
+ * </ul>
+ *
+ * <p>Although this is a checked exception, it is rarely recoverable. Most
+ * callers should simply wrap this exception in an unchecked exception and
+ * rethrow:
+ * <pre>  public JSONArray toJSONObject() {
+ *     try {
+ *         JSONObject result = new JSONObject();
+ *         ...
+ *     } catch (JSONException e) {
+ *         throw new RuntimeException(e);
+ *     }
+ * }</pre>
+ */
+public class JSONException extends RuntimeException {
+
+    public JSONException(String s) {
+        super(s);
+    }
+
+    public JSONException(Throwable cause) {
+        super(cause);
+    }
+
+    public JSONException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/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
new file mode 100755
index 0000000..d2bc126
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONObject.java
@@ -0,0 +1,993 @@
+/*
+ * 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
+ *
+ *      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.
+ */
+
+package org.json;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+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.
+ *
+ * <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".
+ * </ul>
+ *
+ * <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.
+ * </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>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 {
+
+    private static final Double NEGATIVE_ZERO = -0d;
+
+    /**
+     * 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
+     * <li>return {@code true} for {@link #has(String)}
+     * <li>do not throw on {@link #get(String)}
+     * <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".
+     */
+    public static final Object NULL = new Object() {
+        @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
+        @Override
+        public boolean equals(Object o) {
+            return o == this || o == null; // API specifies this broken equals implementation
+        }
+
+        // at least make the broken equals(null) consistent with Objects.hashCode(null).
+        @Override
+        public int hashCode() {
+            return 0;
+        }
+
+        @Override
+        public String toString() {
+            return "null";
+        }
+    };
+
+    private final LinkedHashMap<String, Object> nameValuePairs;
+
+    /**
+     * Creates a {@code JSONObject} with no name/value mappings.
+     */
+    public JSONObject() {
+        nameValuePairs = new LinkedHashMap<String, Object>();
+    }
+
+    /**
+     * 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.
+     * @throws NullPointerException if any of the map's keys are null.
+     */
+    /* (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).
+             */
+            String key = (String) entry.getKey();
+            if (key == null) {
+                throw new NullPointerException("key == null");
+            }
+            nameValuePairs.put(key, wrap(entry.getValue()));
+        }
+    }
+
+    /**
+     * 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.
+         */
+        Object object = readFrom.nextValue();
+        if (object instanceof JSONObject) {
+            this.nameValuePairs = ((JSONObject) object).nameValuePairs;
+        } else {
+            throw JSON.typeMismatch(object, "JSONObject");
+        }
+    }
+
+    /**
+     * 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}.
+     */
+    public JSONObject(String json) throws JSONException {
+        this(new JSONTokener(json));
+    }
+
+    /**
+     * 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.
+     */
+    public JSONObject(JSONObject copyFrom, String[] names) throws JSONException {
+        this();
+        for (String name : names) {
+            Object value = copyFrom.opt(name);
+            if (value != null) {
+                nameValuePairs.put(name, value);
+            }
+        }
+    }
+
+    /**
+     * 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
+     */
+    public JSONObject(Object bean) throws JSONException {
+        this(propertiesAsMap(bean));
+    }
+
+    private static Map<String, Object> propertiesAsMap(Object bean) throws JSONException {
+        Map<String, Object> props = new TreeMap<String, Object>();
+        try {
+            PropertyDescriptor[] properties = Introspector.getBeanInfo(bean.getClass(), Object.class)
+                    .getPropertyDescriptors();
+            for (PropertyDescriptor prop : properties) {
+                Object v = prop.getReadMethod().invoke(bean);
+                props.put(prop.getDisplayName(), wrap(v));
+            }
+        } catch (IllegalAccessException e) {
+            throw new JSONException(e);
+        } catch (IntrospectionException e) {
+            throw new JSONException(e);
+        } catch (InvocationTargetException e) {
+            throw new JSONException(e);
+        }
+        return props;
+    }
+
+    public static String[] getNames(JSONObject x) {
+        Set<String> names = x.keySet();
+        String[] r = new String[names.size()];
+        int i = 0;
+        for (String name : names) {
+            r[i++] = name;
+        }
+        return r;
+    }
+
+    /**
+     * Returns the number of name/value mappings in this object.
+     *
+     * @return the length of this.
+     */
+    public int length() {
+        return nameValuePairs.size();
+    }
+
+    /**
+     * 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.
+     * @throws JSONException Should not be possible.
+     */
+    public JSONObject put(String name, boolean value) throws JSONException {
+        nameValuePairs.put(checkName(name), value);
+        return this;
+    }
+
+    /**
+     * 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}.
+     * @return this object.
+     * @throws JSONException if value is NaN or infinite.
+     */
+    public JSONObject put(String name, double value) throws JSONException {
+        nameValuePairs.put(checkName(name), JSON.checkDouble(value));
+        return this;
+    }
+
+    /**
+     * 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.
+     * @throws JSONException Should not be possible.
+     */
+    public JSONObject put(String name, int value) throws JSONException {
+        nameValuePairs.put(checkName(name), value);
+        return this;
+    }
+
+    /**
+     * 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.
+     * @throws JSONException Should not be possible.
+     */
+    public JSONObject put(String name, long value) throws JSONException {
+        nameValuePairs.put(checkName(name), value);
+        return this;
+    }
+
+    /**
+     * 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}.
+     * @return this object.
+     * @throws JSONException if the value is an invalid double (infinite or NaN).
+     */
+    public JSONObject put(String name, Object value) throws JSONException {
+        if (value == null) {
+            nameValuePairs.remove(name);
+            return this;
+        }
+        if (value instanceof Number) {
+            // deviate from the original by checking all Numbers, not just floats & doubles
+            JSON.checkDouble(((Number) value).doubleValue());
+        }
+        nameValuePairs.put(checkName(name), value);
+        return this;
+    }
+
+    /**
+     * 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.
+     * @throws JSONException if the value is an invalid double (infinite or NaN).
+     */
+    public JSONObject putOpt(String name, Object value) throws JSONException {
+        if (name == null || value == null) {
+            return this;
+        }
+        return put(name, value);
+    }
+
+    /**
+     * 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}
+     * 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}.
+     * @return this object after mutation.
+     * @throws JSONException If the object being added is an invalid number.
+     */
+    // TODO: Change {@code append) to {@link #append} when append is
+    // unhidden.
+    public JSONObject accumulate(String name, Object value) throws JSONException {
+        Object current = nameValuePairs.get(checkName(name));
+        if (current == null) {
+            return put(name, value);
+        }
+
+        if (current instanceof JSONArray) {
+            JSONArray array = (JSONArray) current;
+            array.checkedPut(value);
+        } else {
+            JSONArray array = new JSONArray();
+            array.checkedPut(current);
+            array.checkedPut(value);
+            nameValuePairs.put(name, array);
+        }
+        return this;
+    }
+
+    /**
+     * 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}.
+     */
+    public JSONObject append(String name, Object value) throws JSONException {
+        Object current = nameValuePairs.get(checkName(name));
+
+        final JSONArray array;
+        if (current instanceof JSONArray) {
+            array = (JSONArray) current;
+        } else if (current == null) {
+            JSONArray newArray = new JSONArray();
+            nameValuePairs.put(name, newArray);
+            array = newArray;
+        } else {
+            throw new JSONException("Key " + name + " is not a JSONArray");
+        }
+
+        array.checkedPut(value);
+
+        return this;
+    }
+
+    String checkName(String name) throws JSONException {
+        if (name == null) {
+            throw new JSONException("Names must be non-null");
+        }
+        return name;
+    }
+
+    /**
+     * 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.
+     */
+    public Object remove(String name) {
+        return nameValuePairs.remove(name);
+    }
+
+    /**
+     * 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.
+     */
+    public boolean isNull(String name) {
+        Object value = nameValuePairs.get(name);
+        return value == null || value == 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}
+     */
+    public boolean has(String name) {
+        return nameValuePairs.containsKey(name);
+    }
+
+    /**
+     * 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.
+     */
+    public Object get(String name) throws JSONException {
+        Object result = nameValuePairs.get(name);
+        if (result == null) {
+            throw new JSONException("No value for " + name);
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public Object opt(String name) {
+        return nameValuePairs.get(name);
+    }
+
+    /**
+     * 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.
+     */
+    public boolean getBoolean(String name) throws JSONException {
+        Object object = get(name);
+        Boolean result = JSON.toBoolean(object);
+        if (result == null) {
+            throw JSON.typeMismatch(name, object, "boolean");
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public boolean optBoolean(String name) {
+        return optBoolean(name, false);
+    }
+
+    /**
+     * 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.
+     */
+    public boolean optBoolean(String name, boolean fallback) {
+        Object object = opt(name);
+        Boolean result = JSON.toBoolean(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * 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.
+     */
+    public double getDouble(String name) throws JSONException {
+        Object object = get(name);
+        Double result = JSON.toDouble(object);
+        if (result == null) {
+            throw JSON.typeMismatch(name, object, "double");
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public double optDouble(String name) {
+        return optDouble(name, Double.NaN);
+    }
+
+    /**
+     * 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.
+     */
+    public double optDouble(String name, double fallback) {
+        Object object = opt(name);
+        Double result = JSON.toDouble(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * 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.
+     */
+    public int getInt(String name) throws JSONException {
+        Object object = get(name);
+        Integer result = JSON.toInteger(object);
+        if (result == null) {
+            throw JSON.typeMismatch(name, object, "int");
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public int optInt(String name) {
+        return optInt(name, 0);
+    }
+
+    /**
+     * 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.
+     */
+    public int optInt(String name, int fallback) {
+        Object object = opt(name);
+        Integer result = JSON.toInteger(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * 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.
+     *
+     * @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.
+     */
+    public long getLong(String name) throws JSONException {
+        Object object = get(name);
+        Long result = JSON.toLong(object);
+        if (result == null) {
+            throw JSON.typeMismatch(name, object, "long");
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public long optLong(String name) {
+        return optLong(name, 0L);
+    }
+
+    /**
+     * 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.
+     */
+    public long optLong(String name, long fallback) {
+        Object object = opt(name);
+        Long result = JSON.toLong(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * 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.
+     */
+    public String getString(String name) throws JSONException {
+        Object object = get(name);
+        String result = JSON.toString(object);
+        if (result == null) {
+            throw JSON.typeMismatch(name, object, "String");
+        }
+        return result;
+    }
+
+    /**
+     * 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.
+     */
+    public String optString(String name) {
+        return optString(name, "");
+    }
+
+    /**
+     * 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.
+     */
+    public String optString(String name, String fallback) {
+        Object object = opt(name);
+        String result = JSON.toString(object);
+        return result != null ? result : fallback;
+    }
+
+    /**
+     * 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}.
+     */
+    public JSONArray getJSONArray(String name) throws JSONException {
+        Object object = get(name);
+        if (object instanceof JSONArray) {
+            return (JSONArray) object;
+        } else {
+            throw JSON.typeMismatch(name, object, "JSONArray");
+        }
+    }
+
+    /**
+     * 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
+     */
+    public JSONArray optJSONArray(String name) {
+        Object object = opt(name);
+        return object instanceof JSONArray ? (JSONArray) object : null;
+    }
+
+    /**
+     * 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}.
+     */
+    public JSONObject getJSONObject(String name) throws JSONException {
+        Object object = get(name);
+        if (object instanceof JSONObject) {
+            return (JSONObject) object;
+        } else {
+            throw JSON.typeMismatch(name, object, "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.
+     */
+    public JSONObject optJSONObject(String name) {
+        Object object = opt(name);
+        return object instanceof JSONObject ? (JSONObject) object : null;
+    }
+
+    /**
+     * 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.
+     */
+    public JSONArray toJSONArray(JSONArray names) throws JSONException {
+        JSONArray result = new JSONArray();
+        if (names == null) {
+            return null;
+        }
+        int length = names.length();
+        if (length == 0) {
+            return null;
+        }
+        for (int i = 0; i < length; i++) {
+            String name = JSON.toString(names.opt(i));
+            result.put(opt(name));
+        }
+        return result;
+    }
+
+    /**
+     * 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() {
+        return nameValuePairs.keySet().iterator();
+    }
+
+    /**
+     * 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() {
+        return nameValuePairs.keySet();
+    }
+
+    /**
+     * 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
+                : new JSONArray(new ArrayList<String>(nameValuePairs.keySet()));
+    }
+
+    /**
+     * Encodes this object as a compact JSON string, such as:
+     * <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
+     */
+    @Override
+    public String toString() {
+        try {
+            JSONStringer stringer = new JSONStringer();
+            writeTo(stringer);
+            return stringer.toString();
+        } catch (JSONException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Encodes this object as a human readable JSON string for debugging, such
+     * as:
+     * <pre>
+     * {
+     *     "query": "Pizza",
+     *     "locations": [
+     *         94043,
+     *         90210
+     *     ]
+     * }</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.
+     */
+    public String toString(int indentSpaces) throws JSONException {
+        JSONStringer stringer = new JSONStringer(indentSpaces);
+        writeTo(stringer);
+        return stringer.toString();
+    }
+
+    void writeTo(JSONStringer stringer) throws JSONException {
+        stringer.object();
+        for (Map.Entry<String, Object> entry : nameValuePairs.entrySet()) {
+            stringer.key(entry.getKey()).value(entry.getValue());
+        }
+        stringer.endObject();
+    }
+
+    /**
+     * Encodes the number as a JSON string.
+     *
+     * @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.
+     */
+    public static String numberToString(Number number) throws JSONException {
+        if (number == null) {
+            throw new JSONException("Number must be non-null");
+        }
+
+        double doubleValue = number.doubleValue();
+        JSON.checkDouble(doubleValue);
+
+        // the original returns "-0" instead of "-0.0" for negative zero
+        if (number.equals(NEGATIVE_ZERO)) {
+            return "-0";
+        }
+
+        long longValue = number.longValue();
+        if (doubleValue == (double) longValue) {
+            return Long.toString(longValue);
+        }
+
+        return number.toString();
+    }
+
+    /**
+     * 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.
+     */
+    public static String quote(String data) {
+        if (data == null) {
+            return "\"\"";
+        }
+        try {
+            JSONStringer stringer = new JSONStringer();
+            stringer.open(JSONStringer.Scope.NULL, "");
+            stringer.value(data);
+            stringer.close(JSONStringer.Scope.NULL, JSONStringer.Scope.NULL, "");
+            return stringer.toString();
+        } catch (JSONException e) {
+            throw new AssertionError();
+        }
+    }
+
+    /**
+     * Wraps the given object if necessary.
+     *
+     * <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 object is a primitive wrapper type or {@code String}, returns the object.
+     * If the object is from 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}
+     */
+    public static Object wrap(Object o) {
+        if (o == null) {
+            return NULL;
+        }
+        if (o instanceof JSONArray || o instanceof JSONObject) {
+            return o;
+        }
+        if (o.equals(NULL)) {
+            return o;
+        }
+        try {
+            if (o instanceof Collection) {
+                return new JSONArray((Collection) o);
+            } else if (o.getClass().isArray()) {
+                return new JSONArray(o);
+            }
+            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) {
+                return o;
+            }
+            if (o.getClass().getPackage().getName().startsWith("java.") || o instanceof Enum<?>) {
+                return o.toString();
+            } else {
+                return new JSONObject(o);
+            }
+        } catch (Exception ignored) {
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/b34e47ff/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
new file mode 100755
index 0000000..34815a8
--- /dev/null
+++ b/geode-json/src/main/java/org/json/JSONString.java
@@ -0,0 +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.
+ */
+public interface JSONString {
+  /**
+   * 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


[04/34] geode git commit: GEODE-1887: Now Size api goes through ServerProxy when cache is of type client and DataPolicy is Empty. Added a test for both PR and Replicated regions.

Posted by kl...@apache.org.
GEODE-1887: Now Size api goes through ServerProxy when cache is of type client and DataPolicy is Empty.
Added a test for both PR and Replicated regions.

GEODE-1887: Addressing review comments, refactor test based on the
region type.

GEODE-1887: Spotless fixes.

GEODE-1887: Addressing Review Comments.

GEODE-1887: Spotless


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/f2721dc8
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/f2721dc8
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/f2721dc8

Branch: refs/heads/GEODE-4160-mockito
Commit: f2721dc81256bcec84e855e9dc52d2f234e745da
Parents: a8757f6
Author: adongre <ad...@apache.org>
Authored: Sat Feb 4 21:34:37 2017 +0530
Committer: adongre <ad...@apache.org>
Committed: Mon Feb 27 18:01:53 2017 +0530

----------------------------------------------------------------------
 .../geode/internal/cache/LocalRegion.java       |  6 ++
 .../tier/sockets/ClientServerMiscDUnitTest.java | 84 +++++++++++++++-----
 2 files changed, 69 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/f2721dc8/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 5d5c7e2..382c225 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -9122,6 +9122,12 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
       lockRIReadLock(); // bug #40871 - test sees wrong size for region during RI
     }
     try {
+      if (isClient && getDataPolicy() == DataPolicy.EMPTY) {
+        ServerRegionProxy srp = getServerProxy();
+        if (srp != null) {
+          return srp.size();
+        }
+      }
       return entryCount();
     } finally {
       if (isClient) {

http://git-wip-us.apache.org/repos/asf/geode/blob/f2721dc8/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
index b4f3185..06ea6ba 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java
@@ -23,20 +23,12 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
 import org.apache.geode.GemFireConfigException;
 import org.apache.geode.GemFireIOException;
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.CacheWriterException;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.client.NoAvailableServersException;
-import org.apache.geode.cache.client.Pool;
-import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.*;
+import org.apache.geode.cache.client.*;
 import org.apache.geode.cache.client.internal.Connection;
 import org.apache.geode.cache.client.internal.Op;
 import org.apache.geode.cache.client.internal.PoolImpl;
@@ -49,15 +41,7 @@ import org.apache.geode.internal.AvailablePort;
 import org.apache.geode.internal.cache.CacheServerImpl;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.LocalRegion;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.DistributedTestUtils;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.Wait;
-import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.*;
 import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
 import org.apache.geode.test.dunit.standalone.VersionManager;
 import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -77,6 +61,7 @@ import java.util.Set;
  * Tests client server corner cases between Region and Pool
  */
 @Category({DistributedTest.class, ClientServerTest.class})
+@RunWith(JUnitParamsRunner.class)
 public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
 
   protected static PoolImpl pool = null;
@@ -773,6 +758,63 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase {
   }
 
 
+  @Test
+  @Parameters(method = "regionShortcut")
+  public void testProxyRegionClientServerOp(RegionShortcut shortcut) throws Exception {
+    // start server first
+    final String REGION_NAME = "proxyRegionClientServerOp";
+    PORT1 = initServerCache(false);
+    // Create regions on servers.
+    server1.invoke(() -> {
+      Cache cache = CacheFactory.getAnyInstance();
+      Region<Object, Object> region = cache.createRegionFactory(shortcut).create(REGION_NAME);
+      assertNotNull(region);
+    });
+
+    String host = NetworkUtils.getServerHostName(server1.getHost());
+
+    Properties props = new Properties();
+    props.setProperty(MCAST_PORT, "0");
+    props.setProperty(LOCATORS, "");
+    ClientCacheFactory ccf = new ClientCacheFactory(props);
+    ccf.addPoolServer(host, PORT1);
+
+    ClientCache clientCache = ccf.create();
+    Region<Object, Object> clientRegion =
+        clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
+    assertNotNull(clientRegion);
+
+    // let us populate this region from client.
+    for (int i = 0; i < 10; i++) {
+      clientRegion.put(i, i * 10);
+    }
+    // Verify using gets
+    for (int i = 0; i < 10; i++) {
+      assertEquals(i * 10, clientRegion.get(i));
+    }
+    assertEquals(10, clientRegion.size());
+    assertFalse(clientRegion.isEmpty());
+    // delete all the entries from the server
+    server1.invoke(() -> {
+      Cache cache = CacheFactory.getAnyInstance();
+      Region<Object, Object> region = cache.getRegion(REGION_NAME);
+      assertNotNull(region);
+      for (int i = 0; i < 10; i++) {
+        region.remove(i);
+      }
+    });
+    assertEquals(0, clientRegion.size());
+    assertTrue(clientRegion.isEmpty());
+
+    clientRegion.destroyRegion();
+    clientCache.close();
+  }
+
+  private RegionShortcut[] regionShortcut() {
+    return new RegionShortcut[] {RegionShortcut.PARTITION, RegionShortcut.REPLICATE};
+  }
+
+
   private void createCache(Properties props) throws Exception {
     createCacheV(props);
   }


[15/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/main/java/org/json/JSONTokener.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONTokener.java b/geode-json/src/main/java/org/json/JSONTokener.java
index 59eb4bc..21c9fb0 100755
--- a/geode-json/src/main/java/org/json/JSONTokener.java
+++ b/geode-json/src/main/java/org/json/JSONTokener.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -22,637 +20,620 @@ import java.io.IOException;
 import java.io.Reader;
 
 /**
- * Parses a JSON (<a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>)
- * encoded string into the corresponding object. Most clients of
- * this class will use only need the {@link #JSONTokener(String) constructor}
- * and {@link #nextValue} method. Example usage: <pre>
- * String json = "{"
- *         + "  \"query\": \"Pizza\", "
- *         + "  \"locations\": [ 94043, 90210 ] "
- *         + "}";
+ * Parses a JSON (<a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>) encoded string into
+ * the corresponding object. Most clients of this class will use only need the
+ * {@link #JSONTokener(String) constructor} and {@link #nextValue} method. Example usage:
+ * 
+ * <pre>
+ * String json = "{" + "  \"query\": \"Pizza\", " + "  \"locations\": [ 94043, 90210 ] " + "}";
  *
  * JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
  * String query = object.getString("query");
- * JSONArray locations = object.getJSONArray("locations");</pre>
+ * JSONArray locations = object.getJSONArray("locations");
+ * </pre>
  *
- * <p>For best interoperability and performance use JSON that complies with
- * RFC 4627, such as that generated by {@link JSONStringer}. For legacy reasons
- * this parser is lenient, so a successful parse does not indicate that the
- * input string was valid JSON. All of the following syntax errors will be
- * ignored:
+ * <p>
+ * For best interoperability and performance use JSON that complies with RFC 4627, such as that
+ * generated by {@link JSONStringer}. For legacy reasons this parser is lenient, so a successful
+ * parse does not indicate that the input string was valid JSON. All of the following syntax errors
+ * will be ignored:
  * <ul>
- * <li>End of line comments starting with {@code //} or {@code #} and ending
- * with a newline character.
- * <li>C-style comments starting with {@code /*} and ending with
- * {@code *}{@code /}. Such comments may not be nested.
+ * <li>End of line comments starting with {@code //} or {@code #} and ending with a newline
+ * character.
+ * <li>C-style comments starting with {@code /*} and ending with {@code *}{@code /}. Such comments
+ * may not be nested.
  * <li>Strings that are unquoted or {@code 'single quoted'}.
  * <li>Hexadecimal integers prefixed with {@code 0x} or {@code 0X}.
  * <li>Octal integers prefixed with {@code 0}.
  * <li>Array elements separated by {@code ;}.
- * <li>Unnecessary array separators. These are interpreted as if null was the
- * omitted value.
+ * <li>Unnecessary array separators. These are interpreted as if null was the omitted value.
  * <li>Key-value pairs separated by {@code =} or {@code =>}.
  * <li>Key-value pairs separated by {@code ;}.
  * </ul>
  *
- * <p>Each tokener may be used to parse a single JSON string. 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 tokener may be used to parse a single JSON string. 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 JSONTokener {
 
-    /**
-     * The input JSON.
-     */
-    private final String in;
-
-    /**
-     * The index of the next character to be returned by {@link #next}. When
-     * the input is exhausted, this equals the input's length.
-     */
-    private int pos;
-
-    /**
-     * @param in JSON encoded string. Null is not permitted and will yield a
-     *           tokener that throws {@code NullPointerExceptions} when methods are
-     *           called.
-     */
-    public JSONTokener(String in) {
-        // consume an optional byte order mark (BOM) if it exists
-        if (in != null && in.startsWith("\ufeff")) {
-            in = in.substring(1);
-        }
-        this.in = in;
+  /**
+   * The input JSON.
+   */
+  private final String in;
+
+  /**
+   * The index of the next character to be returned by {@link #next}. When the input is exhausted,
+   * this equals the input's length.
+   */
+  private int pos;
+
+  /**
+   * @param in JSON encoded string. Null is not permitted and will yield a tokener that throws
+   *        {@code NullPointerExceptions} when methods are called.
+   */
+  public JSONTokener(String in) {
+    // consume an optional byte order mark (BOM) if it exists
+    if (in != null && in.startsWith("\ufeff")) {
+      in = in.substring(1);
     }
-
-    public JSONTokener(Reader input) throws IOException {
-        StringBuilder s = new StringBuilder();
-        char[] readBuf = new char[102400];
-        int n = input.read(readBuf);
-        while (n >= 0) {
-            s.append(readBuf, 0, n);
-            n = input.read(readBuf);
-        }
-        in = s.toString();
-        pos = 0;
+    this.in = in;
+  }
+
+  public JSONTokener(Reader input) throws IOException {
+    StringBuilder s = new StringBuilder();
+    char[] readBuf = new char[102400];
+    int n = input.read(readBuf);
+    while (n >= 0) {
+      s.append(readBuf, 0, n);
+      n = input.read(readBuf);
     }
-
-    /**
-     * Returns the next value from the input.
-     *
-     * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean,
-     * Integer, Long, Double or {@link JSONObject#NULL}.
-     * @throws JSONException if the input is malformed.
-     */
-    public Object nextValue() throws JSONException {
-        int c = nextCleanInternal();
-        switch (c) {
-            case -1:
-                throw syntaxError("End of input");
-
-            case '{':
-                return readObject();
-
-            case '[':
-                return readArray();
-
-            case '\'':
-            case '"':
-                return nextString((char) c);
+    in = s.toString();
+    pos = 0;
+  }
+
+  /**
+   * Returns the next value from the input.
+   *
+   * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double or
+   *         {@link JSONObject#NULL}.
+   * @throws JSONException if the input is malformed.
+   */
+  public Object nextValue() throws JSONException {
+    int c = nextCleanInternal();
+    switch (c) {
+      case -1:
+        throw syntaxError("End of input");
+
+      case '{':
+        return readObject();
+
+      case '[':
+        return readArray();
+
+      case '\'':
+      case '"':
+        return nextString((char) c);
+
+      default:
+        pos--;
+        return readLiteral();
+    }
+  }
+
+  private int nextCleanInternal() throws JSONException {
+    while (pos < in.length()) {
+      int c = in.charAt(pos++);
+      switch (c) {
+        case '\t':
+        case ' ':
+        case '\n':
+        case '\r':
+          continue;
+
+        case '/':
+          if (pos == in.length()) {
+            return c;
+          }
+
+          char peek = in.charAt(pos);
+          switch (peek) {
+            case '*':
+              // skip a /* c-style comment */
+              pos++;
+              int commentEnd = in.indexOf("*/", pos);
+              if (commentEnd == -1) {
+                throw syntaxError("Unterminated comment");
+              }
+              pos = commentEnd + 2;
+              continue;
+
+            case '/':
+              // skip a // end-of-line comment
+              pos++;
+              skipToEndOfLine();
+              continue;
 
             default:
-                pos--;
-                return readLiteral();
-        }
+              return c;
+          }
+
+        case '#':
+          /*
+           * Skip a # hash end-of-line comment. The JSON RFC doesn't specify this behavior, but it's
+           * required to parse existing documents. See http://b/2571423.
+           */
+          skipToEndOfLine();
+          continue;
+
+        default:
+          return c;
+      }
     }
 
-    private int nextCleanInternal() throws JSONException {
-        while (pos < in.length()) {
-            int c = in.charAt(pos++);
-            switch (c) {
-                case '\t':
-                case ' ':
-                case '\n':
-                case '\r':
-                    continue;
-
-                case '/':
-                    if (pos == in.length()) {
-                        return c;
-                    }
-
-                    char peek = in.charAt(pos);
-                    switch (peek) {
-                        case '*':
-                            // skip a /* c-style comment */
-                            pos++;
-                            int commentEnd = in.indexOf("*/", pos);
-                            if (commentEnd == -1) {
-                                throw syntaxError("Unterminated comment");
-                            }
-                            pos = commentEnd + 2;
-                            continue;
-
-                        case '/':
-                            // skip a // end-of-line comment
-                            pos++;
-                            skipToEndOfLine();
-                            continue;
-
-                        default:
-                            return c;
-                    }
-
-                case '#':
-                    /*
-                     * Skip a # hash end-of-line comment. The JSON RFC doesn't
-                     * specify this behavior, but it's required to parse
-                     * existing documents. See http://b/2571423.
-                     */
-                    skipToEndOfLine();
-                    continue;
-
-                default:
-                    return c;
-            }
-        }
-
-        return -1;
+    return -1;
+  }
+
+  /**
+   * Advances the position until after the next newline character. If the line is terminated by
+   * "\r\n", the '\n' must be consumed as whitespace by the caller.
+   */
+  private void skipToEndOfLine() {
+    for (; pos < in.length(); pos++) {
+      char c = in.charAt(pos);
+      if (c == '\r' || c == '\n') {
+        pos++;
+        break;
+      }
     }
-
-    /**
-     * Advances the position until after the next newline character. If the line
-     * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
-     * caller.
+  }
+
+  /**
+   * Returns the string up to but not including {@code quote}, unescaping any character escape
+   * sequences encountered along the way. The opening quote should have already been read. This
+   * consumes the closing quote, but does not include it in the returned string.
+   *
+   * @param quote either ' or ".
+   * @return The unescaped string.
+   * @throws JSONException if the string isn't terminated by a closing quote correctly.
+   */
+  public String nextString(char quote) throws JSONException {
+    /*
+     * For strings that are free of escape sequences, we can just extract the result as a substring
+     * of the input. But if we encounter an escape sequence, we need to use a StringBuilder to
+     * compose the result.
      */
-    private void skipToEndOfLine() {
-        for (; pos < in.length(); pos++) {
-            char c = in.charAt(pos);
-            if (c == '\r' || c == '\n') {
-                pos++;
-                break;
-            }
+    StringBuilder builder = null;
+
+    /* the index of the first character not yet appended to the builder. */
+    int start = pos;
+
+    while (pos < in.length()) {
+      int c = in.charAt(pos++);
+      if (c == quote) {
+        if (builder == null) {
+          // a new string avoids leaking memory
+          // noinspection RedundantStringConstructorCall
+          return new String(in.substring(start, pos - 1));
+        } else {
+          builder.append(in, start, pos - 1);
+          return builder.toString();
         }
-    }
+      }
 
-    /**
-     * Returns the string up to but not including {@code quote}, unescaping any
-     * character escape sequences encountered along the way. The opening quote
-     * should have already been read. This consumes the closing quote, but does
-     * not include it in the returned string.
-     *
-     * @param quote either ' or ".
-     * @return The unescaped string.
-     * @throws JSONException if the string isn't terminated by a closing quote correctly.
-     */
-    public String nextString(char quote) throws JSONException {
-        /*
-         * For strings that are free of escape sequences, we can just extract
-         * the result as a substring of the input. But if we encounter an escape
-         * sequence, we need to use a StringBuilder to compose the result.
-         */
-        StringBuilder builder = null;
-
-        /* the index of the first character not yet appended to the builder. */
-        int start = pos;
-
-        while (pos < in.length()) {
-            int c = in.charAt(pos++);
-            if (c == quote) {
-                if (builder == null) {
-                    // a new string avoids leaking memory
-                    //noinspection RedundantStringConstructorCall
-                    return new String(in.substring(start, pos - 1));
-                } else {
-                    builder.append(in, start, pos - 1);
-                    return builder.toString();
-                }
-            }
-
-            if (c == '\\') {
-                if (pos == in.length()) {
-                    throw syntaxError("Unterminated escape sequence");
-                }
-                if (builder == null) {
-                    builder = new StringBuilder();
-                }
-                builder.append(in, start, pos - 1);
-                builder.append(readEscapeCharacter());
-                start = pos;
-            }
+      if (c == '\\') {
+        if (pos == in.length()) {
+          throw syntaxError("Unterminated escape sequence");
         }
-
-        throw syntaxError("Unterminated string");
-    }
-
-    /**
-     * Unescapes the character identified by the character or characters that
-     * immediately follow a backslash. The backslash '\' should have already
-     * been read. This supports both unicode escapes "u000A" and two-character
-     * escapes "\n".
-     */
-    private char readEscapeCharacter() throws JSONException {
-        char escaped = in.charAt(pos++);
-        switch (escaped) {
-            case 'u':
-                if (pos + 4 > in.length()) {
-                    throw syntaxError("Unterminated escape sequence");
-                }
-                String hex = in.substring(pos, pos + 4);
-                pos += 4;
-                try {
-                    return (char) Integer.parseInt(hex, 16);
-                } catch (NumberFormatException nfe) {
-                    throw syntaxError("Invalid escape sequence: " + hex);
-                }
-
-            case 't':
-                return '\t';
-
-            case 'b':
-                return '\b';
-
-            case 'n':
-                return '\n';
-
-            case 'r':
-                return '\r';
-
-            case 'f':
-                return '\f';
-
-            case '\'':
-            case '"':
-            case '\\':
-            default:
-                return escaped;
+        if (builder == null) {
+          builder = new StringBuilder();
         }
+        builder.append(in, start, pos - 1);
+        builder.append(readEscapeCharacter());
+        start = pos;
+      }
     }
 
-    /**
-     * Reads a null, boolean, numeric or unquoted string literal value. Numeric
-     * values will be returned as an Integer, Long, or Double, in that order of
-     * preference.
-     */
-    private Object readLiteral() throws JSONException {
-        String literal = nextToInternal("{}[]/\\:,=;# \t\f");
-
-        if (literal.length() == 0) {
-            throw syntaxError("Expected literal value");
-        } else if ("null".equalsIgnoreCase(literal)) {
-            return JSONObject.NULL;
-        } else if ("true".equalsIgnoreCase(literal)) {
-            return Boolean.TRUE;
-        } else if ("false".equalsIgnoreCase(literal)) {
-            return Boolean.FALSE;
-        }
-
-        /* try to parse as an integral type... */
-        if (literal.indexOf('.') == -1) {
-            int base = 10;
-            String number = literal;
-            if (number.startsWith("0x") || number.startsWith("0X")) {
-                number = number.substring(2);
-                base = 16;
-            } else if (number.startsWith("0") && number.length() > 1) {
-                number = number.substring(1);
-                base = 8;
-            }
-            try {
-                long longValue = Long.parseLong(number, base);
-                if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
-                    return (int) longValue;
-                } else {
-                    return longValue;
-                }
-            } catch (NumberFormatException e) {
-                /*
-                 * This only happens for integral numbers greater than
-                 * Long.MAX_VALUE, numbers in exponential form (5e-10) and
-                 * unquoted strings. Fall through to try floating point.
-                 */
-            }
+    throw syntaxError("Unterminated string");
+  }
+
+  /**
+   * Unescapes the character identified by the character or characters that immediately follow a
+   * backslash. The backslash '\' should have already been read. This supports both unicode escapes
+   * "u000A" and two-character escapes "\n".
+   */
+  private char readEscapeCharacter() throws JSONException {
+    char escaped = in.charAt(pos++);
+    switch (escaped) {
+      case 'u':
+        if (pos + 4 > in.length()) {
+          throw syntaxError("Unterminated escape sequence");
         }
-
-        /* ...next try to parse as a floating point... */
+        String hex = in.substring(pos, pos + 4);
+        pos += 4;
         try {
-            return Double.valueOf(literal);
-        } catch (NumberFormatException ignored) {
+          return (char) Integer.parseInt(hex, 16);
+        } catch (NumberFormatException nfe) {
+          throw syntaxError("Invalid escape sequence: " + hex);
         }
 
-        /* ... finally give up. We have an unquoted string */
-        //noinspection RedundantStringConstructorCall
-        return new String(literal); // a new string avoids leaking memory
-    }
+      case 't':
+        return '\t';
 
-    /**
-     * Returns the string up to but not including any of the given characters or
-     * a newline character. This does not consume the excluded character.
-     */
-    private String nextToInternal(String excluded) {
-        int start = pos;
-        for (; pos < in.length(); pos++) {
-            char c = in.charAt(pos);
-            if (c == '\r' || c == '\n' || excluded.indexOf(c) != -1) {
-                return in.substring(start, pos);
-            }
-        }
-        return in.substring(start);
-    }
+      case 'b':
+        return '\b';
 
-    /**
-     * Reads a sequence of key/value pairs and the trailing closing brace '}' of
-     * an object. The opening brace '{' should have already been read.
-     */
-    private JSONObject readObject() throws JSONException {
-        JSONObject result = new JSONObject();
-
-        /* Peek to see if this is the empty object. */
-        int first = nextCleanInternal();
-        if (first == '}') {
-            return result;
-        } else if (first != -1) {
-            pos--;
-        }
+      case 'n':
+        return '\n';
 
-        while (true) {
-            Object name = nextValue();
-            if (!(name instanceof String)) {
-                if (name == null) {
-                    throw syntaxError("Names cannot be null");
-                } else {
-                    throw syntaxError("Names must be strings, but " + name
-                            + " is of type " + name.getClass().getName());
-                }
-            }
-
-            /*
-             * Expect the name/value separator to be either a colon ':', an
-             * equals sign '=', or an arrow "=>". The last two are bogus but we
-             * include them because that's what the original implementation did.
-             */
-            int separator = nextCleanInternal();
-            if (separator != ':' && separator != '=') {
-                throw syntaxError("Expected ':' after " + name);
-            }
-            if (pos < in.length() && in.charAt(pos) == '>') {
-                pos++;
-            }
-
-            result.put((String) name, nextValue());
-
-            switch (nextCleanInternal()) {
-                case '}':
-                    return result;
-                case ';':
-                case ',':
-                    continue;
-                default:
-                    throw syntaxError("Unterminated object");
-            }
-        }
-    }
+      case 'r':
+        return '\r';
 
-    /**
-     * Reads a sequence of values and the trailing closing brace ']' of an
-     * array. The opening brace '[' should have already been read. Note that
-     * "[]" yields an empty array, but "[,]" returns a two-element array
-     * equivalent to "[null,null]".
-     */
-    private JSONArray readArray() throws JSONException {
-        JSONArray result = new JSONArray();
-
-        /* to cover input that ends with ",]". */
-        boolean hasTrailingSeparator = false;
-
-        while (true) {
-            switch (nextCleanInternal()) {
-                case -1:
-                    throw syntaxError("Unterminated array");
-                case ']':
-                    if (hasTrailingSeparator) {
-                        result.put(null);
-                    }
-                    return result;
-                case ',':
-                case ';':
-                    /* A separator without a value first means "null". */
-                    result.put(null);
-                    hasTrailingSeparator = true;
-                    continue;
-                default:
-                    pos--;
-            }
-
-            result.put(nextValue());
-
-            switch (nextCleanInternal()) {
-                case ']':
-                    return result;
-                case ',':
-                case ';':
-                    hasTrailingSeparator = true;
-                    continue;
-                default:
-                    throw syntaxError("Unterminated array");
-            }
-        }
-    }
+      case 'f':
+        return '\f';
 
-    /**
-     * Returns an exception containing the given message plus the current
-     * position and the entire input string.
-     *
-     * @param message The message we want to include.
-     * @return An exception that we can throw.
-     */
-    public JSONException syntaxError(String message) {
-        return new JSONException(message + this);
+      case '\'':
+      case '"':
+      case '\\':
+      default:
+        return escaped;
     }
-
-    /**
-     * Returns the current position and the entire input string.
-     */
-    @Override
-    public String toString() {
-        // consistent with the original implementation
-        return " at character " + pos + " of " + in;
+  }
+
+  /**
+   * Reads a null, boolean, numeric or unquoted string literal value. Numeric values will be
+   * returned as an Integer, Long, or Double, in that order of preference.
+   */
+  private Object readLiteral() throws JSONException {
+    String literal = nextToInternal("{}[]/\\:,=;# \t\f");
+
+    if (literal.length() == 0) {
+      throw syntaxError("Expected literal value");
+    } else if ("null".equalsIgnoreCase(literal)) {
+      return JSONObject.NULL;
+    } else if ("true".equalsIgnoreCase(literal)) {
+      return Boolean.TRUE;
+    } else if ("false".equalsIgnoreCase(literal)) {
+      return Boolean.FALSE;
     }
 
-    /*
-     * Legacy APIs.
-     *
-     * None of the methods below are on the critical path of parsing JSON
-     * documents. They exist only because they were exposed by the original
-     * implementation and may be used by some clients.
-     */
-
-    /**
-     * Returns true until the input has been exhausted.
-     *
-     * @return true if more input exists.
-     */
-    public boolean more() {
-        return pos < in.length();
+    /* try to parse as an integral type... */
+    if (literal.indexOf('.') == -1) {
+      int base = 10;
+      String number = literal;
+      if (number.startsWith("0x") || number.startsWith("0X")) {
+        number = number.substring(2);
+        base = 16;
+      } else if (number.startsWith("0") && number.length() > 1) {
+        number = number.substring(1);
+        base = 8;
+      }
+      try {
+        long longValue = Long.parseLong(number, base);
+        if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
+          return (int) longValue;
+        } else {
+          return longValue;
+        }
+      } catch (NumberFormatException e) {
+        /*
+         * This only happens for integral numbers greater than Long.MAX_VALUE, numbers in
+         * exponential form (5e-10) and unquoted strings. Fall through to try floating point.
+         */
+      }
     }
 
-    /**
-     * Returns the next available character, or the null character '\0' if all
-     * input has been exhausted. The return value of this method is ambiguous
-     * for JSON strings that contain the character '\0'.
-     *
-     * @return the next character.
-     */
-    public char next() {
-        return pos < in.length() ? in.charAt(pos++) : '\0';
+    /* ...next try to parse as a floating point... */
+    try {
+      return Double.valueOf(literal);
+    } catch (NumberFormatException ignored) {
     }
 
-    /**
-     * Returns the next available character if it equals {@code c}. Otherwise an
-     * exception is thrown.
-     *
-     * @param c The character we are looking for.
-     * @return the next character.
-     * @throws JSONException If the next character isn't {@code c}
-     */
-    public char next(char c) throws JSONException {
-        char result = next();
-        if (result != c) {
-            throw syntaxError("Expected " + c + " but was " + result);
-        }
-        return result;
+    /* ... finally give up. We have an unquoted string */
+    // noinspection RedundantStringConstructorCall
+    return new String(literal); // a new string avoids leaking memory
+  }
+
+  /**
+   * Returns the string up to but not including any of the given characters or a newline character.
+   * This does not consume the excluded character.
+   */
+  private String nextToInternal(String excluded) {
+    int start = pos;
+    for (; pos < in.length(); pos++) {
+      char c = in.charAt(pos);
+      if (c == '\r' || c == '\n' || excluded.indexOf(c) != -1) {
+        return in.substring(start, pos);
+      }
     }
-
-    /**
-     * Returns the next character that is not whitespace and does not belong to
-     * a comment. If the input is exhausted before such a character can be
-     * found, the null character '\0' is returned. The return value of this
-     * method is ambiguous for JSON strings that contain the character '\0'.
-     *
-     * @return The next non-whitespace character.
-     * @throws JSONException Should not be possible.
-     */
-    public char nextClean() throws JSONException {
-        int nextCleanInt = nextCleanInternal();
-        return nextCleanInt == -1 ? '\0' : (char) nextCleanInt;
+    return in.substring(start);
+  }
+
+  /**
+   * Reads a sequence of key/value pairs and the trailing closing brace '}' of an object. The
+   * opening brace '{' should have already been read.
+   */
+  private JSONObject readObject() throws JSONException {
+    JSONObject result = new JSONObject();
+
+    /* Peek to see if this is the empty object. */
+    int first = nextCleanInternal();
+    if (first == '}') {
+      return result;
+    } else if (first != -1) {
+      pos--;
     }
 
-    /**
-     * Returns the next {@code length} characters of the input.
-     *
-     * <p>The returned string shares its backing character array with this
-     * tokener's input string. If a reference to the returned string may be held
-     * indefinitely, you should use {@code new String(result)} to copy it first
-     * to avoid memory leaks.
-     *
-     * @param length The desired number of characters to return.
-     * @return The next few characters.
-     * @throws JSONException if the remaining input is not long enough to
-     *                       satisfy this request.
-     */
-    public String next(int length) throws JSONException {
-        if (pos + length > in.length()) {
-            throw syntaxError(length + " is out of bounds");
+    while (true) {
+      Object name = nextValue();
+      if (!(name instanceof String)) {
+        if (name == null) {
+          throw syntaxError("Names cannot be null");
+        } else {
+          throw syntaxError(
+              "Names must be strings, but " + name + " is of type " + name.getClass().getName());
         }
-        String result = in.substring(pos, pos + length);
-        pos += length;
-        return result;
+      }
+
+      /*
+       * Expect the name/value separator to be either a colon ':', an equals sign '=', or an arrow
+       * "=>". The last two are bogus but we include them because that's what the original
+       * implementation did.
+       */
+      int separator = nextCleanInternal();
+      if (separator != ':' && separator != '=') {
+        throw syntaxError("Expected ':' after " + name);
+      }
+      if (pos < in.length() && in.charAt(pos) == '>') {
+        pos++;
+      }
+
+      result.put((String) name, nextValue());
+
+      switch (nextCleanInternal()) {
+        case '}':
+          return result;
+        case ';':
+        case ',':
+          continue;
+        default:
+          throw syntaxError("Unterminated object");
+      }
     }
-
-    /**
-     * Returns the {@link String#trim trimmed} string holding the characters up
-     * to but not including the first of:
-     * <ul>
-     * <li>any character in {@code excluded}
-     * <li>a newline character '\n'
-     * <li>a carriage return '\r'
-     * </ul>
-     *
-     * <p>The returned string shares its backing character array with this
-     * tokener's input string. If a reference to the returned string may be held
-     * indefinitely, you should use {@code new String(result)} to copy it first
-     * to avoid memory leaks.
-     *
-     * @param excluded The limiting string where the search should stop.
-     * @return a possibly-empty string
-     */
-    public String nextTo(String excluded) {
-        if (excluded == null) {
-            throw new NullPointerException("excluded == null");
-        }
-        return nextToInternal(excluded).trim();
+  }
+
+  /**
+   * Reads a sequence of values and the trailing closing brace ']' of an array. The opening brace
+   * '[' should have already been read. Note that "[]" yields an empty array, but "[,]" returns a
+   * two-element array equivalent to "[null,null]".
+   */
+  private JSONArray readArray() throws JSONException {
+    JSONArray result = new JSONArray();
+
+    /* to cover input that ends with ",]". */
+    boolean hasTrailingSeparator = false;
+
+    while (true) {
+      switch (nextCleanInternal()) {
+        case -1:
+          throw syntaxError("Unterminated array");
+        case ']':
+          if (hasTrailingSeparator) {
+            result.put(null);
+          }
+          return result;
+        case ',':
+        case ';':
+          /* A separator without a value first means "null". */
+          result.put(null);
+          hasTrailingSeparator = true;
+          continue;
+        default:
+          pos--;
+      }
+
+      result.put(nextValue());
+
+      switch (nextCleanInternal()) {
+        case ']':
+          return result;
+        case ',':
+        case ';':
+          hasTrailingSeparator = true;
+          continue;
+        default:
+          throw syntaxError("Unterminated array");
+      }
     }
-
-    /**
-     * Equivalent to {@code nextTo(String.valueOf(excluded))}.
-     *
-     * @param excluded The limiting character.
-     * @return a possibly-empty string
-     */
-    public String nextTo(char excluded) {
-        return nextToInternal(String.valueOf(excluded)).trim();
+  }
+
+  /**
+   * Returns an exception containing the given message plus the current position and the entire
+   * input string.
+   *
+   * @param message The message we want to include.
+   * @return An exception that we can throw.
+   */
+  public JSONException syntaxError(String message) {
+    return new JSONException(message + this);
+  }
+
+  /**
+   * Returns the current position and the entire input string.
+   */
+  @Override
+  public String toString() {
+    // consistent with the original implementation
+    return " at character " + pos + " of " + in;
+  }
+
+  /*
+   * Legacy APIs.
+   *
+   * None of the methods below are on the critical path of parsing JSON documents. They exist only
+   * because they were exposed by the original implementation and may be used by some clients.
+   */
+
+  /**
+   * Returns true until the input has been exhausted.
+   *
+   * @return true if more input exists.
+   */
+  public boolean more() {
+    return pos < in.length();
+  }
+
+  /**
+   * Returns the next available character, or the null character '\0' if all input has been
+   * exhausted. The return value of this method is ambiguous for JSON strings that contain the
+   * character '\0'.
+   *
+   * @return the next character.
+   */
+  public char next() {
+    return pos < in.length() ? in.charAt(pos++) : '\0';
+  }
+
+  /**
+   * Returns the next available character if it equals {@code c}. Otherwise an exception is thrown.
+   *
+   * @param c The character we are looking for.
+   * @return the next character.
+   * @throws JSONException If the next character isn't {@code c}
+   */
+  public char next(char c) throws JSONException {
+    char result = next();
+    if (result != c) {
+      throw syntaxError("Expected " + c + " but was " + result);
     }
-
-    /**
-     * Advances past all input up to and including the next occurrence of
-     * {@code thru}. If the remaining input doesn't contain {@code thru}, the
-     * input is exhausted.
-     *
-     * @param thru The string to skip over.
-     */
-    public void skipPast(String thru) {
-        int thruStart = in.indexOf(thru, pos);
-        pos = thruStart == -1 ? in.length() : (thruStart + thru.length());
+    return result;
+  }
+
+  /**
+   * Returns the next character that is not whitespace and does not belong to a comment. If the
+   * input is exhausted before such a character can be found, the null character '\0' is returned.
+   * The return value of this method is ambiguous for JSON strings that contain the character '\0'.
+   *
+   * @return The next non-whitespace character.
+   * @throws JSONException Should not be possible.
+   */
+  public char nextClean() throws JSONException {
+    int nextCleanInt = nextCleanInternal();
+    return nextCleanInt == -1 ? '\0' : (char) nextCleanInt;
+  }
+
+  /**
+   * Returns the next {@code length} characters of the input.
+   *
+   * <p>
+   * The returned string shares its backing character array with this tokener's input string. If a
+   * reference to the returned string may be held indefinitely, you should use
+   * {@code new String(result)} to copy it first to avoid memory leaks.
+   *
+   * @param length The desired number of characters to return.
+   * @return The next few characters.
+   * @throws JSONException if the remaining input is not long enough to satisfy this request.
+   */
+  public String next(int length) throws JSONException {
+    if (pos + length > in.length()) {
+      throw syntaxError(length + " is out of bounds");
     }
-
-    /**
-     * Advances past all input up to but not including the next occurrence of
-     * {@code to}. If the remaining input doesn't contain {@code to}, the input
-     * is unchanged.
-     *
-     * @param to The character we want to skip to.
-     * @return The value of {@code to} or null.
-     */
-    public char skipTo(char to) {
-        int index = in.indexOf(to, pos);
-        if (index != -1) {
-            pos = index;
-            return to;
-        } else {
-            return '\0';
-        }
+    String result = in.substring(pos, pos + length);
+    pos += length;
+    return result;
+  }
+
+  /**
+   * Returns the {@link String#trim trimmed} string holding the characters up to but not including
+   * the first of:
+   * <ul>
+   * <li>any character in {@code excluded}
+   * <li>a newline character '\n'
+   * <li>a carriage return '\r'
+   * </ul>
+   *
+   * <p>
+   * The returned string shares its backing character array with this tokener's input string. If a
+   * reference to the returned string may be held indefinitely, you should use
+   * {@code new String(result)} to copy it first to avoid memory leaks.
+   *
+   * @param excluded The limiting string where the search should stop.
+   * @return a possibly-empty string
+   */
+  public String nextTo(String excluded) {
+    if (excluded == null) {
+      throw new NullPointerException("excluded == null");
     }
-
-    /**
-     * Unreads the most recent character of input. If no input characters have
-     * been read, the input is unchanged.
-     */
-    public void back() {
-        if (--pos == -1) {
-            pos = 0;
-        }
+    return nextToInternal(excluded).trim();
+  }
+
+  /**
+   * Equivalent to {@code nextTo(String.valueOf(excluded))}.
+   *
+   * @param excluded The limiting character.
+   * @return a possibly-empty string
+   */
+  public String nextTo(char excluded) {
+    return nextToInternal(String.valueOf(excluded)).trim();
+  }
+
+  /**
+   * Advances past all input up to and including the next occurrence of {@code thru}. If the
+   * remaining input doesn't contain {@code thru}, the input is exhausted.
+   *
+   * @param thru The string to skip over.
+   */
+  public void skipPast(String thru) {
+    int thruStart = in.indexOf(thru, pos);
+    pos = thruStart == -1 ? in.length() : (thruStart + thru.length());
+  }
+
+  /**
+   * Advances past all input up to but not including the next occurrence of {@code to}. If the
+   * remaining input doesn't contain {@code to}, the input is unchanged.
+   *
+   * @param to The character we want to skip to.
+   * @return The value of {@code to} or null.
+   */
+  public char skipTo(char to) {
+    int index = in.indexOf(to, pos);
+    if (index != -1) {
+      pos = index;
+      return to;
+    } else {
+      return '\0';
     }
-
-    /**
-     * Returns the integer [0..15] value for the given hex character, or -1
-     * for non-hex input.
-     *
-     * @param hex a character in the ranges [0-9], [A-F] or [a-f]. Any other
-     *            character will yield a -1 result.
-     * @return The decoded integer.
-     */
-    public static int dehexchar(char hex) {
-        if (hex >= '0' && hex <= '9') {
-            return hex - '0';
-        } else if (hex >= 'A' && hex <= 'F') {
-            return hex - 'A' + 10;
-        } else if (hex >= 'a' && hex <= 'f') {
-            return hex - 'a' + 10;
-        } else {
-            return -1;
-        }
+  }
+
+  /**
+   * Unreads the most recent character of input. If no input characters have been read, the input is
+   * unchanged.
+   */
+  public void back() {
+    if (--pos == -1) {
+      pos = 0;
+    }
+  }
+
+  /**
+   * Returns the integer [0..15] value for the given hex character, or -1 for non-hex input.
+   *
+   * @param hex a character in the ranges [0-9], [A-F] or [a-f]. Any other character will yield a -1
+   *        result.
+   * @return The decoded integer.
+   */
+  public static int dehexchar(char hex) {
+    if (hex >= '0' && hex <= '9') {
+      return hex - '0';
+    } else if (hex >= 'A' && hex <= 'F') {
+      return hex - 'A' + 10;
+    } else if (hex >= 'a' && hex <= 'f') {
+      return hex - 'a' + 10;
+    } else {
+      return -1;
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/FileTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/FileTest.java b/geode-json/src/test/java/org/json/FileTest.java
index dae910b..36fcae9 100755
--- a/geode-json/src/test/java/org/json/FileTest.java
+++ b/geode-json/src/test/java/org/json/FileTest.java
@@ -8,280 +8,153 @@ import java.io.InputStreamReader;
 import java.util.Set;
 
 public class FileTest {
-    @Test
-    public void testFile() throws IOException, JSONException {
-        String ref = "[\n" +
-                "  {\n" +
-                "    \"_id\": \"58309f3bd307b72ae49a9b23\",\n" +
-                "    \"index\": 0,\n" +
-                "    \"guid\": \"5764ebd8-b333-469e-8d83-4eb5658f1566\",\n" +
-                "    \"isActive\": true,\n" +
-                "    \"balance\": \"$1,099.93\",\n" +
-                "    \"picture\": \"http://placehold.it/32x32\",\n" +
-                "    \"age\": 37,\n" +
-                "    \"eyeColor\": \"blue\",\n" +
-                "    \"name\": \"Barrera Wilkerson\",\n" +
-                "    \"gender\": \"male\",\n" +
-                "    \"company\": \"VURBO\",\n" +
-                "    \"email\": \"barrerawilkerson@vurbo.com\",\n" +
-                "    \"phone\": \"+1 (817) 429-2473\",\n" +
-                "    \"address\": \"522 Vanderveer Street, Detroit, Wyoming, 4320\",\n" +
-                "    \"about\": \"Et officia aute ullamco magna adipisicing non ut cupidatat cupidatat aliquip. Tempor occaecat ex ad dolore aliquip mollit ea esse ipsum. Est incididunt sunt commodo duis est. Reprehenderit in ut reprehenderit ad culpa ea fugiat et est adipisicing aliquip. Id mollit voluptate qui pariatur officia.\\r\\n\",\n" +
-                "    \"registered\": \"2016-06-29T08:54:14 +07:00\",\n" +
-                "    \"latitude\": -87.548434,\n" +
-                "    \"longitude\": 64.251242,\n" +
-                "    \"tags\": [\n" +
-                "      \"aliqua\",\n" +
-                "      \"ex\",\n" +
-                "      \"sit\",\n" +
-                "      \"magna\",\n" +
-                "      \"dolor\",\n" +
-                "      \"laborum\",\n" +
-                "      \"non\"\n" +
-                "    ],\n" +
-                "    \"friends\": [\n" +
-                "      {\n" +
-                "        \"id\": 0,\n" +
-                "        \"name\": \"Byers Pratt\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 1,\n" +
-                "        \"name\": \"Kennedy Contreras\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 2,\n" +
-                "        \"name\": \"Frazier Monroe\"\n" +
-                "      }\n" +
-                "    ],\n" +
-                "    \"greeting\": \"Hello, Barrera Wilkerson! You have 3 unread messages.\",\n" +
-                "    \"favoriteFruit\": \"banana\"\n" +
-                "  },\n" +
-                "  {\n" +
-                "    \"_id\": \"58309f3b1f506440093a41d1\",\n" +
-                "    \"index\": 1,\n" +
-                "    \"guid\": \"de1a6cc9-f8b3-426e-b68a-cc30e1fff3c1\",\n" +
-                "    \"isActive\": false,\n" +
-                "    \"balance\": \"$3,397.60\",\n" +
-                "    \"picture\": \"http://placehold.it/32x32\",\n" +
-                "    \"age\": 32,\n" +
-                "    \"eyeColor\": \"blue\",\n" +
-                "    \"name\": \"Trisha Morris\",\n" +
-                "    \"gender\": \"female\",\n" +
-                "    \"company\": \"AMTAP\",\n" +
-                "    \"email\": \"trishamorris@amtap.com\",\n" +
-                "    \"phone\": \"+1 (805) 423-3375\",\n" +
-                "    \"address\": \"495 Tampa Court, Libertytown, New Hampshire, 5177\",\n" +
-                "    \"about\": \"Elit culpa Lorem dolor sit laborum ut ullamco ullamco nostrud reprehenderit adipisicing eiusmod. Aliqua quis dolor esse sint. Dolore in excepteur laborum anim ut consectetur. Nisi officia est eu ex ex id. Ipsum duis ullamco ad ut labore dolor. In amet tempor deserunt ullamco velit eu fugiat.\\r\\n\",\n" +
-                "    \"registered\": \"2015-02-08T06:14:19 +08:00\",\n" +
-                "    \"latitude\": -81.956277,\n" +
-                "    \"longitude\": 143.685584,\n" +
-                "    \"tags\": [\n" +
-                "      \"cillum\",\n" +
-                "      \"ullamco\",\n" +
-                "      \"magna\",\n" +
-                "      \"cillum\",\n" +
-                "      \"voluptate\",\n" +
-                "      \"magna\",\n" +
-                "      \"exercitation\"\n" +
-                "    ],\n" +
-                "    \"friends\": [\n" +
-                "      {\n" +
-                "        \"id\": 0,\n" +
-                "        \"name\": \"Fuentes Stout\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 1,\n" +
-                "        \"name\": \"Violet Vargas\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 2,\n" +
-                "        \"name\": \"Schmidt Wilder\"\n" +
-                "      }\n" +
-                "    ],\n" +
-                "    \"greeting\": \"Hello, Trisha Morris! You have 4 unread messages.\",\n" +
-                "    \"favoriteFruit\": \"strawberry\"\n" +
-                "  },\n" +
-                "  {\n" +
-                "    \"_id\": \"58309f3beaef2f31339b3755\",\n" +
-                "    \"index\": 2,\n" +
-                "    \"guid\": \"0bf387b7-abc2-4828-becc-1269928f7c3d\",\n" +
-                "    \"isActive\": false,\n" +
-                "    \"balance\": \"$1,520.64\",\n" +
-                "    \"picture\": \"http://placehold.it/32x32\",\n" +
-                "    \"age\": 37,\n" +
-                "    \"eyeColor\": \"blue\",\n" +
-                "    \"name\": \"Deanna Santiago\",\n" +
-                "    \"gender\": \"female\",\n" +
-                "    \"company\": \"MEGALL\",\n" +
-                "    \"email\": \"deannasantiago@megall.com\",\n" +
-                "    \"phone\": \"+1 (916) 511-2291\",\n" +
-                "    \"address\": \"919 Fayette Street, Homestead, Utah, 8669\",\n" +
-                "    \"about\": \"Sit amet ex quis velit irure Lorem non quis aliquip dolor pariatur nulla Lorem officia. Deserunt officia sit velit labore sint nostrud elit aliquip labore ullamco consectetur id amet. Ullamco duis commodo sit incididunt. Fugiat consectetur ad incididunt officia. Sint cillum minim laborum laboris id cillum est exercitation in eiusmod qui.\\r\\n\",\n" +
-                "    \"registered\": \"2015-11-18T08:39:28 +08:00\",\n" +
-                "    \"latitude\": 79.105701,\n" +
-                "    \"longitude\": -146.901754,\n" +
-                "    \"tags\": [\n" +
-                "      \"non\",\n" +
-                "      \"ullamco\",\n" +
-                "      \"cillum\",\n" +
-                "      \"ipsum\",\n" +
-                "      \"amet\",\n" +
-                "      \"aliqua\",\n" +
-                "      \"aliquip\"\n" +
-                "    ],\n" +
-                "    \"friends\": [\n" +
-                "      {\n" +
-                "        \"id\": 0,\n" +
-                "        \"name\": \"Hanson Anderson\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 1,\n" +
-                "        \"name\": \"Pollard Soto\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 2,\n" +
-                "        \"name\": \"Barlow Campbell\"\n" +
-                "      }\n" +
-                "    ],\n" +
-                "    \"greeting\": \"Hello, Deanna Santiago! You have 7 unread messages.\",\n" +
-                "    \"favoriteFruit\": \"apple\"\n" +
-                "  },\n" +
-                "  {\n" +
-                "    \"_id\": \"58309f3b49a68ad01346f27f\",\n" +
-                "    \"index\": 3,\n" +
-                "    \"guid\": \"d29c0dcc-48fb-4ca4-a63b-b47c0e6d6398\",\n" +
-                "    \"isActive\": false,\n" +
-                "    \"balance\": \"$2,069.96\",\n" +
-                "    \"picture\": \"http://placehold.it/32x32\",\n" +
-                "    \"age\": 29,\n" +
-                "    \"eyeColor\": \"green\",\n" +
-                "    \"name\": \"Brooks Gates\",\n" +
-                "    \"gender\": \"male\",\n" +
-                "    \"company\": \"TERRAGEN\",\n" +
-                "    \"email\": \"brooksgates@terragen.com\",\n" +
-                "    \"phone\": \"+1 (875) 483-2224\",\n" +
-                "    \"address\": \"562 Noll Street, Kipp, Louisiana, 7659\",\n" +
-                "    \"about\": \"Reprehenderit laboris mollit nulla commodo quis laborum commodo. Laborum aliquip laboris officia minim ipsum laborum ipsum reprehenderit quis laboris est sint culpa. Culpa magna aute mollit exercitation.\\r\\n\",\n" +
-                "    \"registered\": \"2016-05-04T10:34:38 +07:00\",\n" +
-                "    \"latitude\": 72.77079,\n" +
-                "    \"longitude\": -134.291768,\n" +
-                "    \"tags\": [\n" +
-                "      \"est\",\n" +
-                "      \"sunt\",\n" +
-                "      \"laboris\",\n" +
-                "      \"ea\",\n" +
-                "      \"proident\",\n" +
-                "      \"aute\",\n" +
-                "      \"excepteur\"\n" +
-                "    ],\n" +
-                "    \"friends\": [\n" +
-                "      {\n" +
-                "        \"id\": 0,\n" +
-                "        \"name\": \"Roxanne Morgan\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 1,\n" +
-                "        \"name\": \"Tamara Kelly\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 2,\n" +
-                "        \"name\": \"Cleveland Bush\"\n" +
-                "      }\n" +
-                "    ],\n" +
-                "    \"greeting\": \"Hello, Brooks Gates! You have 1 unread messages.\",\n" +
-                "    \"favoriteFruit\": \"banana\"\n" +
-                "  },\n" +
-                "  {\n" +
-                "    \"_id\": \"58309f3be746700e9af9a645\",\n" +
-                "    \"index\": 4,\n" +
-                "    \"guid\": \"54382bd6-c476-469d-9e1c-e546f959db51\",\n" +
-                "    \"isActive\": true,\n" +
-                "    \"balance\": \"$2,012.57\",\n" +
-                "    \"picture\": \"http://placehold.it/32x32\",\n" +
-                "    \"age\": 40,\n" +
-                "    \"eyeColor\": \"brown\",\n" +
-                "    \"name\": \"Jackie Thomas\",\n" +
-                "    \"gender\": \"female\",\n" +
-                "    \"company\": \"HINWAY\",\n" +
-                "    \"email\": \"jackiethomas@hinway.com\",\n" +
-                "    \"phone\": \"+1 (843) 470-2096\",\n" +
-                "    \"address\": \"910 Emerson Place, Gwynn, Federated States Of Micronesia, 4688\",\n" +
-                "    \"about\": \"Id cupidatat laboris elit est eiusmod esse nostrud. Ex commodo nisi voluptate est nisi laborum officia sint incididunt pariatur qui deserunt ullamco. Fugiat proident magna ipsum sit sint id adipisicing sit nostrud labore sit officia. Eiusmod exercitation non enim excepteur amet irure ullamco consectetur cupidatat proident Lorem reprehenderit aliquip. Veniam esse dolor Lorem incididunt proident officia enim in incididunt culpa. Mollit voluptate commodo aliquip anim ipsum nostrud ut labore enim labore qui do minim incididunt. Quis irure proident voluptate nisi qui sunt aute duis irure.\\r\\n\",\n" +
-                "    \"registered\": \"2014-08-03T09:21:43 +07:00\",\n" +
-                "    \"latitude\": 84.871256,\n" +
-                "    \"longitude\": 2.043339,\n" +
-                "    \"tags\": [\n" +
-                "      \"tempor\",\n" +
-                "      \"ut\",\n" +
-                "      \"deserunt\",\n" +
-                "      \"esse\",\n" +
-                "      \"nostrud\",\n" +
-                "      \"dolore\",\n" +
-                "      \"ex\"\n" +
-                "    ],\n" +
-                "    \"friends\": [\n" +
-                "      {\n" +
-                "        \"id\": 0,\n" +
-                "        \"name\": \"Lois Walters\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 1,\n" +
-                "        \"name\": \"Brewer Buchanan\"\n" +
-                "      },\n" +
-                "      {\n" +
-                "        \"id\": 2,\n" +
-                "        \"name\": \"Mccormick Fleming\"\n" +
-                "      }\n" +
-                "    ],\n" +
-                "    \"greeting\": \"Hello, Jackie Thomas! You have 2 unread messages.\",\n" +
-                "    \"favoriteFruit\": \"banana\"\n" +
-                "  }\n" +
-                "]";
+  @Test
+  public void testFile() throws IOException, JSONException {
+    String ref = "[\n" + "  {\n" + "    \"_id\": \"58309f3bd307b72ae49a9b23\",\n"
+        + "    \"index\": 0,\n" + "    \"guid\": \"5764ebd8-b333-469e-8d83-4eb5658f1566\",\n"
+        + "    \"isActive\": true,\n" + "    \"balance\": \"$1,099.93\",\n"
+        + "    \"picture\": \"http://placehold.it/32x32\",\n" + "    \"age\": 37,\n"
+        + "    \"eyeColor\": \"blue\",\n" + "    \"name\": \"Barrera Wilkerson\",\n"
+        + "    \"gender\": \"male\",\n" + "    \"company\": \"VURBO\",\n"
+        + "    \"email\": \"barrerawilkerson@vurbo.com\",\n"
+        + "    \"phone\": \"+1 (817) 429-2473\",\n"
+        + "    \"address\": \"522 Vanderveer Street, Detroit, Wyoming, 4320\",\n"
+        + "    \"about\": \"Et officia aute ullamco magna adipisicing non ut cupidatat cupidatat aliquip. Tempor occaecat ex ad dolore aliquip mollit ea esse ipsum. Est incididunt sunt commodo duis est. Reprehenderit in ut reprehenderit ad culpa ea fugiat et est adipisicing aliquip. Id mollit voluptate qui pariatur officia.\\r\\n\",\n"
+        + "    \"registered\": \"2016-06-29T08:54:14 +07:00\",\n"
+        + "    \"latitude\": -87.548434,\n" + "    \"longitude\": 64.251242,\n"
+        + "    \"tags\": [\n" + "      \"aliqua\",\n" + "      \"ex\",\n" + "      \"sit\",\n"
+        + "      \"magna\",\n" + "      \"dolor\",\n" + "      \"laborum\",\n" + "      \"non\"\n"
+        + "    ],\n" + "    \"friends\": [\n" + "      {\n" + "        \"id\": 0,\n"
+        + "        \"name\": \"Byers Pratt\"\n" + "      },\n" + "      {\n"
+        + "        \"id\": 1,\n" + "        \"name\": \"Kennedy Contreras\"\n" + "      },\n"
+        + "      {\n" + "        \"id\": 2,\n" + "        \"name\": \"Frazier Monroe\"\n"
+        + "      }\n" + "    ],\n"
+        + "    \"greeting\": \"Hello, Barrera Wilkerson! You have 3 unread messages.\",\n"
+        + "    \"favoriteFruit\": \"banana\"\n" + "  },\n" + "  {\n"
+        + "    \"_id\": \"58309f3b1f506440093a41d1\",\n" + "    \"index\": 1,\n"
+        + "    \"guid\": \"de1a6cc9-f8b3-426e-b68a-cc30e1fff3c1\",\n" + "    \"isActive\": false,\n"
+        + "    \"balance\": \"$3,397.60\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
+        + "    \"age\": 32,\n" + "    \"eyeColor\": \"blue\",\n"
+        + "    \"name\": \"Trisha Morris\",\n" + "    \"gender\": \"female\",\n"
+        + "    \"company\": \"AMTAP\",\n" + "    \"email\": \"trishamorris@amtap.com\",\n"
+        + "    \"phone\": \"+1 (805) 423-3375\",\n"
+        + "    \"address\": \"495 Tampa Court, Libertytown, New Hampshire, 5177\",\n"
+        + "    \"about\": \"Elit culpa Lorem dolor sit laborum ut ullamco ullamco nostrud reprehenderit adipisicing eiusmod. Aliqua quis dolor esse sint. Dolore in excepteur laborum anim ut consectetur. Nisi officia est eu ex ex id. Ipsum duis ullamco ad ut labore dolor. In amet tempor deserunt ullamco velit eu fugiat.\\r\\n\",\n"
+        + "    \"registered\": \"2015-02-08T06:14:19 +08:00\",\n"
+        + "    \"latitude\": -81.956277,\n" + "    \"longitude\": 143.685584,\n"
+        + "    \"tags\": [\n" + "      \"cillum\",\n" + "      \"ullamco\",\n"
+        + "      \"magna\",\n" + "      \"cillum\",\n" + "      \"voluptate\",\n"
+        + "      \"magna\",\n" + "      \"exercitation\"\n" + "    ],\n" + "    \"friends\": [\n"
+        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Fuentes Stout\"\n"
+        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
+        + "        \"name\": \"Violet Vargas\"\n" + "      },\n" + "      {\n"
+        + "        \"id\": 2,\n" + "        \"name\": \"Schmidt Wilder\"\n" + "      }\n"
+        + "    ],\n" + "    \"greeting\": \"Hello, Trisha Morris! You have 4 unread messages.\",\n"
+        + "    \"favoriteFruit\": \"strawberry\"\n" + "  },\n" + "  {\n"
+        + "    \"_id\": \"58309f3beaef2f31339b3755\",\n" + "    \"index\": 2,\n"
+        + "    \"guid\": \"0bf387b7-abc2-4828-becc-1269928f7c3d\",\n" + "    \"isActive\": false,\n"
+        + "    \"balance\": \"$1,520.64\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
+        + "    \"age\": 37,\n" + "    \"eyeColor\": \"blue\",\n"
+        + "    \"name\": \"Deanna Santiago\",\n" + "    \"gender\": \"female\",\n"
+        + "    \"company\": \"MEGALL\",\n" + "    \"email\": \"deannasantiago@megall.com\",\n"
+        + "    \"phone\": \"+1 (916) 511-2291\",\n"
+        + "    \"address\": \"919 Fayette Street, Homestead, Utah, 8669\",\n"
+        + "    \"about\": \"Sit amet ex quis velit irure Lorem non quis aliquip dolor pariatur nulla Lorem officia. Deserunt officia sit velit labore sint nostrud elit aliquip labore ullamco consectetur id amet. Ullamco duis commodo sit incididunt. Fugiat consectetur ad incididunt officia. Sint cillum minim laborum laboris id cillum est exercitation in eiusmod qui.\\r\\n\",\n"
+        + "    \"registered\": \"2015-11-18T08:39:28 +08:00\",\n" + "    \"latitude\": 79.105701,\n"
+        + "    \"longitude\": -146.901754,\n" + "    \"tags\": [\n" + "      \"non\",\n"
+        + "      \"ullamco\",\n" + "      \"cillum\",\n" + "      \"ipsum\",\n"
+        + "      \"amet\",\n" + "      \"aliqua\",\n" + "      \"aliquip\"\n" + "    ],\n"
+        + "    \"friends\": [\n" + "      {\n" + "        \"id\": 0,\n"
+        + "        \"name\": \"Hanson Anderson\"\n" + "      },\n" + "      {\n"
+        + "        \"id\": 1,\n" + "        \"name\": \"Pollard Soto\"\n" + "      },\n"
+        + "      {\n" + "        \"id\": 2,\n" + "        \"name\": \"Barlow Campbell\"\n"
+        + "      }\n" + "    ],\n"
+        + "    \"greeting\": \"Hello, Deanna Santiago! You have 7 unread messages.\",\n"
+        + "    \"favoriteFruit\": \"apple\"\n" + "  },\n" + "  {\n"
+        + "    \"_id\": \"58309f3b49a68ad01346f27f\",\n" + "    \"index\": 3,\n"
+        + "    \"guid\": \"d29c0dcc-48fb-4ca4-a63b-b47c0e6d6398\",\n" + "    \"isActive\": false,\n"
+        + "    \"balance\": \"$2,069.96\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
+        + "    \"age\": 29,\n" + "    \"eyeColor\": \"green\",\n"
+        + "    \"name\": \"Brooks Gates\",\n" + "    \"gender\": \"male\",\n"
+        + "    \"company\": \"TERRAGEN\",\n" + "    \"email\": \"brooksgates@terragen.com\",\n"
+        + "    \"phone\": \"+1 (875) 483-2224\",\n"
+        + "    \"address\": \"562 Noll Street, Kipp, Louisiana, 7659\",\n"
+        + "    \"about\": \"Reprehenderit laboris mollit nulla commodo quis laborum commodo. Laborum aliquip laboris officia minim ipsum laborum ipsum reprehenderit quis laboris est sint culpa. Culpa magna aute mollit exercitation.\\r\\n\",\n"
+        + "    \"registered\": \"2016-05-04T10:34:38 +07:00\",\n" + "    \"latitude\": 72.77079,\n"
+        + "    \"longitude\": -134.291768,\n" + "    \"tags\": [\n" + "      \"est\",\n"
+        + "      \"sunt\",\n" + "      \"laboris\",\n" + "      \"ea\",\n" + "      \"proident\",\n"
+        + "      \"aute\",\n" + "      \"excepteur\"\n" + "    ],\n" + "    \"friends\": [\n"
+        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Roxanne Morgan\"\n"
+        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
+        + "        \"name\": \"Tamara Kelly\"\n" + "      },\n" + "      {\n"
+        + "        \"id\": 2,\n" + "        \"name\": \"Cleveland Bush\"\n" + "      }\n"
+        + "    ],\n" + "    \"greeting\": \"Hello, Brooks Gates! You have 1 unread messages.\",\n"
+        + "    \"favoriteFruit\": \"banana\"\n" + "  },\n" + "  {\n"
+        + "    \"_id\": \"58309f3be746700e9af9a645\",\n" + "    \"index\": 4,\n"
+        + "    \"guid\": \"54382bd6-c476-469d-9e1c-e546f959db51\",\n" + "    \"isActive\": true,\n"
+        + "    \"balance\": \"$2,012.57\",\n" + "    \"picture\": \"http://placehold.it/32x32\",\n"
+        + "    \"age\": 40,\n" + "    \"eyeColor\": \"brown\",\n"
+        + "    \"name\": \"Jackie Thomas\",\n" + "    \"gender\": \"female\",\n"
+        + "    \"company\": \"HINWAY\",\n" + "    \"email\": \"jackiethomas@hinway.com\",\n"
+        + "    \"phone\": \"+1 (843) 470-2096\",\n"
+        + "    \"address\": \"910 Emerson Place, Gwynn, Federated States Of Micronesia, 4688\",\n"
+        + "    \"about\": \"Id cupidatat laboris elit est eiusmod esse nostrud. Ex commodo nisi voluptate est nisi laborum officia sint incididunt pariatur qui deserunt ullamco. Fugiat proident magna ipsum sit sint id adipisicing sit nostrud labore sit officia. Eiusmod exercitation non enim excepteur amet irure ullamco consectetur cupidatat proident Lorem reprehenderit aliquip. Veniam esse dolor Lorem incididunt proident officia enim in incididunt culpa. Mollit voluptate commodo aliquip anim ipsum nostrud ut labore enim labore qui do minim incididunt. Quis irure proident voluptate nisi qui sunt aute duis irure.\\r\\n\",\n"
+        + "    \"registered\": \"2014-08-03T09:21:43 +07:00\",\n" + "    \"latitude\": 84.871256,\n"
+        + "    \"longitude\": 2.043339,\n" + "    \"tags\": [\n" + "      \"tempor\",\n"
+        + "      \"ut\",\n" + "      \"deserunt\",\n" + "      \"esse\",\n" + "      \"nostrud\",\n"
+        + "      \"dolore\",\n" + "      \"ex\"\n" + "    ],\n" + "    \"friends\": [\n"
+        + "      {\n" + "        \"id\": 0,\n" + "        \"name\": \"Lois Walters\"\n"
+        + "      },\n" + "      {\n" + "        \"id\": 1,\n"
+        + "        \"name\": \"Brewer Buchanan\"\n" + "      },\n" + "      {\n"
+        + "        \"id\": 2,\n" + "        \"name\": \"Mccormick Fleming\"\n" + "      }\n"
+        + "    ],\n" + "    \"greeting\": \"Hello, Jackie Thomas! You have 2 unread messages.\",\n"
+        + "    \"favoriteFruit\": \"banana\"\n" + "  }\n" + "]";
 
-        JSONArray x1 = (JSONArray) new JSONTokener(new InputStreamReader(this.getClass().getResourceAsStream("/sample-01.json"))).nextValue();
-        JSONArray x2 = (JSONArray) new JSONTokener(ref).nextValue();
+    JSONArray x1 = (JSONArray) new JSONTokener(
+        new InputStreamReader(this.getClass().getResourceAsStream("/sample-01.json"))).nextValue();
+    JSONArray x2 = (JSONArray) new JSONTokener(ref).nextValue();
 
-        Assert.assertTrue(jsonEquals(x1, x2));
-    }
+    Assert.assertTrue(jsonEquals(x1, x2));
+  }
 
-    private boolean jsonEquals(JSONArray x1, JSONArray x2) throws JSONException {
-        if (x1.length() != x2.length()) {
-            return false;
-        }
+  private boolean jsonEquals(JSONArray x1, JSONArray x2) throws JSONException {
+    if (x1.length() != x2.length()) {
+      return false;
+    }
 
-        for (int i = 0; i < x1.length(); i++) {
-            Object element1 = x1.get(i);
-            Object element2 = x2.get(i);
-            if (!jsonEquals(element1, element2)) {
-                return false;
-            }
-        }
-        return true;
+    for (int i = 0; i < x1.length(); i++) {
+      Object element1 = x1.get(i);
+      Object element2 = x2.get(i);
+      if (!jsonEquals(element1, element2)) {
+        return false;
+      }
     }
+    return true;
+  }
 
-    private boolean jsonEquals(JSONObject x1, JSONObject x2) throws JSONException {
-        if (x1.length() != x2.length()) {
-            return false;
-        }
-        Set<String> names = x1.keySet();
-        for (String name : names) {
-            if (!jsonEquals(x1.get(name), x2.get(name))) {
-                return false;
-            }
-        }
-        return true;
+  private boolean jsonEquals(JSONObject x1, JSONObject x2) throws JSONException {
+    if (x1.length() != x2.length()) {
+      return false;
+    }
+    Set<String> names = x1.keySet();
+    for (String name : names) {
+      if (!jsonEquals(x1.get(name), x2.get(name))) {
+        return false;
+      }
     }
+    return true;
+  }
 
-    private boolean jsonEquals(Object element1, Object element2) throws JSONException {
-        if (!element1.getClass().equals(element2.getClass())) {
-            return false;
-        }
-        if (element1 instanceof JSONObject) {
-            return jsonEquals((JSONObject) element1, (JSONObject) element2);
-        }
-        if (element1 instanceof JSONArray) {
-            return jsonEquals((JSONArray) element1, (JSONArray) element2);
-        }
-        return element1.equals(element2);
+  private boolean jsonEquals(Object element1, Object element2) throws JSONException {
+    if (!element1.getClass().equals(element2.getClass())) {
+      return false;
+    }
+    if (element1 instanceof JSONObject) {
+      return jsonEquals((JSONObject) element1, (JSONObject) element2);
+    }
+    if (element1 instanceof JSONArray) {
+      return jsonEquals((JSONArray) element1, (JSONArray) element2);
     }
+    return element1.equals(element2);
+  }
 }


[32/34] geode git commit: GEODE-1995: Removed ReliableMessageQueue, ReliableMessageQueueFactory, ReliableMessageQueueFactoryImpl and it's usage in the code from GemfireCacheImpl and DistributedRegion.

Posted by kl...@apache.org.
GEODE-1995: Removed ReliableMessageQueue, ReliableMessageQueueFactory, ReliableMessageQueueFactoryImpl and
it's usage in the code from GemfireCacheImpl and DistributedRegion.

GEODE-1995: Addressing Review Comments.
  Removed ReliableDistributionData
  CacheOperationMessage does not required now to implement ReliableDistributionData, as it is removed
  Removed all reference of getOperations and getOperationCount
  AbstractRegion#handleReliableDistribution does not use ReliableDistributionData removed the same.
  Removed SendQueueOperation
  Removed sendQueue from DistributedRegion
  Cleanup LocalizedStrings
  Removed SEND_QUEUE_MESSAGE from DataSerializableFixedID and DSFIDFactory


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/5ec0d470
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/5ec0d470
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/5ec0d470

Branch: refs/heads/GEODE-4160-mockito
Commit: 5ec0d470f25ec4cb68dd7c5c31791eecb90b2548
Parents: b5fd6b5
Author: adongre <ad...@apache.org>
Authored: Tue Dec 13 12:50:31 2016 +0530
Committer: adongre <ad...@apache.org>
Committed: Tue Feb 28 12:35:38 2017 +0530

----------------------------------------------------------------------
 .../org/apache/geode/internal/DSFIDFactory.java |   2 -
 .../geode/internal/DataSerializableFixedID.java |   1 -
 .../geode/internal/cache/AbstractRegion.java    |   4 +-
 .../geode/internal/cache/DestroyOperation.java  |   6 -
 .../cache/DistributedCacheOperation.java        |  27 +-
 .../cache/DistributedPutAllOperation.java       |  27 --
 .../geode/internal/cache/DistributedRegion.java |  70 +-----
 .../cache/DistributedRemoveAllOperation.java    |  15 --
 .../geode/internal/cache/GemFireCacheImpl.java  |  27 --
 .../internal/cache/InvalidateOperation.java     |   8 -
 .../cache/ReliableDistributionData.java         |  41 ----
 .../internal/cache/ReliableMessageQueue.java    |  69 ------
 .../cache/ReliableMessageQueueFactory.java      |  41 ----
 .../cache/ReliableMessageQueueFactoryImpl.java  | 246 -------------------
 .../internal/cache/SendQueueOperation.java      | 190 --------------
 .../geode/internal/cache/TXCommitMessage.java   |  41 +---
 .../cache/UpdateEntryVersionOperation.java      |   6 -
 .../geode/internal/cache/UpdateOperation.java   |  13 -
 .../cache/wan/serial/BatchDestroyOperation.java |   7 -
 .../geode/internal/i18n/LocalizedStrings.java   |   6 -
 20 files changed, 9 insertions(+), 838 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java b/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
index 5c18639..c02dc47 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DSFIDFactory.java
@@ -251,7 +251,6 @@ import org.apache.geode.internal.cache.RemoteRegionOperation.RemoteRegionOperati
 import org.apache.geode.internal.cache.RemoteRemoveAllMessage;
 import org.apache.geode.internal.cache.RoleEventImpl;
 import org.apache.geode.internal.cache.SearchLoadAndWriteProcessor;
-import org.apache.geode.internal.cache.SendQueueOperation.SendQueueMessage;
 import org.apache.geode.internal.cache.ServerPingMessage;
 import org.apache.geode.internal.cache.StateFlushOperation.StateMarkerMessage;
 import org.apache.geode.internal.cache.StateFlushOperation.StateStabilizationMessage;
@@ -667,7 +666,6 @@ public final class DSFIDFactory implements DataSerializableFixedID {
     registerDSFID(CLEAR_REGION_MESSAGE, ClearRegionMessage.class);
     registerDSFID(TOMBSTONE_MESSAGE, TombstoneMessage.class);
     registerDSFID(INVALIDATE_REGION_MESSAGE, InvalidateRegionMessage.class);
-    registerDSFID(SEND_QUEUE_MESSAGE, SendQueueMessage.class);
     registerDSFID(STATE_MARKER_MESSAGE, StateMarkerMessage.class);
     registerDSFID(STATE_STABILIZATION_MESSAGE, StateStabilizationMessage.class);
     registerDSFID(STATE_STABILIZED_MESSAGE, StateStabilizedMessage.class);

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
index 4e45646..457af2f 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DataSerializableFixedID.java
@@ -160,7 +160,6 @@ public interface DataSerializableFixedID extends SerializationVersions {
   public static final byte PUT_ALL_MESSAGE = -84;
   public static final byte CLEAR_REGION_MESSAGE = -83;
   public static final byte INVALIDATE_REGION_MESSAGE = -82;
-  public static final byte SEND_QUEUE_MESSAGE = -81;
   public static final byte STATE_MARKER_MESSAGE = -80;
   public static final byte STATE_STABILIZATION_MESSAGE = -79;
   public static final byte STATE_STABILIZED_MESSAGE = -78;

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
index fe77578..7dffee2 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
@@ -1719,15 +1719,13 @@ public abstract class AbstractRegion implements Region, RegionAttributes, Attrib
    * Makes sure that the data was distributed to every required role. If it was not it either queues
    * the data for later delivery or it throws an exception.
    *
-   * @param data the data that needs to be reliably distributed
    * @param successfulRecipients the successful recipients
    * @throws RoleException if a required role was not sent the message and the LossAction is either
    *         NO_ACCESS or LIMITED_ACCESS.
    * @since GemFire 5.0
    *
    */
-  protected void handleReliableDistribution(ReliableDistributionData data,
-      Set successfulRecipients) {
+  protected void handleReliableDistribution(Set successfulRecipients) {
     // do nothing by default
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyOperation.java
index a3d9376..5132ec0 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DestroyOperation.java
@@ -199,12 +199,6 @@ public class DestroyOperation extends DistributedCacheOperation {
     }
 
     @Override
-    public List getOperations() {
-      return Collections.singletonList(new QueuedOperation(getOperation(), this.key, null, null,
-          DistributedCacheOperation.DESERIALIZATION_POLICY_NONE, this.callbackArg));
-    }
-
-    @Override
     public ConflationKey getConflationKey() {
       if (!super.regionAllowsConflation || getProcessorId() != 0) {
         // if the publisher's region attributes do not support conflation

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedCacheOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedCacheOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedCacheOperation.java
index e4658b4..bded899 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedCacheOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedCacheOperation.java
@@ -365,13 +365,7 @@ public abstract class DistributedCacheOperation {
         if (!reliableOp || region.isNoDistributionOk()) {
           // nothing needs be done in this case
         } else {
-          // create the message so it can be passed to
-          // handleReliableDistribution
-          // for queuing
-          CacheOperationMessage msg = createMessage();
-          initMessage(msg, null);
-          msg.setRecipients(recipients); // it is going to no one
-          region.handleReliableDistribution(msg, Collections.EMPTY_SET);
+          region.handleReliableDistribution(Collections.EMPTY_SET);
         }
 
         /** compute local client routing before waiting for an ack only for a bucket */
@@ -625,7 +619,7 @@ public abstract class DistributedCacheOperation {
           if (departedMembers != null) {
             successfulRecips.removeAll(departedMembers);
           }
-          region.handleReliableDistribution(msg, successfulRecips);
+          region.handleReliableDistribution(successfulRecips);
         }
       }
 
@@ -864,7 +858,7 @@ public abstract class DistributedCacheOperation {
   }
 
   public static abstract class CacheOperationMessage extends SerialDistributionMessage
-      implements MessageWithReply, DirectReplyMessage, ReliableDistributionData, OldValueImporter {
+      implements MessageWithReply, DirectReplyMessage, OldValueImporter {
 
     protected final static short POSSIBLE_DUPLICATE_MASK = POS_DUP;
     protected final static short OLD_VALUE_MASK = DistributionMessage.UNRESERVED_FLAGS_START;
@@ -1482,21 +1476,6 @@ public abstract class DistributedCacheOperation {
       return this.directAck;
     }
 
-    // ////////////////////////////////////////////////////////////////////
-    // ReliableDistributionData methods
-    // ////////////////////////////////////////////////////////////////////
-
-    public int getOperationCount() {
-      return 1;
-    }
-
-    public List getOperations() {
-      byte noDeserialize = DistributedCacheOperation.DESERIALIZATION_POLICY_NONE;
-      QueuedOperation qOp =
-          new QueuedOperation(getOperation(), null, null, null, noDeserialize, this.callbackArg);
-      return Collections.singletonList(qOp);
-    }
-
     public void setSendDelta(boolean sendDelta) {
       this.sendDelta = sendDelta;
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedPutAllOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedPutAllOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedPutAllOperation.java
index 4082a29..61542c4 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedPutAllOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedPutAllOperation.java
@@ -1261,11 +1261,6 @@ public class DistributedPutAllOperation extends AbstractUpdateOperation {
       return s;
     }
 
-    @Override
-    public int getOperationCount() {
-      return this.putAllDataSize;
-    }
-
     public ClientProxyMembershipID getContext() {
       return this.context;
     }
@@ -1274,27 +1269,5 @@ public class DistributedPutAllOperation extends AbstractUpdateOperation {
       return this.putAllData;
     }
 
-    @Override
-    public List getOperations() {
-      QueuedOperation[] ops = new QueuedOperation[getOperationCount()];
-      for (int i = 0; i < ops.length; i++) {
-        PutAllEntryData entry = this.putAllData[i];
-        byte[] valueBytes = null;
-        Object valueObj = null;
-        Object v = entry.getValue();
-        byte deserializationPolicy;
-        if (v instanceof CachedDeserializable) {
-          deserializationPolicy = DESERIALIZATION_POLICY_LAZY;
-          valueBytes = ((CachedDeserializable) v).getSerializedValue();
-        } else {
-          deserializationPolicy = DESERIALIZATION_POLICY_NONE;
-          valueBytes = (byte[]) v;
-        }
-
-        ops[i] = new QueuedOperation(entry.getOp(), entry.getKey(), valueBytes, valueObj,
-            deserializationPolicy, this.callbackArg);
-      }
-      return Arrays.asList(ops);
-    }
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRegion.java
index 1aaf6c3..cc6ccf7 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRegion.java
@@ -110,13 +110,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
   private final boolean requiresReliabilityCheck;
 
   /**
-   * Provides a queue for reliable message delivery
-   * 
-   * @since GemFire 5.0
-   */
-  protected final ReliableMessageQueue rmq;
-
-  /**
    * Latch that is opened after initialization waits for required roles up to the
    * <a href="DistributedSystem#member-timeout">member-timeout </a>.
    */
@@ -183,18 +176,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
 
     this.requiresReliabilityCheck = setRequiresReliabilityCheck;
 
-    {
-      ReliableMessageQueue tmp = null;
-      if (this.requiresReliabilityCheck) {
-        // if
-        // (attrs.getMembershipAttributes().getLossAction().isAllAccessWithQueuing())
-        // {
-        // tmp = cache.getReliableMessageQueueFactory().create(this);
-        // }
-      }
-      this.rmq = tmp;
-    }
-
     if (internalRegionArgs.isUsedForPartitionedRegionBucket()) {
       this.persistenceAdvisor = internalRegionArgs.getPersistenceAdvisor();
     } else if (this.allowsPersistence()) {
@@ -567,14 +548,12 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
   }
 
   @Override
-  protected void handleReliableDistribution(ReliableDistributionData data,
-      Set successfulRecipients) {
-    handleReliableDistribution(data, successfulRecipients, Collections.EMPTY_SET,
-        Collections.EMPTY_SET);
+  protected void handleReliableDistribution(Set successfulRecipients) {
+    handleReliableDistribution(successfulRecipients, Collections.EMPTY_SET, Collections.EMPTY_SET);
   }
 
-  protected void handleReliableDistribution(ReliableDistributionData data, Set successfulRecipients,
-      Set otherRecipients1, Set otherRecipients2) {
+  protected void handleReliableDistribution(Set successfulRecipients, Set otherRecipients1,
+      Set otherRecipients2) {
     if (this.requiresReliabilityCheck) {
       MembershipAttributes ra = getMembershipAttributes();
       Set recipients = successfulRecipients;
@@ -2140,19 +2119,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
     return getSystem().getDistributionManager().getConfig();
   }
 
-  /**
-   * Sends a list of queued messages to members playing a specified role
-   * 
-   * @param list List of QueuedOperation instances to send. Any messages sent will be removed from
-   *        this list
-   * @param role the role that a recipient must be playing
-   * @return true if at least one message made it to at least one guy playing the role
-   */
-  boolean sendQueue(List list, Role role) {
-    SendQueueOperation op = new SendQueueOperation(getDistributionManager(), this, list, role);
-    return op.distribute();
-  }
-
   /*
    * @see SearchLoadAndWriteProcessor#initialize(LocalRegion, Object, Object)
    */
@@ -2521,10 +2487,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
             this.getFullPath()), ex);
       }
     }
-    if (this.rmq != null) {
-      this.rmq.close();
-    }
-
     // Fix for #48066 - make sure that region operations are completely
     // distributed to peers before destroying the region.
     long timeout = 1000L * getCache().getDistributedSystem().getConfig().getAckWaitThreshold();
@@ -2628,9 +2590,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
       logger.warn("postDestroyRegion: encountered cancellation", e);
     }
 
-    if (this.rmq != null && destroyDiskRegion) {
-      this.rmq.destroy();
-    }
   }
 
   @Override
@@ -3601,27 +3560,6 @@ public class DistributedRegion extends LocalRegion implements CacheDistributionA
             newlyAcquiredRoles = new HashSet(missingRequiredRoles);
             newlyAcquiredRoles.retainAll(roles); // find the intersection
             if (!newlyAcquiredRoles.isEmpty()) {
-              if (DistributedRegion.this.rmq != null) {
-                Iterator it = newlyAcquiredRoles.iterator();
-                final DM dm = getDistributionManager();
-                while (it.hasNext()) {
-                  getCache().getCancelCriterion().checkCancelInProgress(null);
-                  final Role role = (Role) it.next();
-                  try {
-                    // do this in the waiting pool to make it async
-                    // @todo darrel/klund: add a single serial executor for
-                    // queue flush
-                    dm.getWaitingThreadPool().execute(new Runnable() {
-                      public void run() {
-                        DistributedRegion.this.rmq.roleReady(role);
-                      }
-                    });
-                    break;
-                  } catch (RejectedExecutionException ex) {
-                    throw ex;
-                  }
-                } // while
-              }
               missingRequiredRoles.removeAll(newlyAcquiredRoles);
               if (this.members == null && missingRequiredRoles.isEmpty()) {
                 isMissingRequiredRoles = false;

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRemoveAllOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRemoveAllOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRemoveAllOperation.java
index 4a86167..0c13b59 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRemoveAllOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/DistributedRemoveAllOperation.java
@@ -1042,11 +1042,6 @@ public class DistributedRemoveAllOperation extends AbstractUpdateOperation // TO
       return s;
     }
 
-    @Override
-    public int getOperationCount() {
-      return this.removeAllDataSize;
-    }
-
     public ClientProxyMembershipID getContext() {
       return this.context;
     }
@@ -1055,15 +1050,5 @@ public class DistributedRemoveAllOperation extends AbstractUpdateOperation // TO
       return this.removeAllData;
     }
 
-    @Override
-    public List getOperations() {
-      QueuedOperation[] ops = new QueuedOperation[getOperationCount()];
-      for (int i = 0; i < ops.length; i++) {
-        RemoveAllEntryData entry = this.removeAllData[i];
-        ops[i] = new QueuedOperation(entry.getOp(), entry.getKey(), null, null, (byte) 0,
-            this.callbackArg);
-      }
-      return Arrays.asList(ops);
-    }
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 6e374ec..66f1a4a 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -878,8 +878,6 @@ public class GemFireCacheImpl
 
       this.cqService = CqServiceProvider.create(this);
 
-      this.rmqFactory = new ReliableMessageQueueFactoryImpl();
-
       // Create the CacheStatistics
       this.cachePerfStats = new CachePerfStats(system);
       CachePerfStats.enableClockStats = this.system.getConfig().getEnableTimeStatistics();
@@ -2327,17 +2325,6 @@ public class GemFireCacheImpl
           PoolManager.close(keepalive);
 
           if (isDebugEnabled) {
-            logger.debug("{}: closing reliable message queue...", this);
-          }
-          try {
-            getReliableMessageQueueFactory().close(true);
-          } catch (CancelException e) {
-            if (isDebugEnabled) {
-              logger.debug("Ignored cancellation while closing reliable message queue", e);
-            }
-          }
-
-          if (isDebugEnabled) {
             logger.debug("{}: notifying admins of close...", this);
           }
           try {
@@ -4497,22 +4484,8 @@ public class GemFireCacheImpl
     PoolManagerImpl.readyForEvents(this.system, false);
   }
 
-  /**
-   * This cache's reliable message queue factory. Should always have an instance of it.
-   */
-  private final ReliableMessageQueueFactory rmqFactory;
-
   private List<File> backupFiles = Collections.emptyList();
 
-  /**
-   * Returns this cache's ReliableMessageQueueFactory.
-   *
-   * @since GemFire 5.0
-   */
-  public ReliableMessageQueueFactory getReliableMessageQueueFactory() {
-    return this.rmqFactory;
-  }
-
   public InternalResourceManager getResourceManager() {
     return getResourceManager(true);
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/InvalidateOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InvalidateOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/InvalidateOperation.java
index d6d38ef..eceb194 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/InvalidateOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InvalidateOperation.java
@@ -146,14 +146,6 @@ public class InvalidateOperation extends DistributedCacheOperation {
     }
 
     @Override
-    public List getOperations() {
-      byte deserializationPolicy = DistributedCacheOperation.DESERIALIZATION_POLICY_NONE;
-      QueuedOperation qOp = new QueuedOperation(getOperation(), this.key, null, null,
-          deserializationPolicy, this.callbackArg);
-      return Collections.singletonList(qOp);
-    }
-
-    @Override
     public ConflationKey getConflationKey() {
       if (!super.regionAllowsConflation || getProcessorId() != 0) {
         // if the publisher's region attributes do not support conflation

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableDistributionData.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableDistributionData.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableDistributionData.java
deleted file mode 100644
index 5c635ee..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableDistributionData.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * 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.apache.geode.internal.cache;
-
-import java.util.*;
-
-/**
- * Represents one or more distributed operations that can be reliably distributed. This interface
- * allows the data to be queued and checked for reliable distribution.
- * 
- * @since GemFire 5.0
- */
-public interface ReliableDistributionData {
-  // /**
-  // * Returns a set of the recipients that this data was sent to successfully.
-  // * @param processor the reply processor used for responses to this data.
-  // */
-  // public Set getSuccessfulRecipients(ReliableReplyProcessor21 processor);
-  /**
-   * Returns the number of logical operations this data contains.
-   */
-  public int getOperationCount();
-
-  /**
-   * Returns a list of QueuedOperation instances one for each logical operation done by this data
-   * instance.
-   */
-  public List getOperations();
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueue.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueue.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueue.java
deleted file mode 100644
index 55c1039..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueue.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * 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.apache.geode.internal.cache;
-
-import org.apache.geode.distributed.Role;
-
-import java.util.Set;
-
-/**
- * A reliable message queue is used by a DistributedRegion to queue up distributed operations for
- * required roles that are not present at the time the operation is done. Instances of this
- * interface can be obtained from {@link ReliableMessageQueueFactory} which can be obtained from
- * {@link GemFireCacheImpl#getReliableMessageQueueFactory}.
- * 
- * @since GemFire 5.0
- */
-public interface ReliableMessageQueue {
-  /**
-   * Returns the region this queue belongs to.
-   */
-  public DistributedRegion getRegion();
-
-  /**
-   * Adds a message to the queue to be sent to the list of roles.
-   * 
-   * @param data the actual data that describes the operation to enqueue
-   * @param roles the roles that need to receive this message.
-   */
-  public void add(ReliableDistributionData data, Set roles);
-
-  /**
-   * Gets the roles that this queue currently has messages for.
-   * 
-   * @return a set of {link Role}s that currently have queued messages. <code>null</code> is
-   *         returned if no messages are queued.
-   */
-  public Set getQueuingRoles();
-
-  /**
-   * Attempts to send any messages that have been added for the given role to all members that are
-   * currently playing that role.
-   * 
-   * @param role the role whose queued messages should be sent
-   * @return true if send was successful; false if it was not and the messages are still queued.
-   */
-  public boolean roleReady(Role role);
-
-  /**
-   * Removes all the data in this queue causing it to never be sent.
-   */
-  public void destroy();
-
-  /**
-   * Closes this queue. This frees up any memory used by the queue but its persistent data remains.
-   */
-  public void close();
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactory.java
deleted file mode 100644
index 39da937..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactory.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * 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.apache.geode.internal.cache;
-
-/**
- * Represents a factory for instances of {@link ReliableMessageQueue}. The Cache will have an
- * instance of the factory that can be obtained from
- * {@link GemFireCacheImpl#getReliableMessageQueueFactory}.
- * 
- * @since GemFire 5.0
- */
-public interface ReliableMessageQueueFactory {
-  /**
-   * Creates an instance of {@link ReliableMessageQueue} given the region that the queue will be on.
-   * 
-   * @param region the distributed region that the created queue will service.
-   * @return the created queue
-   */
-  public ReliableMessageQueue create(DistributedRegion region);
-
-  /**
-   * Cleanly shutdown this factory flushing any persistent data to disk.
-   * 
-   * @param force true if close should always work
-   * @throws IllegalStateException if <code>force</code> is false and the factory is still in use.
-   *         The factory is in use as long as a queue it produced remains unclosed.
-   */
-  public void close(boolean force);
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactoryImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactoryImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactoryImpl.java
deleted file mode 100644
index 282a0e1..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ReliableMessageQueueFactoryImpl.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * 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.apache.geode.internal.cache;
-
-import org.apache.geode.distributed.Role;
-import org.apache.geode.internal.i18n.LocalizedStrings;
-
-import java.util.*;
-
-/**
- * Implementation of {@link ReliableMessageQueueFactory}
- * 
- * @since GemFire 5.0
- */
-public class ReliableMessageQueueFactoryImpl implements ReliableMessageQueueFactory {
-  private boolean closed;
-
-  /**
-   * Create a factory given its persistence attributes.
-   */
-  public ReliableMessageQueueFactoryImpl() {
-    this.closed = false;
-  }
-
-  /**
-   * Contains all the unclosed queues that have been created by this factory.
-   */
-  private final ArrayList queues = new ArrayList();
-
-  public ReliableMessageQueue create(DistributedRegion region) {
-    if (this.closed) {
-      throw new IllegalStateException(
-          LocalizedStrings.ReliableMessageQueueFactoryImpl_RELIABLE_MESSAGE_QUEUE_IS_CLOSED
-              .toLocalizedString());
-    }
-    synchronized (this.queues) {
-      Queue q = new Queue(region);
-      this.queues.add(q);
-      return q;
-    }
-  }
-
-  public void close(boolean force) {
-    // @todo darrel: nyi
-    if (!force) {
-      synchronized (this.queues) {
-        if (!this.queues.isEmpty()) {
-          throw new IllegalStateException(
-              LocalizedStrings.ReliableMessageQueueFactoryImpl_REGIONS_WITH_MESSAGE_QUEUING_ALREADY_EXIST
-                  .toLocalizedString());
-        }
-      }
-    }
-    this.closed = true;
-  }
-
-  /**
-   * Maps DistributedRegion keys to QueuedRegionData values
-   */
-  private final IdentityHashMap regionMap = new IdentityHashMap(128);
-
-  /**
-   * Adds data in the specified region to be sent to the specified roles
-   */
-  protected void add(DistributedRegion r, ReliableDistributionData data, Set roles) {
-    QueuedRegionData qrd = null;
-    synchronized (this.regionMap) {
-      qrd = (QueuedRegionData) this.regionMap.get(r);
-    }
-    qrd.add(r, data, roles);
-    r.getCachePerfStats().incReliableQueuedOps(data.getOperationCount() * roles.size());
-  }
-
-  public Set getQueuingRoles(DistributedRegion r) {
-    QueuedRegionData qrd = null;
-    synchronized (this.regionMap) {
-      qrd = (QueuedRegionData) this.regionMap.get(r);
-    }
-    return qrd.getQueuingRoles(r);
-  }
-
-  protected boolean roleReady(DistributedRegion r, Role role) {
-    QueuedRegionData qrd = null;
-    synchronized (this.regionMap) {
-      qrd = (QueuedRegionData) this.regionMap.get(r);
-    }
-    return qrd.roleReady(r, role);
-  }
-
-  /**
-   * Initializes data queuing for the given region
-   */
-  protected void init(DistributedRegion r) {
-    QueuedRegionData qrd = new QueuedRegionData();
-    synchronized (this.regionMap) {
-      Object old = this.regionMap.put(r, qrd);
-      if (old != null) {
-        throw new IllegalStateException(
-            LocalizedStrings.ReliableMessageQueueFactoryImpl_UNEXPECTED_QUEUEDREGIONDATA_0_FOR_REGION_1
-                .toLocalizedString(new Object[] {old, r}));
-      }
-    }
-  }
-
-  /**
-   * Removes any data queued for the given region
-   */
-  protected void destroy(DistributedRegion r) {
-    QueuedRegionData qrd = null;
-    synchronized (this.regionMap) {
-      qrd = (QueuedRegionData) this.regionMap.remove(r);
-    }
-    if (qrd != null) {
-      qrd.destroy(r);
-    }
-  }
-
-  /**
-   * Removes a previously created queue from this factory.
-   */
-  protected void removeQueue(Queue q) {
-    synchronized (this.queues) {
-      this.queues.remove(q);
-    }
-  }
-
-  /**
-   * Implements ReliableMessageQueue.
-   * 
-   * @since GemFire 5.0
-   */
-  public class Queue implements ReliableMessageQueue {
-    private final DistributedRegion r;
-
-    Queue(DistributedRegion r) {
-      this.r = r;
-      init(this.r);
-    }
-
-    public DistributedRegion getRegion() {
-      return this.r;
-    }
-
-    public void add(ReliableDistributionData data, Set roles) {
-      ReliableMessageQueueFactoryImpl.this.add(this.r, data, roles);
-    }
-
-    public Set getQueuingRoles() {
-      return ReliableMessageQueueFactoryImpl.this.getQueuingRoles(this.r);
-    }
-
-    public boolean roleReady(Role role) {
-      return ReliableMessageQueueFactoryImpl.this.roleReady(this.r, role);
-    }
-
-    public void destroy() {
-      ReliableMessageQueueFactoryImpl.this.destroy(this.r);
-    }
-
-    public void close() {
-      removeQueue(this);
-    }
-  }
-  /**
-   * Used to organize all the queued data for a region.
-   */
-  static protected class QueuedRegionData {
-    /**
-     * Maps Role keys to lists of ReliableDistributionData
-     */
-    private final HashMap roleMap = new HashMap();
-
-    /**
-     * Adds data in the specified region to be sent to the specified roles
-     */
-    protected void add(DistributedRegion r, ReliableDistributionData data, Set roles) {
-      synchronized (this) {
-        Iterator it = roles.iterator();
-        while (it.hasNext()) {
-          Role role = (Role) it.next();
-          List l = (List) this.roleMap.get(role);
-          if (l == null) {
-            l = new ArrayList();
-            this.roleMap.put(role, l);
-          }
-          l.addAll(data.getOperations());
-        }
-      }
-    }
-
-    protected Set getQueuingRoles(DistributedRegion r) {
-      Set result = null;
-      synchronized (this) {
-        Iterator it = this.roleMap.entrySet().iterator();
-        while (it.hasNext()) {
-          Map.Entry me = (Map.Entry) it.next();
-          List l = (List) me.getValue();
-          if (l != null && !l.isEmpty()) {
-            // found a role with a non-empty list of operations so add to result
-            if (result == null) {
-              result = new HashSet();
-            }
-            result.add(me.getKey());
-          }
-        }
-      }
-      return result;
-    }
-
-    protected boolean roleReady(DistributedRegion r, Role role) {
-      List l = null;
-      synchronized (this) {
-        l = (List) this.roleMap.get(role);
-      }
-      if (l != null) {
-        // @todo darrel: do this in a background thread
-        while (!l.isEmpty()) {
-          if (!r.sendQueue(l, role)) {
-            // Couldn't send the last message so stop and return false
-            return false;
-          }
-        }
-      }
-      return true;
-    }
-
-    /**
-     * Blows away all the data in this object.
-     */
-    public void destroy(DistributedRegion r) {
-      // @todo darrel: nothing needs doing until we use disk
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/SendQueueOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/SendQueueOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/SendQueueOperation.java
deleted file mode 100644
index a72dee9..0000000
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/SendQueueOperation.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * 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.apache.geode.internal.cache;
-
-import java.util.*;
-import java.io.*;
-import org.apache.geode.*;
-import org.apache.geode.cache.*;
-import org.apache.geode.distributed.*;
-import org.apache.geode.distributed.internal.*;
-
-
-/**
- * Sends a chunk of queued messages to everyone currently playing a role.
- *
- * @since GemFire 5.0
- *
- */
-public class SendQueueOperation {
-  // private ReplyProcessor21 processor = null;
-  private DM dm;
-  private DistributedRegion r;
-  private List l;
-  private Role role;
-
-  SendQueueOperation(DM dm, DistributedRegion r, List l, Role role) {
-    this.dm = dm;
-    this.r = r;
-    this.l = l;
-    this.role = role;
-  }
-
-  /**
-   * Returns true if distribution successful. Also modifies message list by removing messages sent
-   * to the required role.
-   */
-  boolean distribute() {
-    CacheDistributionAdvisor advisor = this.r.getCacheDistributionAdvisor();
-    Set recipients = advisor.adviseCacheOpRole(this.role);
-    if (recipients.isEmpty()) {
-      return false;
-    }
-    ReplyProcessor21 processor = new ReplyProcessor21(this.dm, recipients);
-    // @todo darrel: make this a reliable one
-    SendQueueMessage msg = new SendQueueMessage();
-    msg.setRecipients(recipients);
-    msg.setRegionPath(this.r.getFullPath());
-    msg.setProcessorId(processor.getProcessorId());
-    msg.setOperations(this.l);
-    dm.putOutgoing(msg);
-    try {
-      processor.waitForReplies();
-    } catch (InterruptedException ex) {
-      Thread.currentThread().interrupt();
-      // It's OK to keep going, no significant work below.
-    } catch (ReplyException ex) {
-      ex.handleAsUnexpected();
-    }
-    if (msg.getSuccessfulRecipients().isEmpty()) {
-      return false;
-    }
-    // @todo darrel: now remove sent items from the list
-    this.r.getCachePerfStats().incReliableQueuedOps(-l.size());
-    this.l.clear();
-    return true;
-  }
-
-  /**
-   * A batch of queued messages. Once they are processed on the other side an ack is sent.
-   */
-  public static final class SendQueueMessage extends SerialDistributionMessage
-      implements MessageWithReply {
-    private int processorId;
-    private String regionPath;
-    /**
-     * List of QueuedOperation instances
-     */
-    private List ops;
-
-    @Override
-    public int getProcessorId() {
-      return this.processorId;
-    }
-
-    public void setProcessorId(int id) {
-      this.processorId = id;
-    }
-
-    public String getRegionPath() {
-      return this.regionPath;
-    }
-
-    public void setRegionPath(String rp) {
-      this.regionPath = rp;
-    }
-
-    public void setOperations(List l) {
-      this.ops = l;
-    }
-
-    @Override
-    protected void process(DistributionManager dm) {
-      ReplyException rex = null;
-      boolean ignored = false;
-      try {
-        GemFireCacheImpl gfc = (GemFireCacheImpl) CacheFactory.getInstance(dm.getSystem());
-        final LocalRegion lclRgn = gfc.getRegionByPathForProcessing(this.regionPath);
-        if (lclRgn != null) {
-          lclRgn.waitOnInitialization();
-          final long lastMod = gfc.cacheTimeMillis();
-          Iterator it = this.ops.iterator();
-          while (it.hasNext()) {
-            QueuedOperation op = (QueuedOperation) it.next();
-            op.process(lclRgn, getSender(), lastMod);
-          }
-        } else {
-          ignored = true;
-        }
-      } catch (RegionDestroyedException e) {
-        ignored = true;
-      } catch (CancelException e) {
-        ignored = true;
-      } finally {
-        ReplyMessage.send(getSender(), this.processorId, rex, dm, ignored, false, false);
-      }
-    }
-
-    public int getDSFID() {
-      return SEND_QUEUE_MESSAGE;
-    }
-
-    @Override
-    public void fromData(DataInput in) throws IOException, ClassNotFoundException {
-      super.fromData(in);
-      this.regionPath = DataSerializer.readString(in);
-      this.processorId = in.readInt();
-      {
-        int opCount = in.readInt();
-        QueuedOperation[] ops = new QueuedOperation[opCount];
-        for (int i = 0; i < opCount; i++) {
-          ops[i] = QueuedOperation.createFromData(in);
-        }
-        this.ops = Arrays.asList(ops);
-      }
-    }
-
-    @Override
-    public void toData(DataOutput out) throws IOException {
-      super.toData(out);
-      DataSerializer.writeString(this.regionPath, out);
-      out.writeInt(this.processorId);
-      {
-        int opCount = this.ops.size();
-        out.writeInt(opCount);
-        for (int i = 0; i < opCount; i++) {
-          QueuedOperation op = (QueuedOperation) this.ops.get(i);
-          op.toData(out);
-        }
-      }
-    }
-
-    @Override
-    public String toString() {
-      StringBuffer buff = new StringBuffer();
-      buff.append(getClass().getName());
-      buff.append("(region path='"); // make sure this is the first one
-      buff.append(this.regionPath);
-      buff.append("'");
-      buff.append("; processorId=");
-      buff.append(this.processorId);
-      buff.append("; queuedOps=");
-      buff.append(this.ops.size());
-      buff.append(")");
-      return buff.toString();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
index e325bf1..7c2a3e3 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXCommitMessage.java
@@ -526,19 +526,7 @@ public class TXCommitMessage extends PooledDistributionMessage
       successfulRecipients.removeAll(regionDestroyedMembers);
 
       try {
-        ReliableDistributionData rdd = new ReliableDistributionData() {
-          // public Set getSuccessfulRecipients(ReliableReplyProcessor21 processor) {
-          // return successfulRecipients;
-          // }
-          public int getOperationCount() {
-            return rc.getOperationCount();
-          }
-
-          public List getOperations() {
-            return rc.getOperations();
-          }
-        };
-        rc.r.handleReliableDistribution(rdd, successfulRecipients);
+        rc.r.handleReliableDistribution(successfulRecipients);
       } catch (RegionDistributionException e) {
         if (regionDistributionExceptions == Collections.EMPTY_SET) {
           regionDistributionExceptions = new HashSet();
@@ -1408,19 +1396,6 @@ public class TXCommitMessage extends PooledDistributionMessage
       return this.opKeys == null;
     }
 
-    /**
-     * Returns the number of operations this region commit will do
-     * 
-     * @since GemFire 5.0
-     */
-    int getOperationCount() {
-      int result = 0;
-      if (!isEmpty()) {
-        result = this.opKeys.size();
-      }
-      return result;
-    }
-
     boolean needsAck() {
       return this.r.getScope().isDistributedAck();
     }
@@ -1481,20 +1456,6 @@ public class TXCommitMessage extends PooledDistributionMessage
       return result.toString();
     }
 
-    /**
-     * Returns a list of QueuedOperation instances for reliable distribution
-     * 
-     * @since GemFire 5.0
-     */
-    List getOperations() {
-      QueuedOperation[] ops = new QueuedOperation[getOperationCount()];
-      for (int i = 0; i < ops.length; i++) {
-        TXEntryState es = (TXEntryState) this.opEntries.get(i);
-        ops[i] = es.toFarSideQueuedOp(this.opKeys.get(i));
-      }
-      return Arrays.asList(ops);
-    }
-
     private void basicToData(DataOutput out) throws IOException {
       if (this.r != null) {
         DataSerializer.writeString(this.r.getFullPath(), out);

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateEntryVersionOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateEntryVersionOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateEntryVersionOperation.java
index f534a6e..f82f0ce 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateEntryVersionOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateEntryVersionOperation.java
@@ -104,12 +104,6 @@ public class UpdateEntryVersionOperation extends DistributedCacheOperation {
     }
 
     @Override
-    public List getOperations() {
-      return Collections.singletonList(new QueuedOperation(getOperation(), this.key, null, null,
-          DistributedCacheOperation.DESERIALIZATION_POLICY_NONE, this.callbackArg));
-    }
-
-    @Override
     protected void appendFields(StringBuilder buff) {
       super.appendFields(buff);
       buff.append("; key=");

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateOperation.java
index 09ce587..1afae86 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/UpdateOperation.java
@@ -445,19 +445,6 @@ public class UpdateOperation extends AbstractUpdateOperation {
       }
     }
 
-    @Override
-    public List getOperations() {
-      byte[] valueBytes = null;
-      Object valueObj = null;
-      if (this.newValueObj != null) {
-        valueBytes = EntryEventImpl.serialize(this.newValueObj);
-      } else {
-        valueBytes = this.newValue;
-      }
-      return Collections.singletonList(new QueuedOperation(getOperation(), this.key, valueBytes,
-          valueObj, this.deserializationPolicy, this.callbackArg));
-    }
-
     public boolean hasBridgeContext() {
       if (this.event != null) {
         return this.event.getContext() != null;

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/BatchDestroyOperation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/BatchDestroyOperation.java b/geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/BatchDestroyOperation.java
index 5da18a8..a368b60 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/BatchDestroyOperation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/BatchDestroyOperation.java
@@ -37,7 +37,6 @@ import org.apache.geode.internal.cache.DistributedRegion;
 import org.apache.geode.internal.cache.EntryEventImpl;
 import org.apache.geode.internal.cache.EventID;
 import org.apache.geode.internal.cache.InternalCacheEvent;
-import org.apache.geode.internal.cache.QueuedOperation;
 import org.apache.geode.internal.cache.RegionQueue;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.internal.logging.LogService;
@@ -210,12 +209,6 @@ public class BatchDestroyOperation extends DistributedCacheOperation {
     }
 
     @Override
-    public List getOperations() {
-      return Collections.singletonList(new QueuedOperation(getOperation(), this.key, null, null,
-          DistributedCacheOperation.DESERIALIZATION_POLICY_NONE, this.callbackArg));
-    }
-
-    @Override
     public ConflationKey getConflationKey() {
       if (!super.regionAllowsConflation || getProcessorId() != 0) {
         // if the publisher's region attributes do not support conflation

http://git-wip-us.apache.org/repos/asf/geode/blob/5ec0d470/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
index fa63437..47ae0c5 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
@@ -3604,12 +3604,6 @@ public class LocalizedStrings {
   public static final StringId RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL =
       new StringId(3176,
           "CacheClientProxy for this client is no longer on the server , so registerInterest operation is unsuccessful");
-  public static final StringId ReliableMessageQueueFactoryImpl_REGIONS_WITH_MESSAGE_QUEUING_ALREADY_EXIST =
-      new StringId(3177, "Regions with message queuing already exist");
-  public static final StringId ReliableMessageQueueFactoryImpl_RELIABLE_MESSAGE_QUEUE_IS_CLOSED =
-      new StringId(3178, "reliable message queue is closed");
-  public static final StringId ReliableMessageQueueFactoryImpl_UNEXPECTED_QUEUEDREGIONDATA_0_FOR_REGION_1 =
-      new StringId(3179, "unexpected QueuedRegionData  {0}  for region  {1}");
   public static final StringId RemoteBridgeServer_A_REMOTE_BRIDGESERVER_CANNOT_BE_STARTED =
       new StringId(3180, "A remote BridgeServer cannot be started.");
   public static final StringId RemoteBridgeServer_A_REMOTE_BRIDGESERVER_CANNOT_BE_STOPPED =


[11/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/ParsingTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/ParsingTest.java b/geode-json/src/test/java/org/json/ParsingTest.java
index 4a0837a..a49aba7 100755
--- a/geode-json/src/test/java/org/json/ParsingTest.java
+++ b/geode-json/src/test/java/org/json/ParsingTest.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -25,270 +23,269 @@ import static org.junit.Assert.fail;
 
 public class ParsingTest {
 
-    @Test
-    public void testParsingNoObjects() {
-        try {
-            new JSONTokener("").nextValue();
-            fail();
-        } catch (JSONException ignored) {
-        }
+  @Test
+  public void testParsingNoObjects() {
+    try {
+      new JSONTokener("").nextValue();
+      fail();
+    } catch (JSONException ignored) {
     }
-
-    @Test
-    public void testParsingLiterals() throws JSONException {
-        assertParsed(Boolean.TRUE, "true");
-        assertParsed(Boolean.FALSE, "false");
-        assertParsed(JSONObject.NULL, "null");
-        assertParsed(JSONObject.NULL, "NULL");
-        assertParsed(Boolean.FALSE, "False");
-        assertParsed(Boolean.TRUE, "truE");
-    }
-
-    @Test
-    public void testParsingQuotedStrings() throws JSONException {
-        assertParsed("abc", "\"abc\"");
-        assertParsed("123", "\"123\"");
-        assertParsed("foo\nbar", "\"foo\\nbar\"");
-        assertParsed("foo bar", "\"foo\\u0020bar\"");
-        assertParsed("\"{}[]/\\:,=;#", "\"\\\"{}[]/\\\\:,=;#\"");
-    }
-
-    @Test
-    public void testParsingSingleQuotedStrings() throws JSONException {
-        assertParsed("abc", "'abc'");
-        assertParsed("123", "'123'");
-        assertParsed("foo\nbar", "'foo\\nbar'");
-        assertParsed("foo bar", "'foo\\u0020bar'");
-        assertParsed("\"{}[]/\\:,=;#", "'\\\"{}[]/\\\\:,=;#'");
-    }
-
-    @Test
-    public void testParsingUnquotedStrings() throws JSONException {
-        assertParsed("abc", "abc");
-        assertParsed("123abc", "123abc");
-        assertParsed("123e0x", "123e0x");
-        assertParsed("123e", "123e");
-        assertParsed("123ee21", "123ee21");
-        assertParsed("0xFFFFFFFFFFFFFFFFF", "0xFFFFFFFFFFFFFFFFF");
-    }
-
-    /**
-     * Unfortunately the original implementation attempts to figure out what
-     * Java number type best suits an input value.
-     */
-    @Test
-    public void testParsingNumbersThatAreBestRepresentedAsLongs() throws JSONException {
-        assertParsed(9223372036854775807L, "9223372036854775807");
-        assertParsed(9223372036854775806L, "9223372036854775806");
-        assertParsed(-9223372036854775808L, "-9223372036854775808");
-        assertParsed(-9223372036854775807L, "-9223372036854775807");
-    }
-
-    @Test
-    public void testParsingNumbersThatAreBestRepresentedAsIntegers() throws JSONException {
-        assertParsed(0, "0");
-        assertParsed(5, "5");
-        assertParsed(-2147483648, "-2147483648");
-        assertParsed(2147483647, "2147483647");
-    }
-
-    @Test
-    public void testParsingNegativeZero() throws JSONException {
-        assertParsed(0, "-0");
-    }
-
-    @Test
-    public void testParsingIntegersWithAdditionalPrecisionYieldDoubles() throws JSONException {
-        assertParsed(1d, "1.00");
-        assertParsed(1d, "1.0");
-        assertParsed(0d, "0.0");
-        assertParsed(-0d, "-0.0");
-    }
-
-    @Test
-    public void testParsingNumbersThatAreBestRepresentedAsDoubles() throws JSONException {
-        assertParsed(9.223372036854776E18, "9223372036854775808");
-        assertParsed(-9.223372036854776E18, "-9223372036854775809");
-        assertParsed(1.7976931348623157E308, "1.7976931348623157e308");
-        assertParsed(2.2250738585072014E-308, "2.2250738585072014E-308");
-        assertParsed(4.9E-324, "4.9E-324");
-        assertParsed(4.9E-324, "4.9e-324");
-    }
-
-    @Test
-    public void testParsingOctalNumbers() throws JSONException {
-        assertParsed(5, "05");
-        assertParsed(8, "010");
-        assertParsed(1046, "02026");
-    }
-
-    @Test
-    public void testParsingHexNumbers() throws JSONException {
-        assertParsed(5, "0x5");
-        assertParsed(16, "0x10");
-        assertParsed(8230, "0x2026");
-        assertParsed(180150010, "0xABCDEFA");
-        assertParsed(2077093803, "0x7BCDEFAB");
+  }
+
+  @Test
+  public void testParsingLiterals() throws JSONException {
+    assertParsed(Boolean.TRUE, "true");
+    assertParsed(Boolean.FALSE, "false");
+    assertParsed(JSONObject.NULL, "null");
+    assertParsed(JSONObject.NULL, "NULL");
+    assertParsed(Boolean.FALSE, "False");
+    assertParsed(Boolean.TRUE, "truE");
+  }
+
+  @Test
+  public void testParsingQuotedStrings() throws JSONException {
+    assertParsed("abc", "\"abc\"");
+    assertParsed("123", "\"123\"");
+    assertParsed("foo\nbar", "\"foo\\nbar\"");
+    assertParsed("foo bar", "\"foo\\u0020bar\"");
+    assertParsed("\"{}[]/\\:,=;#", "\"\\\"{}[]/\\\\:,=;#\"");
+  }
+
+  @Test
+  public void testParsingSingleQuotedStrings() throws JSONException {
+    assertParsed("abc", "'abc'");
+    assertParsed("123", "'123'");
+    assertParsed("foo\nbar", "'foo\\nbar'");
+    assertParsed("foo bar", "'foo\\u0020bar'");
+    assertParsed("\"{}[]/\\:,=;#", "'\\\"{}[]/\\\\:,=;#'");
+  }
+
+  @Test
+  public void testParsingUnquotedStrings() throws JSONException {
+    assertParsed("abc", "abc");
+    assertParsed("123abc", "123abc");
+    assertParsed("123e0x", "123e0x");
+    assertParsed("123e", "123e");
+    assertParsed("123ee21", "123ee21");
+    assertParsed("0xFFFFFFFFFFFFFFFFF", "0xFFFFFFFFFFFFFFFFF");
+  }
+
+  /**
+   * Unfortunately the original implementation attempts to figure out what Java number type best
+   * suits an input value.
+   */
+  @Test
+  public void testParsingNumbersThatAreBestRepresentedAsLongs() throws JSONException {
+    assertParsed(9223372036854775807L, "9223372036854775807");
+    assertParsed(9223372036854775806L, "9223372036854775806");
+    assertParsed(-9223372036854775808L, "-9223372036854775808");
+    assertParsed(-9223372036854775807L, "-9223372036854775807");
+  }
+
+  @Test
+  public void testParsingNumbersThatAreBestRepresentedAsIntegers() throws JSONException {
+    assertParsed(0, "0");
+    assertParsed(5, "5");
+    assertParsed(-2147483648, "-2147483648");
+    assertParsed(2147483647, "2147483647");
+  }
+
+  @Test
+  public void testParsingNegativeZero() throws JSONException {
+    assertParsed(0, "-0");
+  }
+
+  @Test
+  public void testParsingIntegersWithAdditionalPrecisionYieldDoubles() throws JSONException {
+    assertParsed(1d, "1.00");
+    assertParsed(1d, "1.0");
+    assertParsed(0d, "0.0");
+    assertParsed(-0d, "-0.0");
+  }
+
+  @Test
+  public void testParsingNumbersThatAreBestRepresentedAsDoubles() throws JSONException {
+    assertParsed(9.223372036854776E18, "9223372036854775808");
+    assertParsed(-9.223372036854776E18, "-9223372036854775809");
+    assertParsed(1.7976931348623157E308, "1.7976931348623157e308");
+    assertParsed(2.2250738585072014E-308, "2.2250738585072014E-308");
+    assertParsed(4.9E-324, "4.9E-324");
+    assertParsed(4.9E-324, "4.9e-324");
+  }
+
+  @Test
+  public void testParsingOctalNumbers() throws JSONException {
+    assertParsed(5, "05");
+    assertParsed(8, "010");
+    assertParsed(1046, "02026");
+  }
+
+  @Test
+  public void testParsingHexNumbers() throws JSONException {
+    assertParsed(5, "0x5");
+    assertParsed(16, "0x10");
+    assertParsed(8230, "0x2026");
+    assertParsed(180150010, "0xABCDEFA");
+    assertParsed(2077093803, "0x7BCDEFAB");
+  }
+
+  @Test
+  public void testParsingLargeHexValues() throws JSONException {
+    assertParsed(Integer.MAX_VALUE, "0x7FFFFFFF");
+    String message = "Hex values are parsed as Strings if their signed "
+        + "value is greater than Integer.MAX_VALUE.";
+    assertParsed(message, 0x80000000L, "0x80000000");
+  }
+
+  @Test
+  public void test64BitHexValues() throws JSONException {
+    // note that this is different from the same test in the original Android
+    // this is due to the fact that Long.parseLong doesn't correctly handle
+    // the value -1 expressed as unsigned hex if you use the normal JDK. Presumably
+    // the Android equivalent program does this better.
+    assertParsed("Large hex longs shouldn't yield ints or strings", 0xFFFFFFFFFFFFFFFL,
+        "0xFFFFFFFFFFFFFFF");
+  }
+
+  @Test
+  public void testParsingWithCommentsAndWhitespace() throws JSONException {
+    assertParsed("baz", "  // foo bar \n baz");
+    assertParsed("baz", "  // foo bar \r baz");
+    assertParsed("baz", "  // foo bar \r\n baz");
+    assertParsed("baz", "  # foo bar \n baz");
+    assertParsed("baz", "  # foo bar \r baz");
+    assertParsed("baz", "  # foo bar \r\n baz");
+    assertParsed(5, "  /* foo bar \n baz */ 5");
+    assertParsed(5, "  /* foo bar \n baz */ 5 // quux");
+    assertParsed(5, "  5   ");
+    assertParsed(5, "  5  \r\n\t ");
+    assertParsed(5, "\r\n\t   5 ");
+  }
+
+  @Test
+  public void testParsingArrays() throws JSONException {
+    assertParsed(array(), "[]");
+    assertParsed(array(5, 6, true), "[5,6,true]");
+    assertParsed(array(5, 6, array()), "[5,6,[]]");
+    assertParsed(array(5, 6, 7), "[5;6;7]");
+    assertParsed(array(5, 6, 7), "[5  , 6 \t; \r\n 7\n]");
+    assertParsed(array(5, 6, 7, null), "[5,6,7,]");
+    assertParsed(array(null, null), "[,]");
+    assertParsed(array(5, null, null, null, 5), "[5,,,,5]");
+    assertParsed(array(null, 5), "[,5]");
+    assertParsed(array(null, null, null), "[,,]");
+    assertParsed(array(null, null, null, 5), "[,,,5]");
+  }
+
+  @Test
+  public void testParsingObjects() throws JSONException {
+    assertParsed(object("foo", 5), "{\"foo\": 5}");
+    assertParsed(object("foo", 5), "{foo: 5}");
+    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5, \"bar\": \"baz\"}");
+    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5; \"bar\": \"baz\"}");
+    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"= 5; \"bar\"= \"baz\"}");
+    assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"=> 5; \"bar\"=> \"baz\"}");
+    assertParsed(object("foo", object(), "bar", array()), "{\"foo\"=> {}; \"bar\"=> []}");
+    assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\": {\"foo\": [5, 6]}}");
+    assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\":\n\t{\t \"foo\":[5,\r6]}}");
+  }
+
+  @Test
+  public void testSyntaxProblemUnterminatedObject() {
+    assertParseFail("{");
+    assertParseFail("{\"foo\"");
+    assertParseFail("{\"foo\":");
+    assertParseFail("{\"foo\":bar");
+    assertParseFail("{\"foo\":bar,");
+    assertParseFail("{\"foo\":bar,\"baz\"");
+    assertParseFail("{\"foo\":bar,\"baz\":");
+    assertParseFail("{\"foo\":bar,\"baz\":true");
+    assertParseFail("{\"foo\":bar,\"baz\":true,");
+  }
+
+  @Test
+  public void testSyntaxProblemEmptyString() {
+    assertParseFail("");
+  }
+
+  @Test
+  public void testSyntaxProblemUnterminatedArray() {
+    assertParseFail("[");
+    assertParseFail("[,");
+    assertParseFail("[,,");
+    assertParseFail("[true");
+    assertParseFail("[true,");
+    assertParseFail("[true,,");
+  }
+
+  @Test
+  public void testSyntaxProblemMalformedObject() {
+    assertParseFail("{:}");
+    assertParseFail("{\"key\":}");
+    assertParseFail("{:true}");
+    assertParseFail("{\"key\":true:}");
+    assertParseFail("{null:true}");
+    assertParseFail("{true:true}");
+    assertParseFail("{0xFF:true}");
+  }
+
+  private void assertParseFail(String malformedJson) {
+    try {
+      new JSONTokener(malformedJson).nextValue();
+      fail("Successfully parsed: \"" + malformedJson + "\"");
+    } catch (JSONException ignored) {
+    } catch (StackOverflowError e) {
+      fail("Stack overflowed on input: \"" + malformedJson + "\"");
     }
+  }
 
-    @Test
-    public void testParsingLargeHexValues() throws JSONException {
-        assertParsed(Integer.MAX_VALUE, "0x7FFFFFFF");
-        String message = "Hex values are parsed as Strings if their signed " +
-                "value is greater than Integer.MAX_VALUE.";
-        assertParsed(message, 0x80000000L, "0x80000000");
-    }
-
-    @Test
-    public void test64BitHexValues() throws JSONException {
-        // note that this is different from the same test in the original Android
-        // this is due to the fact that Long.parseLong doesn't correctly handle
-        // the value -1 expressed as unsigned hex if you use the normal JDK. Presumably
-        // the Android equivalent program does this better.
-        assertParsed("Large hex longs shouldn't yield ints or strings",
-                0xFFFFFFFFFFFFFFFL, "0xFFFFFFFFFFFFFFF");
-    }
+  private JSONArray array(Object... elements) {
+    return new JSONArray(Arrays.asList(elements));
+  }
 
-    @Test
-    public void testParsingWithCommentsAndWhitespace() throws JSONException {
-        assertParsed("baz", "  // foo bar \n baz");
-        assertParsed("baz", "  // foo bar \r baz");
-        assertParsed("baz", "  // foo bar \r\n baz");
-        assertParsed("baz", "  # foo bar \n baz");
-        assertParsed("baz", "  # foo bar \r baz");
-        assertParsed("baz", "  # foo bar \r\n baz");
-        assertParsed(5, "  /* foo bar \n baz */ 5");
-        assertParsed(5, "  /* foo bar \n baz */ 5 // quux");
-        assertParsed(5, "  5   ");
-        assertParsed(5, "  5  \r\n\t ");
-        assertParsed(5, "\r\n\t   5 ");
+  private JSONObject object(Object... keyValuePairs) throws JSONException {
+    JSONObject result = new JSONObject();
+    for (int i = 0; i < keyValuePairs.length; i += 2) {
+      result.put((String) keyValuePairs[i], keyValuePairs[i + 1]);
     }
-
-    @Test
-    public void testParsingArrays() throws JSONException {
-        assertParsed(array(), "[]");
-        assertParsed(array(5, 6, true), "[5,6,true]");
-        assertParsed(array(5, 6, array()), "[5,6,[]]");
-        assertParsed(array(5, 6, 7), "[5;6;7]");
-        assertParsed(array(5, 6, 7), "[5  , 6 \t; \r\n 7\n]");
-        assertParsed(array(5, 6, 7, null), "[5,6,7,]");
-        assertParsed(array(null, null), "[,]");
-        assertParsed(array(5, null, null, null, 5), "[5,,,,5]");
-        assertParsed(array(null, 5), "[,5]");
-        assertParsed(array(null, null, null), "[,,]");
-        assertParsed(array(null, null, null, 5), "[,,,5]");
-    }
-
-    @Test
-    public void testParsingObjects() throws JSONException {
-        assertParsed(object("foo", 5), "{\"foo\": 5}");
-        assertParsed(object("foo", 5), "{foo: 5}");
-        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5, \"bar\": \"baz\"}");
-        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\": 5; \"bar\": \"baz\"}");
-        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"= 5; \"bar\"= \"baz\"}");
-        assertParsed(object("foo", 5, "bar", "baz"), "{\"foo\"=> 5; \"bar\"=> \"baz\"}");
-        assertParsed(object("foo", object(), "bar", array()), "{\"foo\"=> {}; \"bar\"=> []}");
-        assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\": {\"foo\": [5, 6]}}");
-        assertParsed(object("foo", object("foo", array(5, 6))), "{\"foo\":\n\t{\t \"foo\":[5,\r6]}}");
-    }
-
-    @Test
-    public void testSyntaxProblemUnterminatedObject() {
-        assertParseFail("{");
-        assertParseFail("{\"foo\"");
-        assertParseFail("{\"foo\":");
-        assertParseFail("{\"foo\":bar");
-        assertParseFail("{\"foo\":bar,");
-        assertParseFail("{\"foo\":bar,\"baz\"");
-        assertParseFail("{\"foo\":bar,\"baz\":");
-        assertParseFail("{\"foo\":bar,\"baz\":true");
-        assertParseFail("{\"foo\":bar,\"baz\":true,");
-    }
-
-    @Test
-    public void testSyntaxProblemEmptyString() {
-        assertParseFail("");
-    }
-
-    @Test
-    public void testSyntaxProblemUnterminatedArray() {
-        assertParseFail("[");
-        assertParseFail("[,");
-        assertParseFail("[,,");
-        assertParseFail("[true");
-        assertParseFail("[true,");
-        assertParseFail("[true,,");
-    }
-
-    @Test
-    public void testSyntaxProblemMalformedObject() {
-        assertParseFail("{:}");
-        assertParseFail("{\"key\":}");
-        assertParseFail("{:true}");
-        assertParseFail("{\"key\":true:}");
-        assertParseFail("{null:true}");
-        assertParseFail("{true:true}");
-        assertParseFail("{0xFF:true}");
-    }
-
-    private void assertParseFail(String malformedJson) {
-        try {
-            new JSONTokener(malformedJson).nextValue();
-            fail("Successfully parsed: \"" + malformedJson + "\"");
-        } catch (JSONException ignored) {
-        } catch (StackOverflowError e) {
-            fail("Stack overflowed on input: \"" + malformedJson + "\"");
-        }
-    }
-
-    private JSONArray array(Object... elements) {
-        return new JSONArray(Arrays.asList(elements));
-    }
-
-    private JSONObject object(Object... keyValuePairs) throws JSONException {
-        JSONObject result = new JSONObject();
-        for (int i = 0; i < keyValuePairs.length; i += 2) {
-            result.put((String) keyValuePairs[i], keyValuePairs[i + 1]);
-        }
-        return result;
-    }
-
-    private void assertParsed(String message, Object expected, String json) throws JSONException {
-        Object actual = new JSONTokener(json).nextValue();
-        actual = canonicalize(actual);
-        expected = canonicalize(expected);
-        assertEquals("For input \"" + json + "\" " + message, expected, actual);
-    }
-
-    private void assertParsed(Object expected, String json) throws JSONException {
-        assertParsed("", expected, json);
-    }
-
-    /**
-     * Since they don't implement equals or hashCode properly, this recursively
-     * replaces JSONObjects with an equivalent HashMap, and JSONArrays with the
-     * equivalent ArrayList.
-     */
-    private Object canonicalize(Object input) throws JSONException {
-        if (input instanceof JSONArray) {
-            JSONArray array = (JSONArray) input;
-            List<Object> result = new ArrayList<Object>();
-            for (int i = 0; i < array.length(); i++) {
-                result.add(canonicalize(array.opt(i)));
-            }
-            return result;
-        } else if (input instanceof JSONObject) {
-            JSONObject object = (JSONObject) input;
-            Map<String, Object> result = new HashMap<String, Object>();
-            for (Iterator<?> i = object.keys(); i.hasNext(); ) {
-                String key = (String) i.next();
-                result.put(key, canonicalize(object.get(key)));
-            }
-            return result;
-        } else if (input == null || input.equals(JSONObject.NULL)) {
-            return JSONObject.NULL;
-        } else {
-            return input;
-        }
+    return result;
+  }
+
+  private void assertParsed(String message, Object expected, String json) throws JSONException {
+    Object actual = new JSONTokener(json).nextValue();
+    actual = canonicalize(actual);
+    expected = canonicalize(expected);
+    assertEquals("For input \"" + json + "\" " + message, expected, actual);
+  }
+
+  private void assertParsed(Object expected, String json) throws JSONException {
+    assertParsed("", expected, json);
+  }
+
+  /**
+   * Since they don't implement equals or hashCode properly, this recursively replaces JSONObjects
+   * with an equivalent HashMap, and JSONArrays with the equivalent ArrayList.
+   */
+  private Object canonicalize(Object input) throws JSONException {
+    if (input instanceof JSONArray) {
+      JSONArray array = (JSONArray) input;
+      List<Object> result = new ArrayList<Object>();
+      for (int i = 0; i < array.length(); i++) {
+        result.add(canonicalize(array.opt(i)));
+      }
+      return result;
+    } else if (input instanceof JSONObject) {
+      JSONObject object = (JSONObject) input;
+      Map<String, Object> result = new HashMap<String, Object>();
+      for (Iterator<?> i = object.keys(); i.hasNext();) {
+        String key = (String) i.next();
+        result.put(key, canonicalize(object.get(key)));
+      }
+      return result;
+    } else if (input == null || input.equals(JSONObject.NULL)) {
+      return JSONObject.NULL;
+    } else {
+      return input;
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/SelfUseTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/SelfUseTest.java b/geode-json/src/test/java/org/json/SelfUseTest.java
index 0b9fb2c..78ee678 100755
--- a/geode-json/src/test/java/org/json/SelfUseTest.java
+++ b/geode-json/src/test/java/org/json/SelfUseTest.java
@@ -1,17 +1,15 @@
 /*
  * 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,256 +19,255 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 
 /**
- * These tests checks self use calls. For the most part we doesn't attempt to
- * cover self-use, except in those cases where our clean room implementation
- * does it.
+ * These tests checks self use calls. For the most part we doesn't attempt to cover self-use, except
+ * in those cases where our clean room implementation does it.
  * <p>
- * <p>This black box test was written without inspecting the non-free org.json
- * sourcecode.
+ * <p>
+ * This black box test was written without inspecting the non-free org.json sourcecode.
  */
 public class SelfUseTest {
 
-    private int objectPutCalls = 0;
-    private int objectGetCalls = 0;
-    private int objectOptCalls = 0;
-    private int objectOptTypeCalls = 0;
-    private int arrayPutCalls = 0;
-    private int arrayGetCalls = 0;
-    private int arrayOptCalls = 0;
-    private int arrayOptTypeCalls = 0;
-    private int tokenerNextCalls = 0;
-    private int tokenerNextValueCalls = 0;
-
-    private final JSONObject object = new JSONObject() {
-        @Override
-        public JSONObject put(String name, Object value) throws JSONException {
-            objectPutCalls++;
-            return super.put(name, value);
-        }
-
-        @Override
-        public Object get(String name) throws JSONException {
-            objectGetCalls++;
-            return super.get(name);
-        }
-
-        @Override
-        public Object opt(String name) {
-            objectOptCalls++;
-            return super.opt(name);
-        }
-
-        @Override
-        public boolean optBoolean(String key, boolean defaultValue) {
-            objectOptTypeCalls++;
-            return super.optBoolean(key, defaultValue);
-        }
-
-        @Override
-        public double optDouble(String key, double defaultValue) {
-            objectOptTypeCalls++;
-            return super.optDouble(key, defaultValue);
-        }
-
-        @Override
-        public int optInt(String key, int defaultValue) {
-            objectOptTypeCalls++;
-            return super.optInt(key, defaultValue);
-        }
-
-        @Override
-        public long optLong(String key, long defaultValue) {
-            objectOptTypeCalls++;
-            return super.optLong(key, defaultValue);
-        }
-
-        @Override
-        public String optString(String key, String defaultValue) {
-            objectOptTypeCalls++;
-            return super.optString(key, defaultValue);
-        }
-    };
-
-    private final JSONArray array = new JSONArray() {
-        @Override
-        public JSONArray put(int index, Object value) throws JSONException {
-            arrayPutCalls++;
-            return super.put(index, value);
-        }
-
-        @Override
-        public Object get(int index) throws JSONException {
-            arrayGetCalls++;
-            return super.get(index);
-        }
-
-        @Override
-        public Object opt(int index) {
-            arrayOptCalls++;
-            return super.opt(index);
-        }
-
-        @Override
-        public boolean optBoolean(int index, boolean fallback) {
-            arrayOptTypeCalls++;
-            return super.optBoolean(index, fallback);
-        }
-
-        @Override
-        public double optDouble(int index, double fallback) {
-            arrayOptTypeCalls++;
-            return super.optDouble(index, fallback);
-        }
-
-        @Override
-        public long optLong(int index, long fallback) {
-            arrayOptTypeCalls++;
-            return super.optLong(index, fallback);
-        }
-
-        @Override
-        public String optString(int index, String fallback) {
-            arrayOptTypeCalls++;
-            return super.optString(index, fallback);
-        }
-
-        @Override
-        public int optInt(int index, int fallback) {
-            arrayOptTypeCalls++;
-            return super.optInt(index, fallback);
-        }
-    };
-
-    private final JSONTokener tokener = new JSONTokener("{\"foo\": [true]}") {
-        @Override
-        public char next() {
-            tokenerNextCalls++;
-            return super.next();
-        }
-
-        @Override
-        public Object nextValue() throws JSONException {
-            tokenerNextValueCalls++;
-            return super.nextValue();
-        }
-    };
-
-
-    @Test
-    public void testObjectPut() throws JSONException {
-        object.putOpt("foo", "bar");
-        assertEquals(1, objectPutCalls);
+  private int objectPutCalls = 0;
+  private int objectGetCalls = 0;
+  private int objectOptCalls = 0;
+  private int objectOptTypeCalls = 0;
+  private int arrayPutCalls = 0;
+  private int arrayGetCalls = 0;
+  private int arrayOptCalls = 0;
+  private int arrayOptTypeCalls = 0;
+  private int tokenerNextCalls = 0;
+  private int tokenerNextValueCalls = 0;
+
+  private final JSONObject object = new JSONObject() {
+    @Override
+    public JSONObject put(String name, Object value) throws JSONException {
+      objectPutCalls++;
+      return super.put(name, value);
+    }
+
+    @Override
+    public Object get(String name) throws JSONException {
+      objectGetCalls++;
+      return super.get(name);
+    }
+
+    @Override
+    public Object opt(String name) {
+      objectOptCalls++;
+      return super.opt(name);
+    }
+
+    @Override
+    public boolean optBoolean(String key, boolean defaultValue) {
+      objectOptTypeCalls++;
+      return super.optBoolean(key, defaultValue);
+    }
+
+    @Override
+    public double optDouble(String key, double defaultValue) {
+      objectOptTypeCalls++;
+      return super.optDouble(key, defaultValue);
+    }
+
+    @Override
+    public int optInt(String key, int defaultValue) {
+      objectOptTypeCalls++;
+      return super.optInt(key, defaultValue);
+    }
+
+    @Override
+    public long optLong(String key, long defaultValue) {
+      objectOptTypeCalls++;
+      return super.optLong(key, defaultValue);
     }
 
-    @Test
-    public void testObjectAccumulate() throws JSONException {
-        object.accumulate("foo", "bar");
-        assertEquals(1, objectPutCalls);
+    @Override
+    public String optString(String key, String defaultValue) {
+      objectOptTypeCalls++;
+      return super.optString(key, defaultValue);
     }
+  };
 
-    @Test
-    public void testObjectGetBoolean() throws JSONException {
-        object.put("foo", "true");
-        object.getBoolean("foo");
-        assertEquals(1, objectGetCalls);
+  private final JSONArray array = new JSONArray() {
+    @Override
+    public JSONArray put(int index, Object value) throws JSONException {
+      arrayPutCalls++;
+      return super.put(index, value);
     }
 
-    @Test
-    public void testObjectOptType() throws JSONException {
-        object.optBoolean("foo");
-        assertEquals(1, objectOptCalls);
-        assertEquals(1, objectOptTypeCalls);
-        object.optDouble("foo");
-        assertEquals(2, objectOptCalls);
-        assertEquals(2, objectOptTypeCalls);
-        object.optInt("foo");
-        assertEquals(3, objectOptCalls);
-        assertEquals(3, objectOptTypeCalls);
-        object.optLong("foo");
-        assertEquals(4, objectOptCalls);
-        assertEquals(4, objectOptTypeCalls);
-        object.optString("foo");
-        assertEquals(5, objectOptCalls);
-        assertEquals(5, objectOptTypeCalls);
+    @Override
+    public Object get(int index) throws JSONException {
+      arrayGetCalls++;
+      return super.get(index);
     }
 
-    @Test
-    public void testToJSONArray() throws JSONException {
-        object.put("foo", 5);
-        object.put("bar", 10);
-        array.put("foo");
-        array.put("baz");
-        array.put("bar");
-        object.toJSONArray(array);
-        assertEquals(3, arrayOptCalls);
-        assertEquals(0, arrayOptTypeCalls);
-        assertEquals(3, objectOptCalls);
-        assertEquals(0, objectOptTypeCalls);
+    @Override
+    public Object opt(int index) {
+      arrayOptCalls++;
+      return super.opt(index);
     }
 
-    @Test
-    public void testPutAtIndex() throws JSONException {
-        array.put(10, false);
-        assertEquals(1, arrayPutCalls);
+    @Override
+    public boolean optBoolean(int index, boolean fallback) {
+      arrayOptTypeCalls++;
+      return super.optBoolean(index, fallback);
     }
 
-    @Test
-    public void testIsNull() {
-        array.isNull(5);
-        assertEquals(1, arrayOptCalls);
+    @Override
+    public double optDouble(int index, double fallback) {
+      arrayOptTypeCalls++;
+      return super.optDouble(index, fallback);
     }
 
-    @Test
-    public void testArrayGetType() throws JSONException {
-        array.put(true);
-        array.getBoolean(0);
-        assertEquals(1, arrayGetCalls);
+    @Override
+    public long optLong(int index, long fallback) {
+      arrayOptTypeCalls++;
+      return super.optLong(index, fallback);
     }
 
-    @Test
-    public void testArrayOptType() throws JSONException {
-        array.optBoolean(3);
-        assertEquals(1, arrayOptCalls);
-        assertEquals(1, arrayOptTypeCalls);
-        array.optDouble(3);
-        assertEquals(2, arrayOptCalls);
-        assertEquals(2, arrayOptTypeCalls);
-        array.optInt(3);
-        assertEquals(3, arrayOptCalls);
-        assertEquals(3, arrayOptTypeCalls);
-        array.optLong(3);
-        assertEquals(4, arrayOptCalls);
-        assertEquals(4, arrayOptTypeCalls);
-        array.optString(3);
-        assertEquals(5, arrayOptCalls);
-        assertEquals(5, arrayOptTypeCalls);
+    @Override
+    public String optString(int index, String fallback) {
+      arrayOptTypeCalls++;
+      return super.optString(index, fallback);
     }
 
-    @Test
-    public void testToJSONObject() throws JSONException {
-        array.put("foo");
-        array.put("baz");
-        array.put("bar");
-        JSONArray values = new JSONArray();
-        values.put(5.5d);
-        values.put(11d);
-        values.put(30);
-        values.toJSONObject(array);
-        assertEquals(3, arrayOptCalls);
-        assertEquals(0, arrayOptTypeCalls);
+    @Override
+    public int optInt(int index, int fallback) {
+      arrayOptTypeCalls++;
+      return super.optInt(index, fallback);
     }
+  };
 
-    @Test
-    public void testNextExpecting() throws JSONException {
-        tokener.next('{');
-        assertEquals(1, tokenerNextCalls);
-        tokener.next('\"');
-        assertEquals(2, tokenerNextCalls);
+  private final JSONTokener tokener = new JSONTokener("{\"foo\": [true]}") {
+    @Override
+    public char next() {
+      tokenerNextCalls++;
+      return super.next();
     }
 
-    @Test
-    public void testNextValue() throws JSONException {
-        tokener.nextValue();
-        assertEquals(4, tokenerNextValueCalls);
+    @Override
+    public Object nextValue() throws JSONException {
+      tokenerNextValueCalls++;
+      return super.nextValue();
     }
+  };
+
+
+  @Test
+  public void testObjectPut() throws JSONException {
+    object.putOpt("foo", "bar");
+    assertEquals(1, objectPutCalls);
+  }
+
+  @Test
+  public void testObjectAccumulate() throws JSONException {
+    object.accumulate("foo", "bar");
+    assertEquals(1, objectPutCalls);
+  }
+
+  @Test
+  public void testObjectGetBoolean() throws JSONException {
+    object.put("foo", "true");
+    object.getBoolean("foo");
+    assertEquals(1, objectGetCalls);
+  }
+
+  @Test
+  public void testObjectOptType() throws JSONException {
+    object.optBoolean("foo");
+    assertEquals(1, objectOptCalls);
+    assertEquals(1, objectOptTypeCalls);
+    object.optDouble("foo");
+    assertEquals(2, objectOptCalls);
+    assertEquals(2, objectOptTypeCalls);
+    object.optInt("foo");
+    assertEquals(3, objectOptCalls);
+    assertEquals(3, objectOptTypeCalls);
+    object.optLong("foo");
+    assertEquals(4, objectOptCalls);
+    assertEquals(4, objectOptTypeCalls);
+    object.optString("foo");
+    assertEquals(5, objectOptCalls);
+    assertEquals(5, objectOptTypeCalls);
+  }
+
+  @Test
+  public void testToJSONArray() throws JSONException {
+    object.put("foo", 5);
+    object.put("bar", 10);
+    array.put("foo");
+    array.put("baz");
+    array.put("bar");
+    object.toJSONArray(array);
+    assertEquals(3, arrayOptCalls);
+    assertEquals(0, arrayOptTypeCalls);
+    assertEquals(3, objectOptCalls);
+    assertEquals(0, objectOptTypeCalls);
+  }
+
+  @Test
+  public void testPutAtIndex() throws JSONException {
+    array.put(10, false);
+    assertEquals(1, arrayPutCalls);
+  }
+
+  @Test
+  public void testIsNull() {
+    array.isNull(5);
+    assertEquals(1, arrayOptCalls);
+  }
+
+  @Test
+  public void testArrayGetType() throws JSONException {
+    array.put(true);
+    array.getBoolean(0);
+    assertEquals(1, arrayGetCalls);
+  }
+
+  @Test
+  public void testArrayOptType() throws JSONException {
+    array.optBoolean(3);
+    assertEquals(1, arrayOptCalls);
+    assertEquals(1, arrayOptTypeCalls);
+    array.optDouble(3);
+    assertEquals(2, arrayOptCalls);
+    assertEquals(2, arrayOptTypeCalls);
+    array.optInt(3);
+    assertEquals(3, arrayOptCalls);
+    assertEquals(3, arrayOptTypeCalls);
+    array.optLong(3);
+    assertEquals(4, arrayOptCalls);
+    assertEquals(4, arrayOptTypeCalls);
+    array.optString(3);
+    assertEquals(5, arrayOptCalls);
+    assertEquals(5, arrayOptTypeCalls);
+  }
+
+  @Test
+  public void testToJSONObject() throws JSONException {
+    array.put("foo");
+    array.put("baz");
+    array.put("bar");
+    JSONArray values = new JSONArray();
+    values.put(5.5d);
+    values.put(11d);
+    values.put(30);
+    values.toJSONObject(array);
+    assertEquals(3, arrayOptCalls);
+    assertEquals(0, arrayOptTypeCalls);
+  }
+
+  @Test
+  public void testNextExpecting() throws JSONException {
+    tokener.next('{');
+    assertEquals(1, tokenerNextCalls);
+    tokener.next('\"');
+    assertEquals(2, tokenerNextCalls);
+  }
+
+  @Test
+  public void testNextValue() throws JSONException {
+    tokener.nextValue();
+    assertEquals(4, tokenerNextValueCalls);
+  }
 }


[34/34] geode git commit: Upgrade mockito

Posted by kl...@apache.org.
Upgrade mockito


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/5b3cbca1
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/5b3cbca1
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/5b3cbca1

Branch: refs/heads/GEODE-4160-mockito
Commit: 5b3cbca10bc98abe74e0e17142017e77c8bdbc49
Parents: bc32a76
Author: Kirk Lund <kl...@apache.org>
Authored: Fri Feb 24 21:10:50 2017 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Feb 28 14:58:30 2017 -0800

----------------------------------------------------------------------
 geode-core/build.gradle                                 |  4 ----
 .../query/internal/index/HashIndexSetJUnitTest.java     |  2 +-
 .../gms/messenger/JGroupsMessengerJUnitTest.java        |  6 +++---
 .../cache/tier/sockets/command/ContainsKey66Test.java   |  2 +-
 .../cache/tier/sockets/command/CreateRegionTest.java    |  2 +-
 .../cache/tier/sockets/command/Destroy65Test.java       |  2 +-
 .../cache/tier/sockets/command/DestroyRegionTest.java   |  2 +-
 .../cache/tier/sockets/command/DestroyTest.java         |  2 +-
 .../tier/sockets/command/ExecuteFunction65Test.java     |  2 +-
 .../tier/sockets/command/ExecuteFunction66Test.java     |  2 +-
 .../cache/tier/sockets/command/ExecuteFunctionTest.java |  2 +-
 .../internal/cache/tier/sockets/command/Get70Test.java  |  2 +-
 .../cache/tier/sockets/command/GetAll651Test.java       |  2 +-
 .../cache/tier/sockets/command/GetAll70Test.java        |  2 +-
 .../internal/cache/tier/sockets/command/GetAllTest.java |  2 +-
 .../tier/sockets/command/GetAllWithCallbackTest.java    |  2 +-
 .../cache/tier/sockets/command/InvalidateTest.java      |  2 +-
 .../internal/cache/tier/sockets/command/KeySetTest.java |  2 +-
 .../internal/cache/tier/sockets/command/Put61Test.java  |  2 +-
 .../internal/cache/tier/sockets/command/Put65Test.java  |  2 +-
 .../internal/cache/tier/sockets/command/PutTest.java    |  2 +-
 .../tier/sockets/command/RegisterInterest61Test.java    |  2 +-
 .../sockets/command/RegisterInterestList61Test.java     |  2 +-
 .../sockets/command/RegisterInterestList66Test.java     |  2 +-
 .../tier/sockets/command/RegisterInterestListTest.java  |  2 +-
 .../tier/sockets/command/RegisterInterestTest.java      |  2 +-
 .../cache/tier/sockets/command/RemoveAllTest.java       |  2 +-
 .../cache/tier/sockets/command/RequestTest.java         |  2 +-
 .../tier/sockets/command/UnregisterInterestTest.java    |  2 +-
 .../beans/DistributedSystemBridgeJUnitTest.java         |  2 +-
 .../cache/lucene/internal/LuceneIndexFactorySpy.java    |  2 +-
 .../internal/PartitionedRepositoryManagerJUnitTest.java |  2 +-
 .../distributed/LuceneQueryFunctionJUnitTest.java       | 12 ++++++------
 .../TopEntriesFunctionCollectorJUnitTest.java           |  4 ++--
 .../geode/cache/lucene/test/IndexRepositorySpy.java     |  2 +-
 geode-pulse/build.gradle                                |  3 ---
 gradle/dependency-versions.properties                   |  4 ++--
 gradle/test.gradle                                      |  7 ++++++-
 38 files changed, 50 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/build.gradle
----------------------------------------------------------------------
diff --git a/geode-core/build.gradle b/geode-core/build.gradle
index 757599a..45a2385 100755
--- a/geode-core/build.gradle
+++ b/geode-core/build.gradle
@@ -133,10 +133,6 @@ dependencies {
   testCompile 'net.spy:spymemcached:' + project.'spymemcached.version'
   testCompile 'redis.clients:jedis:' + project.'jedis.version'
 
-  testCompile 'org.powermock:powermock-core:' + project.'powermock.version'
-  testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
-  testCompile 'org.powermock:powermock-api-mockito:' + project.'powermock.version'
-
   testCompile 'com.pholser:junit-quickcheck-core:' + project.'junit-quickcheck.version'
   testCompile 'com.pholser:junit-quickcheck-generators:' + project.'junit-quickcheck.version'
   testCompile 'com.pholser:junit-quickcheck-guava:' + project.'junit-quickcheck.version'

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/HashIndexSetJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/HashIndexSetJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/HashIndexSetJUnitTest.java
index 20fc1e1..067ae83 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/HashIndexSetJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/HashIndexSetJUnitTest.java
@@ -493,7 +493,7 @@ public class HashIndexSetJUnitTest {
 
     @Override
     public Object answer(InvocationOnMock invocation) throws Throwable {
-      Object evalOn = invocation.getArgumentAt(0, Object.class);
+      Object evalOn = invocation.getArgument(0);
       if (evalOn instanceof Portfolio) {
         Portfolio p = (Portfolio) evalOn;
         return p.indexKey;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
index 307b594..37ab575 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
@@ -44,7 +44,7 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
 
 import static org.apache.geode.distributed.ConfigurationProperties.*;
 import static org.junit.Assert.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.io.ByteArrayInputStream;
@@ -261,7 +261,7 @@ public class JGroupsMessengerJUnitTest {
       } else {
         // for mcast we send a direct-ack message and expect the messenger
         // to register it
-        stub(msg.isDirectAck()).toReturn(true);
+        when(msg.isDirectAck()).thenReturn(true);
       }
       when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
 
@@ -414,7 +414,7 @@ public class JGroupsMessengerJUnitTest {
       } else {
         // for mcast we send a direct-ack message and expect the messenger
         // to register it
-        stub(msg.isDirectAck()).toReturn(true);
+        when(msg.isDirectAck()).thenReturn(true);
       }
       when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
       interceptor.collectMessages = true;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
index 1297a62..ba109f2 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/CreateRegionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/CreateRegionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/CreateRegionTest.java
index 0b411dd..bf5f41f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/CreateRegionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/CreateRegionTest.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Destroy65Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Destroy65Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Destroy65Test.java
index ffc462a..4e5db7d 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Destroy65Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Destroy65Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyRegionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyRegionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyRegionTest.java
index 808792a..8651449 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyRegionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyRegionTest.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyTest.java
index ce869ab..8d77809 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/DestroyTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.nio.ByteBuffer;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction65Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction65Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction65Test.java
index 8df33ab..31b8243 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction65Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction65Test.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction66Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction66Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction66Test.java
index 3c60419..2fde252 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction66Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunction66Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunctionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunctionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunctionTest.java
index 67b5ca6..23b0076 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunctionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteFunctionTest.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Rule;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Get70Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Get70Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Get70Test.java
index ca08f03..d5d26cd 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Get70Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Get70Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll651Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll651Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll651Test.java
index e82b1f2..df1c4f8 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll651Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll651Test.java
@@ -16,7 +16,7 @@ package org.apache.geode.internal.cache.tier.sockets.command;
 
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll70Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll70Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll70Test.java
index 9806c6e..a006034 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll70Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAll70Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllTest.java
index 2554560..f884d6c 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllWithCallbackTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllWithCallbackTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllWithCallbackTest.java
index 415f8f9..ee854bd 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllWithCallbackTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/GetAllWithCallbackTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/InvalidateTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/InvalidateTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/InvalidateTest.java
index 971179c..e65b503 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/InvalidateTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/InvalidateTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/KeySetTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/KeySetTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/KeySetTest.java
index 3ca8b3b..4b82084 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/KeySetTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/KeySetTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put61Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put61Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put61Test.java
index 03a9321..5d720d4 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put61Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put61Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put65Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put65Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put65Test.java
index cf30b35..d776ce7 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put65Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/Put65Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/PutTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/PutTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/PutTest.java
index 5197b21..1761479 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/PutTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/PutTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterest61Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterest61Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterest61Test.java
index 495f772..d77cc64 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterest61Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterest61Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList61Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList61Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList61Test.java
index 94bd633..2cd09d5 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList61Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList61Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList66Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList66Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList66Test.java
index bc92d54..be8e125 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList66Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestList66Test.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.ArrayList;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestListTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestListTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestListTest.java
index 1832ca2..b1db6cf 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestListTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestListTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestTest.java
index 317347f..5bf6f6e 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RegisterInterestTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.util.Properties;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RemoveAllTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RemoveAllTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RemoveAllTest.java
index dca4127..377cdb5 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RemoveAllTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RemoveAllTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.internal.cache.tier.sockets.command;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RequestTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RequestTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RequestTest.java
index 33ee145..5362f53 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RequestTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/RequestTest.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/UnregisterInterestTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/UnregisterInterestTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/UnregisterInterestTest.java
index 157e0f3..2638171 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/UnregisterInterestTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/UnregisterInterestTest.java
@@ -14,7 +14,7 @@
  */
 package org.apache.geode.internal.cache.tier.sockets.command;
 
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-core/src/test/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeJUnitTest.java
index a886ff7..bdf097e 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/beans/DistributedSystemBridgeJUnitTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.management.internal.beans;
 
 import static org.junit.Assert.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 import java.io.IOException;

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
index 5c6d256..bc8b9f6 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
@@ -65,7 +65,7 @@ public class LuceneIndexFactorySpy extends LuceneIndexFactory {
     public RepositoryManager createRepositoryManager() {
       RepositoryManager repositoryManagerSpy = Mockito.spy(super.createRepositoryManager());
       Answer getRepositoryAnswer = invocation -> {
-        getRepositoryConsumer.accept(invocation.getArgumentAt(0, Object.class));
+        getRepositoryConsumer.accept(invocation.getArgument(0));
         return invocation.callRealMethod();
       };
       try {

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
index 9c603c7..6b0cb3b 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
@@ -15,7 +15,7 @@
 package org.apache.geode.cache.lucene.internal;
 
 import static org.junit.Assert.*;
-import static org.mockito.Matchers.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
index 6a9af9b..122dbc9 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
@@ -87,7 +87,7 @@ public class LuceneQueryFunctionJUnitTest {
     when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
     when(mockRepoManager.getRepositories(eq(mockContext))).thenReturn(repos);
     doAnswer(invocation -> {
-      IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
+      IndexResultCollector collector = invocation.getArgument(2);
       collector.collect(r1_1.getKey(), r1_1.getScore());
       collector.collect(r1_2.getKey(), r1_2.getScore());
       collector.collect(r1_3.getKey(), r1_3.getScore());
@@ -96,7 +96,7 @@ public class LuceneQueryFunctionJUnitTest {
         any(IndexResultCollector.class));
 
     doAnswer(invocation -> {
-      IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
+      IndexResultCollector collector = invocation.getArgument(2);
       collector.collect(r2_1.getKey(), r2_1.getScore());
       collector.collect(r2_2.getKey(), r2_2.getScore());
       return null;
@@ -130,7 +130,7 @@ public class LuceneQueryFunctionJUnitTest {
     when(mockRepoManager.getRepositories(eq(mockContext))).thenReturn(repos);
 
     doAnswer(invocation -> {
-      IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
+      IndexResultCollector collector = invocation.getArgument(2);
       collector.collect(r1_1.getKey(), r1_1.getScore());
       collector.collect(r1_2.getKey(), r1_2.getScore());
       collector.collect(r1_3.getKey(), r1_3.getScore());
@@ -138,7 +138,7 @@ public class LuceneQueryFunctionJUnitTest {
     }).when(mockRepository1).query(eq(query), eq(3), any(IndexResultCollector.class));
 
     doAnswer(invocation -> {
-      IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
+      IndexResultCollector collector = invocation.getArgument(2);
       collector.collect(r2_1.getKey(), r2_1.getScore());
       collector.collect(r2_2.getKey(), r2_2.getScore());
       return null;
@@ -171,7 +171,7 @@ public class LuceneQueryFunctionJUnitTest {
     when(mockRepoManager.getRepositories(eq(mockContext))).thenReturn(repos);
     when(mockManager.newCollector(eq("repo2"))).thenReturn(mockCollector);
     when(mockManager.reduce(any(Collection.class))).thenAnswer(invocation -> {
-      Collection<IndexResultCollector> collectors = invocation.getArgumentAt(0, Collection.class);
+      Collection<IndexResultCollector> collectors = invocation.getArgument(0);
       assertEquals(1, collectors.size());
       assertEquals(mockCollector, collectors.iterator().next());
       return new TopEntriesCollector(null);
@@ -179,7 +179,7 @@ public class LuceneQueryFunctionJUnitTest {
     });
 
     doAnswer(invocation -> {
-      IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
+      IndexResultCollector collector = invocation.getArgument(2);
       collector.collect(r2_1.getKey(), r2_1.getScore());
       return null;
     }).when(mockRepository2).query(eq(query), eq(LuceneQueryFactory.DEFAULT_LIMIT),

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
index bf08877..f6cb7d6 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
@@ -139,8 +139,8 @@ public class TopEntriesFunctionCollectorJUnitTest {
     Mockito.doReturn(mockCollector).when(mockManager)
         .reduce(Mockito.argThat(new ArgumentMatcher<Collection<TopEntriesCollector>>() {
           @Override
-          public boolean matches(Object argument) {
-            Collection<TopEntriesCollector> collectors = (Collection<TopEntriesCollector>) argument;
+          public boolean matches(Collection<TopEntriesCollector> argument) {
+            Collection<TopEntriesCollector> collectors = argument;
             return collectors.contains(result1) && collectors.contains(result2);
           }
         }));

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
index 5fd2abe..e23c857 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
@@ -65,7 +65,7 @@ public class IndexRepositorySpy extends IndexRepositoryFactory {
     final IndexRepository spy = Mockito.spy(indexRepo);
 
     Answer invokeBeforeWrite = invocation -> {
-      beforeWrite.accept(invocation.getArgumentAt(0, Object.class));
+      beforeWrite.accept(invocation.getArgument(0));
       return invocation.callRealMethod();
     };
 

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/geode-pulse/build.gradle
----------------------------------------------------------------------
diff --git a/geode-pulse/build.gradle b/geode-pulse/build.gradle
index 298ae5a..59849da 100755
--- a/geode-pulse/build.gradle
+++ b/geode-pulse/build.gradle
@@ -79,9 +79,6 @@ dependencies {
   testCompile 'org.seleniumhq.selenium:selenium-remote-driver:' + project.'selenium.version'
   testCompile 'org.seleniumhq.selenium:selenium-support:' + project.'selenium.version'
   testCompile 'org.springframework:spring-test:' + project.'springframework.version'
-  testCompile 'org.powermock:powermock-core:' + project.'powermock.version'
-  testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
-  testCompile 'org.powermock:powermock-api-mockito:' + project.'powermock.version'
   testCompile 'com.tdunning:json:' + project.'open-json.version'
 
   testRuntime 'com.google.code.gson:gson:' + project.'google-gson.version'

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index d4a104e..ab537ec 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -65,7 +65,7 @@ junit-quickcheck.version = 0.7
 JUnitParams.version = 1.0.6
 log4j.version = 2.7
 lucene.version = 6.4.1
-mockito-core.version = 1.10.19
+mockito-core.version = 2.7.11
 mockrunner.version = 1.1.2
 mortbay-jetty-servlet-api.version=2.5.20110712
 multithreadedtc.version = 1.01
@@ -75,7 +75,7 @@ mx4j-tools.version = 3.0.1
 netty-all.version = 4.1.8.Final
 open-json.version = 1.8
 phantomjsdriver.version=1.3.0
-powermock.version = 1.6.6
+powermock.version = 1.7.0RC2
 selenium.version=3.0.1
 shiro.version=1.3.2
 slf4j-api.version = 1.7.23

http://git-wip-us.apache.org/repos/asf/geode/blob/5b3cbca1/gradle/test.gradle
----------------------------------------------------------------------
diff --git a/gradle/test.gradle b/gradle/test.gradle
index fd44df8..3015ec0 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -43,10 +43,15 @@ subprojects {
     testCompile 'eu.codearte.catch-exception:catch-throwable:' + project.'catch-throwable.version'
     testCompile 'junit:junit:' + project.'junit.version'
     testCompile 'org.assertj:assertj-core:' + project.'assertj-core.version'
-    testCompile 'org.mockito:mockito-core:' + project.'mockito-core.version'
     testCompile 'org.hamcrest:hamcrest-all:' + project.'hamcrest-all.version'
     testCompile 'org.jmock:jmock-junit4:' + project.'jmock.version'
     testCompile 'org.jmock:jmock-legacy:' + project.'jmock.version'
+
+    testCompile 'org.mockito:mockito-core:' + project.'mockito-core.version'
+    testCompile 'org.powermock:powermock-core:' + project.'powermock.version'
+    testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
+    testCompile 'org.powermock:powermock-api-mockito2:' + project.'powermock.version'
+
     testCompile 'pl.pragmatists:JUnitParams:' + project.'JUnitParams.version'
 
     testRuntime 'cglib:cglib:' + project.'cglib.version'


[09/34] geode git commit: GEODE-2142: Removal of offending JSON.ORG code and license information

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/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
deleted file mode 100755
index a2c6d8b..0000000
--- a/geode-json/src/main/java/org/json/JSONObject.java
+++ /dev/null
@@ -1,1525 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-
-/**
- * A JSONObject is an unordered collection of name/value pairs. Its external form is a string
- * wrapped in curly braces with colons between the names and values, and commas between the values
- * and names. The internal form is an object having <code>get</code> and <code>opt</code> methods
- * for accessing the values by name, and <code>put</code> methods for adding or replacing values by
- * name. The values can be any of these types: <code>Boolean</code>, <code>JSONArray</code>,
- * <code>JSONObject</code>, <code>Number</code>, <code>String</code>, or the
- * <code>JSONObject.NULL</code> object. A JSONObject constructor can be used to convert an external
- * form JSON text into an internal form whose values can be retrieved with the <code>get</code> and
- * <code>opt</code> methods, or to convert values into a JSON text using the <code>put</code> and
- * <code>toString</code> methods. A <code>get</code> method returns a value if one can be found, and
- * throws an exception if one cannot be found. An <code>opt</code> method returns a default value
- * instead of throwing an exception, and so is useful for obtaining optional values.
- * <p>
- * The generic <code>get()</code> and <code>opt()</code> methods return an object, which you can
- * cast or query for type. There are also typed <code>get</code> and <code>opt</code> methods that
- * do type checking and type coercion for you. The opt methods differ from the get methods in that
- * they do not throw. Instead, they return a specified value, such as null.
- * <p>
- * The <code>put</code> methods add or replace values in an object. For example,
- *
- * <pre>
- * myString = new JSONObject().put(&quot;JSON&quot;, &quot;Hello, World!&quot;).toString();
- * </pre>
- *
- * produces the string <code>{"JSON": "Hello, World"}</code>.
- * <p>
- * The texts produced by the <code>toString</code> methods strictly conform to the JSON syntax
- * rules. The constructors are more forgiving in the texts they will accept:
- * <ul>
- * <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear just before the closing
- * brace.</li>
- * <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single quote)</small>.</li>
- * <li>Strings do not need to be quoted at all if they do not begin with a quote or single quote,
- * and if they do not contain leading or trailing spaces, and if they do not contain any of these
- * characters: <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and if they
- * are not the reserved words <code>true</code>, <code>false</code>, or <code>null</code>.</li>
- * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as by <code>:</code>.</li>
- * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as well as by
- * <code>,</code> <small>(comma)</small>.</li>
- * </ul>
- *
- * @author JSON.org
- * @version 2012-05-29
- */
-public class JSONObject {
-  /**
-   * JSONObject.NULL is equivalent to the value that JavaScript calls null, whilst Java's null is
-   * equivalent to the value that JavaScript calls undefined.
-   */
-  private static final class Null {
-
-    /**
-     * There is only intended to be a single instance of the NULL object, so the clone method
-     * returns itself.
-     * 
-     * @return NULL.
-     */
-    protected final Object clone() {
-      return this;
-    }
-
-    /**
-     * A Null object is equal to the null value and to itself.
-     * 
-     * @param object An object to test for nullness.
-     * @return true if the object parameter is the JSONObject.NULL object or null.
-     */
-    public boolean equals(Object object) {
-      return object == null || object == this;
-    }
-
-    /**
-     * Get the "null" string value.
-     * 
-     * @return The string "null".
-     */
-    public String toString() {
-      return "null";
-    }
-  }
-
-
-  /**
-   * The map where the JSONObject's properties are kept.
-   */
-  private final Map map;
-
-
-  /**
-   * It is sometimes more convenient and less ambiguous to have a <code>NULL</code> object than to
-   * use Java's <code>null</code> value. <code>JSONObject.NULL.equals(null)</code> returns
-   * <code>true</code>. <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.
-   */
-  public static final Object NULL = new Null();
-
-
-  public static ThreadLocal<Set> cyclicDependencySet = new ThreadLocal();
-  public static ThreadLocal<Boolean> cyclicDepChkEnabled = new ThreadLocal();
-
-
-  /**
-   * Construct an empty JSONObject.
-   */
-  public JSONObject() {
-    this.map = new LinkedHashMap();
-  }
-
-
-  /**
-   * Construct a JSONObject from a subset of another JSONObject. An array of strings is used to
-   * identify the keys that should be copied. Missing keys are ignored.
-   * 
-   * @param jo A JSONObject.
-   * @param names An array of strings.
-   */
-  public JSONObject(JSONObject jo, String[] names) {
-    this();
-    for (int i = 0; i < names.length; i += 1) {
-      try {
-        this.putOnce(names[i], jo.opt(names[i]));
-      } catch (Exception ignore) {
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONObject from a JSONTokener.
-   * 
-   * @param x A JSONTokener object containing the source string.
-   * @throws JSONException If there is a syntax error in the source string or a duplicated key.
-   */
-  public JSONObject(JSONTokener x) throws JSONException {
-    this();
-    char c;
-    String key;
-
-    if (x.nextClean() != '{') {
-      throw x.syntaxError("A JSONObject text must begin with '{'");
-    }
-    for (;;) {
-      c = x.nextClean();
-      switch (c) {
-        case 0:
-          throw x.syntaxError("A JSONObject text must end with '}'");
-        case '}':
-          return;
-        default:
-          x.back();
-          key = x.nextValue().toString();
-      }
-
-      // The key is followed by ':'. We will also tolerate '=' or '=>'.
-
-      c = x.nextClean();
-      if (c == '=') {
-        if (x.next() != '>') {
-          x.back();
-        }
-      } else if (c != ':') {
-        throw x.syntaxError("Expected a ':' after a key");
-      }
-      this.putOnce(key, x.nextValue());
-
-      // Pairs are separated by ','. We will also tolerate ';'.
-
-      switch (x.nextClean()) {
-        case ';':
-        case ',':
-          if (x.nextClean() == '}') {
-            return;
-          }
-          x.back();
-          break;
-        case '}':
-          return;
-        default:
-          throw x.syntaxError("Expected a ',' or '}'");
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONObject from a Map.
-   *
-   * @param map A map object that can be used to initialize the contents of the JSONObject.
-   */
-  public JSONObject(Map map) {
-    this.map = new LinkedHashMap();
-    if (map != null) {
-      Iterator i = map.entrySet().iterator();
-      while (i.hasNext()) {
-        Map.Entry e = (Map.Entry) i.next();
-        Object value = e.getValue();
-        if (value != null) {
-          this.map.put(e.getKey(), wrap(value));
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONObject from an Object using bean getters. It reflects on all of the public
-   * methods of the object. For each of the methods with no parameters and a name starting with
-   * <code>"get"</code> or <code>"is"</code> followed by an uppercase letter, the method is invoked,
-   * and a key and the value returned from the getter method are put into the new JSONObject.
-   *
-   * The key is formed by removing the <code>"get"</code> or <code>"is"</code> prefix. If the second
-   * remaining character is not upper case, then the first character is converted to lower case.
-   *
-   * For example, if an object has a method named <code>"getName"</code>, and if the result of
-   * calling <code>object.getName()</code> is <code>"Larry Fine"</code>, then the JSONObject will
-   * contain <code>"name": "Larry Fine"</code>.
-   *
-   * @param bean An object that has getter methods that should be used to make a JSONObject.
-   */
-  public JSONObject(Object bean) {
-    this();
-    this.populateMap(bean);
-  }
-
-
-  /**
-   * Construct a JSONObject from an Object, using reflection to find the public members. The
-   * resulting JSONObject's keys will be the strings from the names array, and the values will be
-   * the field values associated with those keys in the object. If a key is not found or not
-   * visible, then it will not be copied into the new JSONObject.
-   * 
-   * @param object An object that has fields that should be used to make a JSONObject.
-   * @param names An array of strings, the names of the fields to be obtained from the object.
-   */
-  public JSONObject(Object object, String names[]) {
-    this();
-    Class c = object.getClass();
-    for (int i = 0; i < names.length; i += 1) {
-      String name = names[i];
-      try {
-        this.putOpt(name, c.getField(name).get(object));
-      } catch (Exception ignore) {
-      }
-    }
-  }
-
-
-  /**
-   * Construct a JSONObject from a source JSON text string. This is the most commonly used
-   * JSONObject constructor.
-   * 
-   * @param source A string beginning with <code>{</code>&nbsp;<small>(left brace)</small> and
-   *        ending with <code>}</code>&nbsp;<small>(right brace)</small>.
-   * @exception JSONException If there is a syntax error in the source string or a duplicated key.
-   */
-  public JSONObject(String source) throws JSONException {
-    this(new JSONTokener(source));
-  }
-
-
-  /**
-   * Construct a JSONObject from a ResourceBundle.
-   * 
-   * @param baseName The ResourceBundle base name.
-   * @param locale The Locale to load the ResourceBundle for.
-   * @throws JSONException If any JSONExceptions are detected.
-   */
-  public JSONObject(String baseName, Locale locale) throws JSONException {
-    this();
-    ResourceBundle bundle =
-        ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
-
-    // Iterate through the keys in the bundle.
-
-    Enumeration keys = bundle.getKeys();
-    while (keys.hasMoreElements()) {
-      Object key = keys.nextElement();
-      if (key instanceof String) {
-
-        // Go through the path, ensuring that there is a nested JSONObject for each
-        // segment except the last. Add the value using the last segment's name into
-        // the deepest nested JSONObject.
-
-        String[] path = ((String) key).split("\\.");
-        int last = path.length - 1;
-        JSONObject target = this;
-        for (int i = 0; i < last; i += 1) {
-          String segment = path[i];
-          JSONObject nextTarget = target.optJSONObject(segment);
-          if (nextTarget == null) {
-            nextTarget = new JSONObject();
-            target.put(segment, nextTarget);
-          }
-          target = nextTarget;
-        }
-        target.put(path[last], bundle.getString((String) key));
-      }
-    }
-  }
-
-
-  /**
-   * Accumulate values under a key. It is similar to the put method except that if there is already
-   * an object stored under the key then a JSONArray is stored under the key to hold all of the
-   * accumulated values. If there is already a JSONArray, then the new value is appended to it. In
-   * contrast, the put method replaces the previous value.
-   *
-   * If only one value is accumulated that is not a JSONArray, then the result will be the same as
-   * using put. But if multiple values are accumulated, then the result will be like append.
-   * 
-   * @param key A key string.
-   * @param value An object to be accumulated under the key.
-   * @return this.
-   * @throws JSONException If the value is an invalid number or if the key is null.
-   */
-  public JSONObject accumulate(String key, Object value) throws JSONException {
-    testValidity(value);
-    Object object = this.opt(key);
-    if (object == null) {
-      this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
-    } else if (object instanceof JSONArray) {
-      ((JSONArray) object).put(value);
-    } else {
-      this.put(key, new JSONArray().put(object).put(value));
-    }
-    return this;
-  }
-
-
-  /**
-   * Append values to the array under a key. If the key does not exist in the JSONObject, then the
-   * key is put in the JSONObject with its value being a JSONArray containing the value parameter.
-   * If the key was already associated with a JSONArray, then the value parameter is appended to it.
-   * 
-   * @param key A key string.
-   * @param value An object to be accumulated under the key.
-   * @return this.
-   * @throws JSONException If the key is null or if the current value associated with the key is not
-   *         a JSONArray.
-   */
-  public JSONObject append(String key, Object value) throws JSONException {
-    testValidity(value);
-    Object object = this.opt(key);
-    if (object == null) {
-      this.put(key, new JSONArray().put(value));
-    } else if (object instanceof JSONArray) {
-      this.put(key, ((JSONArray) object).put(value));
-    } else {
-      throw new JSONException("JSONObject[" + key + "] is not a JSONArray.");
-    }
-    return this;
-  }
-
-
-  /**
-   * Produce a string from a double. The string "null" will be returned if the number is not finite.
-   * 
-   * @param d A double.
-   * @return A String.
-   */
-  public static String doubleToString(double d) {
-    if (Double.isInfinite(d) || Double.isNaN(d)) {
-      return "null";
-    }
-
-    // Shave off trailing zeros and decimal point, if possible.
-
-    String string = Double.toString(d);
-    if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
-      while (string.endsWith("0")) {
-        string = string.substring(0, string.length() - 1);
-      }
-      if (string.endsWith(".")) {
-        string = string.substring(0, string.length() - 1);
-      }
-    }
-    return string;
-  }
-
-
-  /**
-   * Get the value object associated with a key.
-   *
-   * @param key A key string.
-   * @return The object associated with the key.
-   * @throws JSONException if the key is not found.
-   */
-  public Object get(String key) throws JSONException {
-    if (key == null) {
-      throw new JSONException("Null key.");
-    }
-    Object object = this.opt(key);
-    if (object == null) {
-      throw new JSONException("JSONObject[" + quote(key) + "] not found.");
-    }
-    return object;
-  }
-
-
-  /**
-   * Get the boolean value associated with a key.
-   *
-   * @param key A key string.
-   * @return The truth.
-   * @throws JSONException if the value is not a Boolean or the String "true" or "false".
-   */
-  public boolean getBoolean(String key) throws JSONException {
-    Object object = this.get(key);
-    if (object.equals(Boolean.FALSE)
-        || (object instanceof String && ((String) object).equalsIgnoreCase("false"))) {
-      return false;
-    } else if (object.equals(Boolean.TRUE)
-        || (object instanceof String && ((String) object).equalsIgnoreCase("true"))) {
-      return true;
-    }
-    throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean.");
-  }
-
-
-  /**
-   * Get the double value associated with a key.
-   * 
-   * @param key A key string.
-   * @return The numeric value.
-   * @throws JSONException if the key is not found or if the value is not a Number object and cannot
-   *         be converted to a number.
-   */
-  public double getDouble(String key) throws JSONException {
-    Object object = this.get(key);
-    try {
-      return object instanceof Number ? ((Number) object).doubleValue()
-          : Double.parseDouble((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
-    }
-  }
-
-
-  /**
-   * Get the int value associated with a key.
-   *
-   * @param key A key string.
-   * @return The integer value.
-   * @throws JSONException if the key is not found or if the value cannot be converted to an
-   *         integer.
-   */
-  public int getInt(String key) throws JSONException {
-    Object object = this.get(key);
-    try {
-      return object instanceof Number ? ((Number) object).intValue()
-          : Integer.parseInt((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
-    }
-  }
-
-
-  /**
-   * Get the JSONArray value associated with a key.
-   *
-   * @param key A key string.
-   * @return A JSONArray which is the value.
-   * @throws JSONException if the key is not found or if the value is not a JSONArray.
-   */
-  public JSONArray getJSONArray(String key) throws JSONException {
-    Object object = this.get(key);
-    if (object instanceof JSONArray) {
-      return (JSONArray) object;
-    }
-    throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray.");
-  }
-
-
-  /**
-   * Get the JSONObject value associated with a key.
-   *
-   * @param key A key string.
-   * @return A JSONObject which is the value.
-   * @throws JSONException if the key is not found or if the value is not a JSONObject.
-   */
-  public JSONObject getJSONObject(String key) throws JSONException {
-    Object object = this.get(key);
-    if (object instanceof JSONObject) {
-      return (JSONObject) object;
-    }
-    throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
-  }
-
-
-  /**
-   * Get the long value associated with a key.
-   *
-   * @param key A key string.
-   * @return The long value.
-   * @throws JSONException if the key is not found or if the value cannot be converted to a long.
-   */
-  public long getLong(String key) throws JSONException {
-    Object object = this.get(key);
-    try {
-      return object instanceof Number ? ((Number) object).longValue()
-          : Long.parseLong((String) object);
-    } catch (Exception e) {
-      throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
-    }
-  }
-
-
-  /**
-   * Get an array of field names from a JSONObject.
-   *
-   * @return An array of field names, or null if there are no names.
-   */
-  public static String[] getNames(JSONObject jo) {
-    int length = jo.length();
-    if (length == 0) {
-      return null;
-    }
-    Iterator iterator = jo.keys();
-    String[] names = new String[length];
-    int i = 0;
-    while (iterator.hasNext()) {
-      names[i] = (String) iterator.next();
-      i += 1;
-    }
-    return names;
-  }
-
-
-  /**
-   * Get an array of field names from an Object.
-   *
-   * @return An array of field names, or null if there are no names.
-   */
-  public static String[] getNames(Object object) {
-    if (object == null) {
-      return null;
-    }
-    Class klass = object.getClass();
-    Field[] fields = klass.getFields();
-    int length = fields.length;
-    if (length == 0) {
-      return null;
-    }
-    String[] names = new String[length];
-    for (int i = 0; i < length; i += 1) {
-      names[i] = fields[i].getName();
-    }
-    return names;
-  }
-
-
-  /**
-   * Get the string associated with a key.
-   *
-   * @param key A key string.
-   * @return A string which is the value.
-   * @throws JSONException if there is no string value for the key.
-   */
-  public String getString(String key) throws JSONException {
-    Object object = this.get(key);
-    if (object instanceof String) {
-      return (String) object;
-    }
-    throw new JSONException("JSONObject[" + quote(key) + "] not a string.");
-  }
-
-
-  /**
-   * Determine if the JSONObject contains a specific key.
-   * 
-   * @param key A key string.
-   * @return true if the key exists in the JSONObject.
-   */
-  public boolean has(String key) {
-    return this.map.containsKey(key);
-  }
-
-
-  /**
-   * Increment a property of a JSONObject. If there is no such property, create one with a value of
-   * 1. If there is such a property, and if it is an Integer, Long, Double, or Float, then add one
-   * to it.
-   * 
-   * @param key A key string.
-   * @return this.
-   * @throws JSONException If there is already a property with this name that is not an Integer,
-   *         Long, Double, or Float.
-   */
-  public JSONObject increment(String key) throws JSONException {
-    Object value = this.opt(key);
-    if (value == null) {
-      this.put(key, 1);
-    } else if (value instanceof Integer) {
-      this.put(key, ((Integer) value).intValue() + 1);
-    } else if (value instanceof Long) {
-      this.put(key, ((Long) value).longValue() + 1);
-    } else if (value instanceof Double) {
-      this.put(key, ((Double) value).doubleValue() + 1);
-    } else if (value instanceof Float) {
-      this.put(key, ((Float) value).floatValue() + 1);
-    } else {
-      throw new JSONException("Unable to increment [" + quote(key) + "].");
-    }
-    return this;
-  }
-
-
-  /**
-   * Determine if the value associated with the key is null or if there is no value.
-   * 
-   * @param key A key string.
-   * @return true if there is no value associated with the key or if the value is the
-   *         JSONObject.NULL object.
-   */
-  public boolean isNull(String key) {
-    return JSONObject.NULL.equals(this.opt(key));
-  }
-
-
-  /**
-   * Get an enumeration of the keys of the JSONObject.
-   *
-   * @return An iterator of the keys.
-   */
-  public Iterator keys() {
-    return this.map.keySet().iterator();
-  }
-
-
-  /**
-   * Get the number of keys stored in the JSONObject.
-   *
-   * @return The number of keys in the JSONObject.
-   */
-  public int length() {
-    return this.map.size();
-  }
-
-
-  /**
-   * Produce a JSONArray containing the names of the elements of this JSONObject.
-   * 
-   * @return A JSONArray containing the key strings, or null if the JSONObject is empty.
-   */
-  public JSONArray names() {
-    JSONArray ja = new JSONArray();
-    Iterator keys = this.keys();
-    while (keys.hasNext()) {
-      ja.put(keys.next());
-    }
-    return ja.length() == 0 ? null : ja;
-  }
-
-  /**
-   * Produce a string from a Number.
-   * 
-   * @param number A Number
-   * @return A String.
-   * @throws JSONException If n is a non-finite number.
-   */
-  public static String numberToString(Number number) throws JSONException {
-    if (number == null) {
-      throw new JSONException("Null pointer");
-    }
-    testValidity(number);
-
-    // Shave off trailing zeros and decimal point, if possible.
-
-    String string = number.toString();
-    if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
-      while (string.endsWith("0")) {
-        string = string.substring(0, string.length() - 1);
-      }
-      if (string.endsWith(".")) {
-        string = string.substring(0, string.length() - 1);
-      }
-    }
-    return string;
-  }
-
-
-  /**
-   * Get an optional value associated with a key.
-   * 
-   * @param key A key string.
-   * @return An object which is the value, or null if there is no value.
-   */
-  public Object opt(String key) {
-    return key == null ? null : this.map.get(key);
-  }
-
-
-  /**
-   * Get an optional boolean associated with a key. It returns false if there is no such key, or if
-   * the value is not Boolean.TRUE or the String "true".
-   *
-   * @param key A key string.
-   * @return The truth.
-   */
-  public boolean optBoolean(String key) {
-    return this.optBoolean(key, false);
-  }
-
-
-  /**
-   * Get an optional boolean associated with a key. It returns the defaultValue if there is no such
-   * key, or if it is not a Boolean or the String "true" or "false" (case insensitive).
-   *
-   * @param key A key string.
-   * @param defaultValue The default.
-   * @return The truth.
-   */
-  public boolean optBoolean(String key, boolean defaultValue) {
-    try {
-      return this.getBoolean(key);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get an optional double associated with a key, or NaN if there is no such key or if its value is
-   * not a number. If the value is a string, an attempt will be made to evaluate it as a number.
-   *
-   * @param key A string which is the key.
-   * @return An object which is the value.
-   */
-  public double optDouble(String key) {
-    return this.optDouble(key, Double.NaN);
-  }
-
-
-  /**
-   * Get an optional double associated with a key, or the defaultValue if there is no such key or if
-   * its value is not a number. If the value is a string, an attempt will be made to evaluate it as
-   * a number.
-   *
-   * @param key A key string.
-   * @param defaultValue The default.
-   * @return An object which is the value.
-   */
-  public double optDouble(String key, double defaultValue) {
-    try {
-      return this.getDouble(key);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get an optional int value associated with a key, or zero if there is no such key or if the
-   * value is not a number. If the value is a string, an attempt will be made to evaluate it as a
-   * number.
-   *
-   * @param key A key string.
-   * @return An object which is the value.
-   */
-  public int optInt(String key) {
-    return this.optInt(key, 0);
-  }
-
-
-  /**
-   * Get an optional int value associated with a key, or the default if there is no such key or if
-   * the value is not a number. If the value is a string, an attempt will be made to evaluate it as
-   * a number.
-   *
-   * @param key A key string.
-   * @param defaultValue The default.
-   * @return An object which is the value.
-   */
-  public int optInt(String key, int defaultValue) {
-    try {
-      return this.getInt(key);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get an optional JSONArray associated with a key. It returns null if there is no such key, or if
-   * its value is not a JSONArray.
-   *
-   * @param key A key string.
-   * @return A JSONArray which is the value.
-   */
-  public JSONArray optJSONArray(String key) {
-    Object o = this.opt(key);
-    return o instanceof JSONArray ? (JSONArray) o : null;
-  }
-
-
-  /**
-   * Get an optional JSONObject associated with a key. It returns null if there is no such key, or
-   * if its value is not a JSONObject.
-   *
-   * @param key A key string.
-   * @return A JSONObject which is the value.
-   */
-  public JSONObject optJSONObject(String key) {
-    Object object = this.opt(key);
-    return object instanceof JSONObject ? (JSONObject) object : null;
-  }
-
-
-  /**
-   * Get an optional long value associated with a key, or zero if there is no such key or if the
-   * value is not a number. If the value is a string, an attempt will be made to evaluate it as a
-   * number.
-   *
-   * @param key A key string.
-   * @return An object which is the value.
-   */
-  public long optLong(String key) {
-    return this.optLong(key, 0);
-  }
-
-
-  /**
-   * Get an optional long value associated with a key, or the default if there is no such key or if
-   * the value is not a number. If the value is a string, an attempt will be made to evaluate it as
-   * a number.
-   *
-   * @param key A key string.
-   * @param defaultValue The default.
-   * @return An object which is the value.
-   */
-  public long optLong(String key, long defaultValue) {
-    try {
-      return this.getLong(key);
-    } catch (Exception e) {
-      return defaultValue;
-    }
-  }
-
-
-  /**
-   * Get an optional string associated with a key. It returns an empty string if there is no such
-   * key. If the value is not a string and is not null, then it is converted to a string.
-   *
-   * @param key A key string.
-   * @return A string which is the value.
-   */
-  public String optString(String key) {
-    return this.optString(key, "");
-  }
-
-
-  /**
-   * Get an optional string associated with a key. It returns the defaultValue if there is no such
-   * key.
-   *
-   * @param key A key string.
-   * @param defaultValue The default.
-   * @return A string which is the value.
-   */
-  public String optString(String key, String defaultValue) {
-    Object object = this.opt(key);
-    return NULL.equals(object) ? defaultValue : object.toString();
-  }
-
-
-  private void populateMap(Object bean) {
-    Class klass = bean.getClass();
-
-    // If klass is a System class then set includeSuperClass to false.
-
-    boolean includeSuperClass = klass.getClassLoader() != null;
-
-    Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
-    for (int i = 0; i < methods.length; i += 1) {
-      try {
-        Method method = methods[i];
-        if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
-          String name = method.getName();
-          String key = "";
-          if (name.startsWith("get")) {
-            if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
-              key = "";
-            } else {
-              key = name.substring(3);
-            }
-          } else if (name.startsWith("is")) {
-            key = name.substring(2);
-          }
-          if (key.length() > 0 && Character.isUpperCase(key.charAt(0))
-              && method.getParameterTypes().length == 0) {
-            if (key.length() == 1) {
-              key = key.toLowerCase();
-            } else if (!Character.isUpperCase(key.charAt(1))) {
-              key = key.substring(0, 1).toLowerCase() + key.substring(1);
-            }
-            Object result = method.invoke(bean, (Object[]) null);
-            if (result != null) {
-              this.map.put(key, wrap(result));
-            } else if (!method.getReturnType().isArray()) {
-              this.map.put(key, JSONObject.NULL);
-            }
-          }
-        }
-      } catch (Exception ignore) {
-      }
-    }
-    this.map.put("type-class", klass.getCanonicalName());
-  }
-
-
-  /**
-   * Put a key/boolean pair in the JSONObject.
-   *
-   * @param key A key string.
-   * @param value A boolean which is the value.
-   * @return this.
-   * @throws JSONException If the key is null.
-   */
-  public JSONObject put(String key, boolean value) throws JSONException {
-    this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
-    return this;
-  }
-
-
-  /**
-   * Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced
-   * from a Collection.
-   * 
-   * @param key A key string.
-   * @param value A Collection value.
-   * @return this.
-   * @throws JSONException
-   */
-  public JSONObject put(String key, Collection value) throws JSONException {
-    this.put(key, new JSONArray(value));
-    return this;
-  }
-
-
-  /**
-   * Put a key/double pair in the JSONObject.
-   *
-   * @param key A key string.
-   * @param value A double which is the value.
-   * @return this.
-   * @throws JSONException If the key is null or if the number is invalid.
-   */
-  public JSONObject put(String key, double value) throws JSONException {
-    this.put(key, new Double(value));
-    return this;
-  }
-
-
-  /**
-   * Put a key/int pair in the JSONObject.
-   *
-   * @param key A key string.
-   * @param value An int which is the value.
-   * @return this.
-   * @throws JSONException If the key is null.
-   */
-  public JSONObject put(String key, int value) throws JSONException {
-    this.put(key, new Integer(value));
-    return this;
-  }
-
-
-  /**
-   * Put a key/long pair in the JSONObject.
-   *
-   * @param key A key string.
-   * @param value A long which is the value.
-   * @return this.
-   * @throws JSONException If the key is null.
-   */
-  public JSONObject put(String key, long value) throws JSONException {
-    this.put(key, new Long(value));
-    return this;
-  }
-
-
-  /**
-   * Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced
-   * from a Map.
-   * 
-   * @param key A key string.
-   * @param value A Map value.
-   * @return this.
-   * @throws JSONException
-   */
-  public JSONObject put(String key, Map value) throws JSONException {
-    this.put(key, new JSONObject(value));
-    return this;
-  }
-
-
-  /**
-   * Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from
-   * the JSONObject if it is present.
-   * 
-   * @param key A key string.
-   * @param value An object which is the value. It should be of one of these types: Boolean, Double,
-   *        Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.
-   * @return this.
-   * @throws JSONException If the value is non-finite number or if the key is null.
-   */
-  public JSONObject put(String key, Object value) throws JSONException {
-    if (key == null) {
-      throw new JSONException("Null key.");
-    }
-    if (value != null) {
-      testValidity(value);
-      this.map.put(key, value);
-    } else {
-      this.remove(key);
-    }
-    return this;
-  }
-
-
-  /**
-   * Put a key/value pair in the JSONObject, but only if the key and the value are both non-null,
-   * and only if there is not already a member with that name.
-   * 
-   * @param key
-   * @param value
-   * @return his.
-   * @throws JSONException if the key is a duplicate
-   */
-  public JSONObject putOnce(String key, Object value) throws JSONException {
-    if (key != null && value != null) {
-      if (this.opt(key) != null) {
-        throw new JSONException("Duplicate key \"" + key + "\"");
-      }
-      this.put(key, value);
-    }
-    return this;
-  }
-
-
-  /**
-   * Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
-   * 
-   * @param key A key string.
-   * @param value An object which is the value. It should be of one of these types: Boolean, Double,
-   *        Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.
-   * @return this.
-   * @throws JSONException If the value is a non-finite number.
-   */
-  public JSONObject putOpt(String key, Object value) throws JSONException {
-    if (key != null && value != null) {
-      this.put(key, value);
-    }
-    return this;
-  }
-
-
-  /**
-   * Produce a string in double quotes with backslash sequences in all the right places. A backslash
-   * will be inserted within </, producing <\/, allowing JSON text to be delivered in HTML. In JSON
-   * text, a string cannot contain a control character or an unescaped quote or backslash.
-   * 
-   * @param string A String
-   * @return A String correctly formatted for insertion in a JSON text.
-   */
-  public static String quote(String string) {
-    StringWriter sw = new StringWriter();
-    synchronized (sw.getBuffer()) {
-      try {
-        return quote(string, sw).toString();
-      } catch (IOException ignored) {
-        // will never happen - we are writing to a string writer
-        return "";
-      }
-    }
-  }
-
-  public static Writer quote(String string, Writer w) throws IOException {
-    if (string == null || string.length() == 0) {
-      w.write("\"\"");
-      return w;
-    }
-
-    char b;
-    char c = 0;
-    String hhhh;
-    int i;
-    int len = string.length();
-
-    w.write('"');
-    for (i = 0; i < len; i += 1) {
-      b = c;
-      c = string.charAt(i);
-      switch (c) {
-        case '\\':
-        case '"':
-          w.write('\\');
-          w.write(c);
-          break;
-        case '/':
-          if (b == '<') {
-            w.write('\\');
-          }
-          w.write(c);
-          break;
-        case '\b':
-          w.write("\\b");
-          break;
-        case '\t':
-          w.write("\\t");
-          break;
-        case '\n':
-          w.write("\\n");
-          break;
-        case '\f':
-          w.write("\\f");
-          break;
-        case '\r':
-          w.write("\\r");
-          break;
-        default:
-          if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
-            hhhh = "000" + Integer.toHexString(c);
-            w.write("\\u" + hhhh.substring(hhhh.length() - 4));
-          } else {
-            w.write(c);
-          }
-      }
-    }
-    w.write('"');
-    return w;
-  }
-
-  /**
-   * Remove a name and its value, if present.
-   * 
-   * @param key The name to be removed.
-   * @return The value that was associated with the name, or null if there was no value.
-   */
-  public Object remove(String key) {
-    return this.map.remove(key);
-  }
-
-  /**
-   * Try to convert a string into a number, boolean, or null. If the string can't be converted,
-   * return the string.
-   * 
-   * @param string A String.
-   * @return A simple JSON value.
-   */
-  public static Object stringToValue(String string) {
-    Double d;
-    if (string.equals("")) {
-      return string;
-    }
-    if (string.equalsIgnoreCase("true")) {
-      return Boolean.TRUE;
-    }
-    if (string.equalsIgnoreCase("false")) {
-      return Boolean.FALSE;
-    }
-    if (string.equalsIgnoreCase("null")) {
-      return JSONObject.NULL;
-    }
-
-    /*
-     * If it might be a number, try converting it. If a number cannot be produced, then the value
-     * will just be a string. Note that the plus and implied string conventions are non-standard. A
-     * JSON parser may accept non-JSON forms as long as it accepts all correct JSON forms.
-     */
-
-    char b = string.charAt(0);
-    if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
-      try {
-        if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
-          d = Double.valueOf(string);
-          if (!d.isInfinite() && !d.isNaN()) {
-            return d;
-          }
-        } else {
-          Long myLong = new Long(string);
-          if (myLong.longValue() == myLong.intValue()) {
-            return new Integer(myLong.intValue());
-          } else {
-            return myLong;
-          }
-        }
-      } catch (Exception ignore) {
-      }
-    }
-    return string;
-  }
-
-
-  /**
-   * Throw an exception if the object is a NaN or infinite number.
-   * 
-   * @param o The object to test.
-   * @throws JSONException If o is a non-finite number.
-   */
-  public static void testValidity(Object o) throws JSONException {
-    if (o != null) {
-      if (o instanceof Double) {
-        if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
-          throw new JSONException("JSON does not allow non-finite numbers.");
-        }
-      } else if (o instanceof Float) {
-        if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
-          throw new JSONException("JSON does not allow non-finite numbers.");
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Produce a JSONArray containing the values of the members of this JSONObject.
-   * 
-   * @param names A JSONArray containing a list of key strings. This determines the sequence of the
-   *        values in the result.
-   * @return A JSONArray of values.
-   * @throws JSONException If any of the values are non-finite numbers.
-   */
-  public JSONArray toJSONArray(JSONArray names) throws JSONException {
-    if (names == null || names.length() == 0) {
-      return null;
-    }
-    JSONArray ja = new JSONArray();
-    for (int i = 0; i < names.length(); i += 1) {
-      ja.put(this.opt(names.getString(i)));
-    }
-    return ja;
-  }
-
-  /**
-   * Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not
-   * result in a syntactically correct JSON text, then null will be returned instead.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @return a printable, displayable, portable, transmittable representation of the object,
-   *         beginning with <code>{</code>&nbsp;<small>(left brace)</small> and ending with
-   *         <code>}</code>&nbsp;<small>(right brace)</small>.
-   */
-  public String toString() {
-    try {
-      return this.toString(0);
-    } catch (Exception e) {
-      return null;
-    }
-  }
-
-
-  /**
-   * Make a prettyprinted JSON text of this JSONObject.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   * 
-   * @param indentFactor The number of spaces to add to each level of indentation.
-   * @return a printable, displayable, portable, transmittable representation of the object,
-   *         beginning with <code>{</code>&nbsp;<small>(left brace)</small> and ending with
-   *         <code>}</code>&nbsp;<small>(right brace)</small>.
-   * @throws JSONException If the object contains an invalid number.
-   */
-  public String toString(int indentFactor) throws JSONException {
-    StringWriter w = new StringWriter();
-    synchronized (w.getBuffer()) {
-      return this.write(w, indentFactor, 0).toString();
-    }
-  }
-
-  /**
-   * Make a JSON text of an Object value. If the object has an value.toJSONString() method, then
-   * that method will be used to produce the JSON text. The method is required to produce a strictly
-   * conforming text. If the object does not contain a toJSONString method (which is the most common
-   * case), then a text will be produced by other means. If the value is an array or Collection,
-   * then a JSONArray will be made from it and its toJSONString method will be called. If the value
-   * is a MAP, then a JSONObject will be made from it and its toJSONString method will be called.
-   * Otherwise, the value's toString method will be called, and the result will be quoted.
-   *
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   * 
-   * @param value The value to be serialized.
-   * @return a printable, displayable, transmittable representation of the object, beginning with
-   *         <code>{</code>&nbsp;<small>(left brace)</small> and ending with
-   *         <code>}</code>&nbsp;<small>(right brace)</small>.
-   * @throws JSONException If the value is or contains an invalid number.
-   */
-  public static String valueToString(Object value) throws JSONException {
-    if (value == null || value.equals(null)) {
-      return "null";
-    }
-    if (value instanceof JSONString) {
-      Object object;
-      try {
-        object = ((JSONString) value).toJSONString();
-      } catch (Exception e) {
-        throw new JSONException(e);
-      }
-      if (object instanceof String) {
-        return (String) object;
-      }
-      throw new JSONException("Bad value from toJSONString: " + object);
-    }
-    if (value instanceof Number) {
-      return numberToString((Number) value);
-    }
-    if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
-      return value.toString();
-    }
-    if (value instanceof Map) {
-      return new JSONObject((Map) value).toString();
-    }
-    if (value instanceof Collection) {
-      return new JSONArray((Collection) value).toString();
-    }
-    if (value.getClass().isArray()) {
-      return new JSONArray(value).toString();
-    }
-    return quote(value.toString());
-  }
-
-  /**
-   * Wrap an object, if necessary. If the object is null, return the NULL object. If it is an array
-   * or collection, wrap it in a JSONArray. If it is a map, wrap it in a JSONObject. If it is a
-   * standard property (Double, String, et al) then it is already wrapped. Otherwise, if it comes
-   * from one of the java packages, turn it into a string. And if it doesn't, try to wrap it in a
-   * JSONObject. If the wrapping fails, then null is returned.
-   *
-   * @param object The object to wrap
-   * @return The wrapped value
-   */
-  public static Object wrap(Object object) {
-    try {
-      if (object == null) {
-        return NULL;
-      }
-      if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object)
-          || object instanceof JSONString || object instanceof Byte || object instanceof Character
-          || object instanceof Short || object instanceof Integer || object instanceof Long
-          || object instanceof Boolean || object instanceof Float || object instanceof Double
-          || object instanceof String) {
-        return object;
-      }
-
-      if (object instanceof Collection) {
-        return new JSONArray((Collection) object);
-      }
-      if (object.getClass().isArray()) {
-        return new JSONArray(object);
-      }
-      if (object instanceof Map) {
-        return new JSONObject((Map) object);
-      }
-      Package objectPackage = object.getClass().getPackage();
-      String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
-      if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.")
-          || object.getClass().getClassLoader() == null
-          || object.getClass().getName().contains("GemFireCacheImpl")) {
-        return object.toString();
-      }
-
-      if (cyclicDepChkEnabled.get() != null && cyclicDependencySet.get() != null) {
-        if (cyclicDepChkEnabled.get() && cyclicDependencySet.get().contains(object)) {
-          // break cyclic reference
-          return object.getClass().getCanonicalName();
-        } else {
-          cyclicDependencySet.get().add(object);
-          return new JSONObject(object);
-        }
-      } else
-        return new JSONObject(object);
-
-    } catch (Exception exception) {
-      return null;
-    }
-  }
-
-
-  /**
-   * Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace
-   * is added.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @return The writer.
-   * @throws JSONException
-   */
-  public Writer write(Writer writer) throws JSONException {
-    return this.write(writer, 0, 0);
-  }
-
-
-  static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent)
-      throws JSONException, IOException {
-    if (value == null || value.equals(null)) {
-      writer.write("null");
-    } else if (value instanceof JSONObject) {
-      ((JSONObject) value).write(writer, indentFactor, indent);
-    } else if (value instanceof JSONArray) {
-      ((JSONArray) value).write(writer, indentFactor, indent);
-    } else if (value instanceof Map) {
-      new JSONObject((Map) value).write(writer, indentFactor, indent);
-    } else if (value instanceof Collection) {
-      new JSONArray((Collection) value).write(writer, indentFactor, indent);
-    } else if (value.getClass().isArray()) {
-      new JSONArray(value).write(writer, indentFactor, indent);
-    } else if (value instanceof Number) {
-      writer.write(numberToString((Number) value));
-    } else if (value instanceof Boolean) {
-      writer.write(value.toString());
-    } else if (value instanceof JSONString) {
-      Object o;
-      try {
-        o = ((JSONString) value).toJSONString();
-      } catch (Exception e) {
-        throw new JSONException(e);
-      }
-      writer.write(o != null ? o.toString() : quote(value.toString()));
-    } else {
-      quote(value.toString(), writer);
-    }
-    return writer;
-  }
-
-  static final void indent(Writer writer, int indent) throws IOException {
-    for (int i = 0; i < indent; i += 1) {
-      writer.write(' ');
-    }
-  }
-
-  /**
-   * Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace
-   * is added.
-   * <p>
-   * Warning: This method assumes that the data structure is acyclical.
-   *
-   * @return The writer.
-   * @throws JSONException
-   */
-  Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
-    try {
-      boolean commanate = false;
-      final int length = this.length();
-      Iterator keys = this.keys();
-      writer.write('{');
-
-      if (length == 1) {
-        Object key = keys.next();
-        writer.write(quote(key.toString()));
-        writer.write(':');
-        if (indentFactor > 0) {
-          writer.write(' ');
-        }
-        writeValue(writer, this.map.get(key), indentFactor, indent);
-      } else if (length != 0) {
-        final int newindent = indent + indentFactor;
-        while (keys.hasNext()) {
-          Object key = keys.next();
-          if (commanate) {
-            writer.write(',');
-          }
-          if (indentFactor > 0) {
-            writer.write('\n');
-          }
-          indent(writer, newindent);
-          writer.write(quote(key.toString()));
-          writer.write(':');
-          if (indentFactor > 0) {
-            writer.write(' ');
-          }
-          writeValue(writer, this.map.get(key), indentFactor, newindent);
-          commanate = true;
-        }
-        if (indentFactor > 0) {
-          writer.write('\n');
-        }
-        indent(writer, indent);
-      }
-      writer.write('}');
-      return writer;
-    } catch (IOException exception) {
-      throw new JSONException(exception);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/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
deleted file mode 100755
index 4a09d89..0000000
--- a/geode-json/src/main/java/org/json/JSONString.java
+++ /dev/null
@@ -1,17 +0,0 @@
-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.
- */
-public interface JSONString {
-  /**
-   * The <code>toJSONString</code> method allows a class to produce its own JSON serialization.
-   * 
-   * @return A strictly syntactically correct JSON text.
-   */
-  public String toJSONString();
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/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
deleted file mode 100755
index 234e174..0000000
--- a/geode-json/src/main/java/org/json/JSONStringer.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.json;
-
-/*
- * Copyright (c) 2006 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import java.io.StringWriter;
-
-/**
- * JSONStringer provides a quick and convenient way of producing JSON text. The texts produced
- * strictly conform to JSON syntax rules. No whitespace is added, so the results are ready for
- * transmission or storage. Each instance of JSONStringer can produce one JSON text.
- * <p>
- * A JSONStringer instance provides a <code>value</code> method for appending values to the text,
- * and a <code>key</code> method for adding keys before values in objects. There are
- * <code>array</code> and <code>endArray</code> methods that make and bound array values, and
- * <code>object</code> and <code>endObject</code> methods which make and bound object values. All of
- * these methods return the JSONWriter instance, permitting cascade style. For example,
- * 
- * <pre>
- * myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
- * </pre>
- * 
- * which produces the string
- * 
- * <pre>
- * {"JSON":"Hello, World!"}
- * </pre>
- * <p>
- * The first method called must be <code>array</code> or <code>object</code>. There are no methods
- * for adding commas or colons. JSONStringer adds them for you. Objects and arrays can be nested up
- * to 20 levels deep.
- * <p>
- * This can sometimes be easier than using a JSONObject to build a string.
- * 
- * @author JSON.org
- * @version 2008-09-18
- */
-public class JSONStringer extends JSONWriter {
-  /**
-   * Make a fresh JSONStringer. It can be used to build one JSON text.
-   */
-  public JSONStringer() {
-    super(new StringWriter());
-  }
-
-  /**
-   * Return the JSON text. This method is used to obtain the product of the JSONStringer instance.
-   * It will return <code>null</code> if there was a problem in the construction of the JSON text
-   * (such as the calls to <code>array</code> were not properly balanced with calls to
-   * <code>endArray</code>).
-   * 
-   * @return The JSON text.
-   */
-  public String toString() {
-    return this.mode == 'd' ? this.writer.toString() : null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/JSONTokener.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONTokener.java b/geode-json/src/main/java/org/json/JSONTokener.java
deleted file mode 100644
index 4dd2ba2..0000000
--- a/geode-json/src/main/java/org/json/JSONTokener.java
+++ /dev/null
@@ -1,437 +0,0 @@
-package org.json;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-/*
- * Copyright (c) 2002 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the
- * JSONObject and JSONArray constructors to parse JSON source strings.
- * 
- * @author JSON.org
- * @version 2012-02-16
- */
-public class JSONTokener {
-
-  private long character;
-  private boolean eof;
-  private long index;
-  private long line;
-  private char previous;
-  private Reader reader;
-  private boolean usePrevious;
-
-
-  /**
-   * Construct a JSONTokener from a Reader.
-   *
-   * @param reader A reader.
-   */
-  public JSONTokener(Reader reader) {
-    this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
-    this.eof = false;
-    this.usePrevious = false;
-    this.previous = 0;
-    this.index = 0;
-    this.character = 1;
-    this.line = 1;
-  }
-
-
-  /**
-   * Construct a JSONTokener from an InputStream.
-   */
-  public JSONTokener(InputStream inputStream) throws JSONException {
-    this(new InputStreamReader(inputStream));
-  }
-
-
-  /**
-   * Construct a JSONTokener from a string.
-   *
-   * @param s A source string.
-   */
-  public JSONTokener(String s) {
-    this(new StringReader(s));
-  }
-
-
-  /**
-   * Back up one character. This provides a sort of lookahead capability, so that you can test for a
-   * digit or letter before attempting to parse the next number or identifier.
-   */
-  public void back() throws JSONException {
-    if (this.usePrevious || this.index <= 0) {
-      throw new JSONException("Stepping back two steps is not supported");
-    }
-    this.index -= 1;
-    this.character -= 1;
-    this.usePrevious = true;
-    this.eof = false;
-  }
-
-
-  /**
-   * Get the hex value of a character (base16).
-   * 
-   * @param c A character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
-   * @return An int between 0 and 15, or -1 if c was not a hex digit.
-   */
-  public static int dehexchar(char c) {
-    if (c >= '0' && c <= '9') {
-      return c - '0';
-    }
-    if (c >= 'A' && c <= 'F') {
-      return c - ('A' - 10);
-    }
-    if (c >= 'a' && c <= 'f') {
-      return c - ('a' - 10);
-    }
-    return -1;
-  }
-
-  public boolean end() {
-    return this.eof && !this.usePrevious;
-  }
-
-
-  /**
-   * Determine if the source string still contains characters that next() can consume.
-   * 
-   * @return true if not yet at the end of the source.
-   */
-  public boolean more() throws JSONException {
-    this.next();
-    if (this.end()) {
-      return false;
-    }
-    this.back();
-    return true;
-  }
-
-
-  /**
-   * Get the next character in the source string.
-   *
-   * @return The next character, or 0 if past the end of the source string.
-   */
-  public char next() throws JSONException {
-    int c;
-    if (this.usePrevious) {
-      this.usePrevious = false;
-      c = this.previous;
-    } else {
-      try {
-        c = this.reader.read();
-      } catch (IOException exception) {
-        throw new JSONException(exception);
-      }
-
-      if (c <= 0) { // End of stream
-        this.eof = true;
-        c = 0;
-      }
-    }
-    this.index += 1;
-    if (this.previous == '\r') {
-      this.line += 1;
-      this.character = c == '\n' ? 0 : 1;
-    } else if (c == '\n') {
-      this.line += 1;
-      this.character = 0;
-    } else {
-      this.character += 1;
-    }
-    this.previous = (char) c;
-    return this.previous;
-  }
-
-
-  /**
-   * Consume the next character, and check that it matches a specified character.
-   * 
-   * @param c The character to match.
-   * @return The character.
-   * @throws JSONException if the character does not match.
-   */
-  public char next(char c) throws JSONException {
-    char n = this.next();
-    if (n != c) {
-      throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
-    }
-    return n;
-  }
-
-
-  /**
-   * Get the next n characters.
-   *
-   * @param n The number of characters to take.
-   * @return A string of n characters.
-   * @throws JSONException Substring bounds error if there are not n characters remaining in the
-   *         source string.
-   */
-  public String next(int n) throws JSONException {
-    if (n == 0) {
-      return "";
-    }
-
-    char[] chars = new char[n];
-    int pos = 0;
-
-    while (pos < n) {
-      chars[pos] = this.next();
-      if (this.end()) {
-        throw this.syntaxError("Substring bounds error");
-      }
-      pos += 1;
-    }
-    return new String(chars);
-  }
-
-
-  /**
-   * Get the next char in the string, skipping whitespace.
-   * 
-   * @throws JSONException
-   * @return A character, or 0 if there are no more characters.
-   */
-  public char nextClean() throws JSONException {
-    for (;;) {
-      char c = this.next();
-      if (c == 0 || c > ' ') {
-        return c;
-      }
-    }
-  }
-
-
-  /**
-   * Return the characters up to the next close quote character. Backslash processing is done. The
-   * formal JSON format does not allow strings in single quotes, but an implementation is allowed to
-   * accept them.
-   * 
-   * @param quote The quoting character, either <code>"</code>&nbsp;<small>(double quote)</small> or
-   *        <code>'</code>&nbsp;<small>(single quote)</small>.
-   * @return A String.
-   * @throws JSONException Unterminated string.
-   */
-  public String nextString(char quote) throws JSONException {
-    char c;
-    StringBuffer sb = new StringBuffer();
-    for (;;) {
-      c = this.next();
-      switch (c) {
-        case 0:
-        case '\n':
-        case '\r':
-          throw this.syntaxError("Unterminated string");
-        case '\\':
-          c = this.next();
-          switch (c) {
-            case 'b':
-              sb.append('\b');
-              break;
-            case 't':
-              sb.append('\t');
-              break;
-            case 'n':
-              sb.append('\n');
-              break;
-            case 'f':
-              sb.append('\f');
-              break;
-            case 'r':
-              sb.append('\r');
-              break;
-            case 'u':
-              sb.append((char) Integer.parseInt(this.next(4), 16));
-              break;
-            case '"':
-            case '\'':
-            case '\\':
-            case '/':
-              sb.append(c);
-              break;
-            default:
-              throw this.syntaxError("Illegal escape.");
-          }
-          break;
-        default:
-          if (c == quote) {
-            return sb.toString();
-          }
-          sb.append(c);
-      }
-    }
-  }
-
-
-  /**
-   * Get the text up but not including the specified character or the end of line, whichever comes
-   * first.
-   * 
-   * @param delimiter A delimiter character.
-   * @return A string.
-   */
-  public String nextTo(char delimiter) throws JSONException {
-    StringBuffer sb = new StringBuffer();
-    for (;;) {
-      char c = this.next();
-      if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
-        if (c != 0) {
-          this.back();
-        }
-        return sb.toString().trim();
-      }
-      sb.append(c);
-    }
-  }
-
-
-  /**
-   * Get the text up but not including one of the specified delimiter characters or the end of line,
-   * whichever comes first.
-   * 
-   * @param delimiters A set of delimiter characters.
-   * @return A string, trimmed.
-   */
-  public String nextTo(String delimiters) throws JSONException {
-    char c;
-    StringBuffer sb = new StringBuffer();
-    for (;;) {
-      c = this.next();
-      if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
-        if (c != 0) {
-          this.back();
-        }
-        return sb.toString().trim();
-      }
-      sb.append(c);
-    }
-  }
-
-
-  /**
-   * Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long,
-   * or String, or the JSONObject.NULL object.
-   * 
-   * @throws JSONException If syntax error.
-   *
-   * @return An object.
-   */
-  public Object nextValue() throws JSONException {
-    char c = this.nextClean();
-    String string;
-
-    switch (c) {
-      case '"':
-      case '\'':
-        return this.nextString(c);
-      case '{':
-        this.back();
-        return new JSONObject(this);
-      case '[':
-        this.back();
-        return new JSONArray(this);
-    }
-
-    /*
-     * Handle unquoted text. This could be the values true, false, or null, or it can be a number.
-     * An implementation (such as this one) is allowed to also accept non-standard forms.
-     *
-     * Accumulate characters until we reach the end of the text or a formatting character.
-     */
-
-    StringBuffer sb = new StringBuffer();
-    while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
-      sb.append(c);
-      c = this.next();
-    }
-    this.back();
-
-    string = sb.toString().trim();
-    if ("".equals(string)) {
-      throw this.syntaxError("Missing value");
-    }
-    return JSONObject.stringToValue(string);
-  }
-
-
-  /**
-   * Skip characters until the next character is the requested character. If the requested character
-   * is not found, no characters are skipped.
-   * 
-   * @param to A character to skip to.
-   * @return The requested character, or zero if the requested character is not found.
-   */
-  public char skipTo(char to) throws JSONException {
-    char c;
-    try {
-      long startIndex = this.index;
-      long startCharacter = this.character;
-      long startLine = this.line;
-      this.reader.mark(1000000);
-      do {
-        c = this.next();
-        if (c == 0) {
-          this.reader.reset();
-          this.index = startIndex;
-          this.character = startCharacter;
-          this.line = startLine;
-          return c;
-        }
-      } while (c != to);
-    } catch (IOException exc) {
-      throw new JSONException(exc);
-    }
-
-    this.back();
-    return c;
-  }
-
-
-  /**
-   * Make a JSONException to signal a syntax error.
-   *
-   * @param message The error message.
-   * @return A JSONException object, suitable for throwing
-   */
-  public JSONException syntaxError(String message) {
-    return new JSONException(message + this.toString());
-  }
-
-
-  /**
-   * Make a printable string of this JSONTokener.
-   *
-   * @return " at {index} [character {character} line {line}]"
-   */
-  public String toString() {
-    return " at " + this.index + " [character " + this.character + " line " + this.line + "]";
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode/blob/76ea6c3c/geode-json/src/main/java/org/json/JSONWriter.java
----------------------------------------------------------------------
diff --git a/geode-json/src/main/java/org/json/JSONWriter.java b/geode-json/src/main/java/org/json/JSONWriter.java
deleted file mode 100755
index 7d4704b..0000000
--- a/geode-json/src/main/java/org/json/JSONWriter.java
+++ /dev/null
@@ -1,321 +0,0 @@
-package org.json;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/*
- * Copyright (c) 2006 JSON.org
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- * associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- * 
- * The Software shall be used for Good, not Evil.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * JSONWriter provides a quick and convenient way of producing JSON text. The texts produced
- * strictly conform to JSON syntax rules. No whitespace is added, so the results are ready for
- * transmission or storage. Each instance of JSONWriter can produce one JSON text.
- * <p>
- * A JSONWriter instance provides a <code>value</code> method for appending values to the text, and
- * a <code>key</code> method for adding keys before values in objects. There are <code>array</code>
- * and <code>endArray</code> methods that make and bound array values, and <code>object</code> and
- * <code>endObject</code> methods which make and bound object values. All of these methods return
- * the JSONWriter instance, permitting a cascade style. For example,
- * 
- * <pre>
- * new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
- * </pre>
- * 
- * which writes
- * 
- * <pre>
- * {"JSON":"Hello, World!"}
- * </pre>
- * <p>
- * The first method called must be <code>array</code> or <code>object</code>. There are no methods
- * for adding commas or colons. JSONWriter adds them for you. Objects and arrays can be nested up to
- * 20 levels deep.
- * <p>
- * This can sometimes be easier than using a JSONObject to build a string.
- * 
- * @author JSON.org
- * @version 2011-11-24
- */
-public class JSONWriter {
-  private static final int maxdepth = 200;
-
-  /**
-   * The comma flag determines if a comma should be output before the next value.
-   */
-  private boolean comma;
-
-  /**
-   * The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k' (key), 'o' (object).
-   */
-  protected char mode;
-
-  /**
-   * The object/array stack.
-   */
-  private final JSONObject stack[];
-
-  /**
-   * The stack top index. A value of 0 indicates that the stack is empty.
-   */
-  private int top;
-
-  /**
-   * The writer that will receive the output.
-   */
-  protected Writer writer;
-
-  /**
-   * Make a fresh JSONWriter. It can be used to build one JSON text.
-   */
-  public JSONWriter(Writer w) {
-    this.comma = false;
-    this.mode = 'i';
-    this.stack = new JSONObject[maxdepth];
-    this.top = 0;
-    this.writer = w;
-  }
-
-  /**
-   * Append a value.
-   * 
-   * @param string A string value.
-   * @return this
-   * @throws JSONException If the value is out of sequence.
-   */
-  private JSONWriter append(String string) throws JSONException {
-    if (string == null) {
-      throw new JSONException("Null pointer");
-    }
-    if (this.mode == 'o' || this.mode == 'a') {
-      try {
-        if (this.comma && this.mode == 'a') {
-          this.writer.write(',');
-        }
-        this.writer.write(string);
-      } catch (IOException e) {
-        throw new JSONException(e);
-      }
-      if (this.mode == 'o') {
-        this.mode = 'k';
-      }
-      this.comma = true;
-      return this;
-    }
-    throw new JSONException("Value out of sequence.");
-  }
-
-  /**
-   * Begin appending a new array. All values until the balancing <code>endArray</code> will be
-   * appended to this array. The <code>endArray</code> method must be called to mark the array's
-   * end.
-   * 
-   * @return this
-   * @throws JSONException If the nesting is too deep, or if the object is started in the wrong
-   *         place (for example as a key or after the end of the outermost array or object).
-   */
-  public JSONWriter array() throws JSONException {
-    if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
-      this.push(null);
-      this.append("[");
-      this.comma = false;
-      return this;
-    }
-    throw new JSONException("Misplaced array.");
-  }
-
-  /**
-   * End something.
-   * 
-   * @param mode Mode
-   * @param c Closing character
-   * @return this
-   * @throws JSONException If unbalanced.
-   */
-  private JSONWriter end(char mode, char c) throws JSONException {
-    if (this.mode != mode) {
-      throw new JSONException(mode == 'a' ? "Misplaced endArray." : "Misplaced endObject.");
-    }
-    this.pop(mode);
-    try {
-      this.writer.write(c);
-    } catch (IOException e) {
-      throw new JSONException(e);
-    }
-    this.comma = true;
-    return this;
-  }
-
-  /**
-   * End an array. This method most be called to balance calls to <code>array</code>.
-   * 
-   * @return this
-   * @throws JSONException If incorrectly nested.
-   */
-  public JSONWriter endArray() throws JSONException {
-    return this.end('a', ']');
-  }
-
-  /**
-   * End an object. This method most be called to balance calls to <code>object</code>.
-   * 
-   * @return this
-   * @throws JSONException If incorrectly nested.
-   */
-  public JSONWriter endObject() throws JSONException {
-    return this.end('k', '}');
-  }
-
-  /**
-   * Append a key. The key will be associated with the next value. In an object, every value must be
-   * preceded by a key.
-   * 
-   * @param string A key string.
-   * @return this
-   * @throws JSONException If the key is out of place. For example, keys do not belong in arrays or
-   *         if the key is null.
-   */
-  public JSONWriter key(String string) throws JSONException {
-    if (string == null) {
-      throw new JSONException("Null key.");
-    }
-    if (this.mode == 'k') {
-      try {
-        this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
-        if (this.comma) {
-          this.writer.write(',');
-        }
-        this.writer.write(JSONObject.quote(string));
-        this.writer.write(':');
-        this.comma = false;
-        this.mode = 'o';
-        return this;
-      } catch (IOException e) {
-        throw new JSONException(e);
-      }
-    }
-    throw new JSONException("Misplaced key.");
-  }
-
-
-  /**
-   * Begin appending a new object. All keys and values until the balancing <code>endObject</code>
-   * will be appended to this object. The <code>endObject</code> method must be called to mark the
-   * object's end.
-   * 
-   * @return this
-   * @throws JSONException If the nesting is too deep, or if the object is started in the wrong
-   *         place (for example as a key or after the end of the outermost array or object).
-   */
-  public JSONWriter object() throws JSONException {
-    if (this.mode == 'i') {
-      this.mode = 'o';
-    }
-    if (this.mode == 'o' || this.mode == 'a') {
-      this.append("{");
-      this.push(new JSONObject());
-      this.comma = false;
-      return this;
-    }
-    throw new JSONException("Misplaced object.");
-
-  }
-
-
-  /**
-   * Pop an array or object scope.
-   * 
-   * @param c The scope to close.
-   * @throws JSONException If nesting is wrong.
-   */
-  private void pop(char c) throws JSONException {
-    if (this.top <= 0) {
-      throw new JSONException("Nesting error.");
-    }
-    char m = this.stack[this.top - 1] == null ? 'a' : 'k';
-    if (m != c) {
-      throw new JSONException("Nesting error.");
-    }
-    this.top -= 1;
-    this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
-  }
-
-  /**
-   * Push an array or object scope.
-   * 
-   * @param jo The scope to open.
-   * @throws JSONException If nesting is too deep.
-   */
-  private void push(JSONObject jo) throws JSONException {
-    if (this.top >= maxdepth) {
-      throw new JSONException("Nesting too deep.");
-    }
-    this.stack[this.top] = jo;
-    this.mode = jo == null ? 'a' : 'k';
-    this.top += 1;
-  }
-
-
-  /**
-   * Append either the value <code>true</code> or the value <code>false</code>.
-   * 
-   * @param b A boolean.
-   * @return this
-   * @throws JSONException
-   */
-  public JSONWriter value(boolean b) throws JSONException {
-    return this.append(b ? "true" : "false");
-  }
-
-  /**
-   * Append a double value.
-   * 
-   * @param d A double.
-   * @return this
-   * @throws JSONException If the number is not finite.
-   */
-  public JSONWriter value(double d) throws JSONException {
-    return this.value(new Double(d));
-  }
-
-  /**
-   * Append a long value.
-   * 
-   * @param l A long.
-   * @return this
-   * @throws JSONException
-   */
-  public JSONWriter value(long l) throws JSONException {
-    return this.append(Long.toString(l));
-  }
-
-
-  /**
-   * Append an object value.
-   * 
-   * @param object The object to append. It can be null, or a Boolean, Number, String, JSONObject,
-   *        or JSONArray, or an object that implements JSONString.
-   * @return this
-   * @throws JSONException If the value is out of sequence.
-   */
-  public JSONWriter value(Object object) throws JSONException {
-    return this.append(JSONObject.valueToString(object));
-  }
-}


[13/34] geode git commit: GEODE-2142: spotless

Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/eac0bb8c/geode-json/src/test/java/org/json/JSONObjectTest.java
----------------------------------------------------------------------
diff --git a/geode-json/src/test/java/org/json/JSONObjectTest.java b/geode-json/src/test/java/org/json/JSONObjectTest.java
index 393a2d0..c795551 100755
--- a/geode-json/src/test/java/org/json/JSONObjectTest.java
+++ b/geode-json/src/test/java/org/json/JSONObjectTest.java
@@ -1,17 +1,15 @@
 /*
  * 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;
@@ -43,1156 +41,1150 @@ import static org.junit.Assert.*;
  * This black box test was written without inspecting the non-free org.json sourcecode.
  */
 public class JSONObjectTest {
-    @Test
-    public void testKeyset() throws Exception {
-        JSONObject x = new JSONObject("{'a':1, 'b':2, 'c':3}");
-        Set<String> k = new TreeSet<String>();
-        for (String kx : Arrays.asList("a", "b", "c")) {
-            k.add(kx);
-        }
-        assertEquals(x.keySet(), k);
-        x = new JSONObject("{}");
-        assertEquals(x.keySet().size(), 0);
-    }
-
-    @Test
-    public void testEmptyObject() throws JSONException {
-        JSONObject object = new JSONObject();
-        assertEquals(0, object.length());
-
-        // bogus (but documented) behaviour: returns null rather than the empty object!
-        assertNull(object.names());
-
-        // returns null rather than an empty array!
-        assertNull(object.toJSONArray(new JSONArray()));
-        assertEquals("{}", object.toString());
-        assertEquals("{}", object.toString(5));
-        try {
-            object.get("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getBoolean("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getDouble("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getInt("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getJSONArray("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getJSONObject("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getLong("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getString("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertFalse(object.has("foo"));
-        assertTrue(object.isNull("foo")); // isNull also means "is not present"
-        assertNull(object.opt("foo"));
-        assertEquals(false, object.optBoolean("foo"));
-        assertEquals(true, object.optBoolean("foo", true));
-        assertEquals(Double.NaN, object.optDouble("foo"), 0);
-        assertEquals(5.0, object.optDouble("foo", 5.0), 0);
-        assertEquals(0, object.optInt("foo"));
-        assertEquals(5, object.optInt("foo", 5));
-        assertEquals(null, object.optJSONArray("foo"));
-        assertEquals(null, object.optJSONObject("foo"));
-        assertEquals(0, object.optLong("foo"));
-        assertEquals(Long.MAX_VALUE - 1, object.optLong("foo", Long.MAX_VALUE - 1));
-        assertEquals("", object.optString("foo")); // empty string is default!
-        assertEquals("bar", object.optString("foo", "bar"));
-        assertNull(object.remove("foo"));
-    }
-
-    @Test
-    public void testEqualsAndHashCode() throws JSONException {
-        JSONObject a = new JSONObject();
-        JSONObject b = new JSONObject();
-
-        // JSON object doesn't override either equals or hashCode (!)
-        assertFalse(a.equals(b));
-        assertEquals(a.hashCode(), System.identityHashCode(a));
-    }
-
-    @Test
-    public void testGet() throws JSONException {
-        JSONObject object = new JSONObject();
-        Object value = new Object();
-        object.put("foo", value);
-        object.put("bar", new Object());
-        object.put("baz", new Object());
-        assertSame(value, object.get("foo"));
-        try {
-            object.get("FOO");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put(null, value);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.get(null);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testPut() throws JSONException {
-        JSONObject object = new JSONObject();
-        assertSame(object, object.put("foo", true));
-        object.put("foo", false);
-        assertEquals(false, object.get("foo"));
-
-        object.put("foo", 5.0d);
-        assertEquals(5.0d, object.get("foo"));
-        object.put("foo", 0);
-        assertEquals(0, object.get("foo"));
-        object.put("bar", Long.MAX_VALUE - 1);
-        assertEquals(Long.MAX_VALUE - 1, object.get("bar"));
-        object.put("baz", "x");
-        assertEquals("x", object.get("baz"));
-        object.put("bar", JSONObject.NULL);
-        assertSame(JSONObject.NULL, object.get("bar"));
-    }
-
-    @Test
-    public void testPutNullRemoves() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "bar");
-        object.put("foo", null);
-        assertEquals(0, object.length());
-        assertFalse(object.has("foo"));
-        try {
-            object.get("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testPutOpt() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "bar");
-        object.putOpt("foo", null);
-        assertEquals("bar", object.get("foo"));
-        object.putOpt(null, null);
-        assertEquals(1, object.length());
-        object.putOpt(null, "bar");
-        assertEquals(1, object.length());
-    }
-
-    @Test
-    public void testPutOptUnsupportedNumbers() throws JSONException {
-        JSONObject object = new JSONObject();
-        try {
-            object.putOpt("foo", Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.putOpt("foo", Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.putOpt("foo", Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testRemove() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "bar");
-        assertEquals(null, object.remove(null));
-        assertEquals(null, object.remove(""));
-        assertEquals(null, object.remove("bar"));
-        assertEquals("bar", object.remove("foo"));
-        assertEquals(null, object.remove("foo"));
-    }
-
-    @Test
-    public void testBooleans() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", true);
-        object.put("bar", false);
-        object.put("baz", "true");
-        object.put("quux", "false");
-        assertEquals(4, object.length());
-        assertEquals(true, object.getBoolean("foo"));
-        assertEquals(false, object.getBoolean("bar"));
-        assertEquals(true, object.getBoolean("baz"));
-        assertEquals(false, object.getBoolean("quux"));
-        assertFalse(object.isNull("foo"));
-        assertFalse(object.isNull("quux"));
-        assertTrue(object.has("foo"));
-        assertTrue(object.has("quux"));
-        assertFalse(object.has("missing"));
-        assertEquals(true, object.optBoolean("foo"));
-        assertEquals(false, object.optBoolean("bar"));
-        assertEquals(true, object.optBoolean("baz"));
-        assertEquals(false, object.optBoolean("quux"));
-        assertEquals(false, object.optBoolean("missing"));
-        assertEquals(true, object.optBoolean("foo", true));
-        assertEquals(false, object.optBoolean("bar", true));
-        assertEquals(true, object.optBoolean("baz", true));
-        assertEquals(false, object.optBoolean("quux", true));
-        assertEquals(true, object.optBoolean("missing", true));
-
-        object.put("foo", "truE");
-        object.put("bar", "FALSE");
-        assertEquals(true, object.getBoolean("foo"));
-        assertEquals(false, object.getBoolean("bar"));
-        assertEquals(true, object.optBoolean("foo"));
-        assertEquals(false, object.optBoolean("bar"));
-        assertEquals(true, object.optBoolean("foo", false));
-        assertEquals(false, object.optBoolean("bar", false));
-    }
-
-    // http://code.google.com/p/android/issues/detail?id=16411
-    @Test
-    public void testCoerceStringToBoolean() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "maybe");
-        try {
-            object.getBoolean("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals(false, object.optBoolean("foo"));
-        assertEquals(true, object.optBoolean("foo", true));
-    }
-
-    @Test
-    public void testNumbers() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", Double.MIN_VALUE);
-        object.put("bar", 9223372036854775806L);
-        object.put("baz", Double.MAX_VALUE);
-        object.put("quux", -0d);
-        assertEquals(4, object.length());
-
-        String toString = object.toString();
-        assertTrue(toString, toString.contains("\"foo\":4.9E-324"));
-        assertTrue(toString, toString.contains("\"bar\":9223372036854775806"));
-        assertTrue(toString, toString.contains("\"baz\":1.7976931348623157E308"));
-
-        // toString() and getString() return different values for -0d!
-        assertTrue(toString, toString.contains("\"quux\":-0}") // no trailing decimal point
-                || toString.contains("\"quux\":-0,"));
-
-        assertEquals(Double.MIN_VALUE, object.get("foo"));
-        assertEquals(9223372036854775806L, object.get("bar"));
-        assertEquals(Double.MAX_VALUE, object.get("baz"));
-        assertEquals(-0d, object.get("quux"));
-        assertEquals(Double.MIN_VALUE, object.getDouble("foo"), 0);
-        assertEquals(9.223372036854776E18, object.getDouble("bar"), 0);
-        assertEquals(Double.MAX_VALUE, object.getDouble("baz"), 0);
-        assertEquals(-0d, object.getDouble("quux"), 0);
-        assertEquals(0, object.getLong("foo"));
-        assertEquals(9223372036854775806L, object.getLong("bar"));
-        assertEquals(Long.MAX_VALUE, object.getLong("baz"));
-        assertEquals(0, object.getLong("quux"));
-        assertEquals(0, object.getInt("foo"));
-        assertEquals(-2, object.getInt("bar"));
-        assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
-        assertEquals(0, object.getInt("quux"));
-        assertEquals(Double.MIN_VALUE, object.opt("foo"));
-        assertEquals(9223372036854775806L, object.optLong("bar"));
-        assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
-        assertEquals(0, object.optInt("quux"));
-        assertEquals(Double.MIN_VALUE, object.opt("foo"));
-        assertEquals(9223372036854775806L, object.optLong("bar"));
-        assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
-        assertEquals(0, object.optInt("quux"));
-        assertEquals(Double.MIN_VALUE, object.optDouble("foo", 5.0d), 0);
-        assertEquals(9223372036854775806L, object.optLong("bar", 1L));
-        assertEquals(Long.MAX_VALUE, object.optLong("baz", 1L));
-        assertEquals(0, object.optInt("quux", -1));
-        assertEquals("4.9E-324", object.getString("foo"));
-        assertEquals("9223372036854775806", object.getString("bar"));
-        assertEquals("1.7976931348623157E308", object.getString("baz"));
-        assertEquals("-0.0", object.getString("quux"));
-    }
-
-    @Test
-    public void testFloats() throws JSONException {
-        JSONObject object = new JSONObject();
-        try {
-            object.put("foo", (Float) Float.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", (Float) Float.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", (Float) Float.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testOtherNumbers() throws JSONException {
-        Number nan = new Number() {
-            public int intValue() {
-                throw new UnsupportedOperationException();
-            }
-
-            public long longValue() {
-                throw new UnsupportedOperationException();
-            }
-
-            public float floatValue() {
-                throw new UnsupportedOperationException();
-            }
-
-            public double doubleValue() {
-                return Double.NaN;
-            }
-
-            @Override
-            public String toString() {
-                return "x";
-            }
-        };
-
-        JSONObject object = new JSONObject();
-        try {
-            object.put("foo", nan);
-            fail("Object.put() accepted a NaN (via a custom Number class)");
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testForeignObjects() throws JSONException {
-        Object foreign = new Object() {
-            @Override
-            public String toString() {
-                return "x";
-            }
-        };
-
-        // foreign object types are accepted and treated as Strings!
-        JSONObject object = new JSONObject();
-        object.put("foo", foreign);
-        assertEquals("{\"foo\":\"x\"}", object.toString());
-    }
-
-    @Test
-    public void testNullKeys() {
-        try {
-            new JSONObject().put(null, false);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONObject().put(null, 0.0d);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONObject().put(null, 5);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONObject().put(null, 5L);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            new JSONObject().put(null, "foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testStrings() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "true");
-        object.put("bar", "5.5");
-        object.put("baz", "9223372036854775806");
-        object.put("quux", "null");
-        object.put("height", "5\"8' tall");
-
-        assertTrue(object.toString().contains("\"foo\":\"true\""));
-        assertTrue(object.toString().contains("\"bar\":\"5.5\""));
-        assertTrue(object.toString().contains("\"baz\":\"9223372036854775806\""));
-        assertTrue(object.toString().contains("\"quux\":\"null\""));
-        assertTrue(object.toString().contains("\"height\":\"5\\\"8' tall\""));
-
-        assertEquals("true", object.get("foo"));
-        assertEquals("null", object.getString("quux"));
-        assertEquals("5\"8' tall", object.getString("height"));
-        assertEquals("true", object.opt("foo"));
-        assertEquals("5.5", object.optString("bar"));
-        assertEquals("true", object.optString("foo", "x"));
-        assertFalse(object.isNull("foo"));
-
-        assertEquals(true, object.getBoolean("foo"));
-        assertEquals(true, object.optBoolean("foo"));
-        assertEquals(true, object.optBoolean("foo", false));
-        assertEquals(0, object.optInt("foo"));
-        assertEquals(-2, object.optInt("foo", -2));
-
-        assertEquals(5.5d, object.getDouble("bar"), 0);
-        assertEquals(5L, object.getLong("bar"));
-        assertEquals(5, object.getInt("bar"));
-        assertEquals(5, object.optInt("bar", 3));
-
-        // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
-        // double and then converting that to a long. This is consistent with JavaScript.
-        assertEquals(9223372036854775807L, object.getLong("baz"));
-        assertEquals(9.223372036854776E18, object.getDouble("baz"), 0);
-        assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
-
-        assertFalse(object.isNull("quux"));
-        try {
-            object.getDouble("quux");
-            fail();
-        } catch (JSONException e) {
-            // expected
-        }
-        assertEquals(Double.NaN, object.optDouble("quux"), 0);
-        assertEquals(-1.0d, object.optDouble("quux", -1.0d), 0);
-
-        object.put("foo", "TRUE");
-        assertEquals(true, object.getBoolean("foo"));
-    }
-
-    @Test
-    public void testJSONObjects() throws JSONException {
-        JSONObject object = new JSONObject();
-
-        JSONArray a = new JSONArray();
-        JSONObject b = new JSONObject();
-        object.put("foo", a);
-        object.put("bar", b);
-
-        assertSame(a, object.getJSONArray("foo"));
-        assertSame(b, object.getJSONObject("bar"));
-        try {
-            object.getJSONObject("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.getJSONArray("bar");
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals(a, object.optJSONArray("foo"));
-        assertEquals(b, object.optJSONObject("bar"));
-        assertEquals(null, object.optJSONArray("bar"));
-        assertEquals(null, object.optJSONObject("foo"));
-    }
-
-    @Test
-    public void testNullCoercionToString() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", JSONObject.NULL);
-        assertEquals("null", object.getString("foo"));
-    }
-
-    @Test
-    public void testArrayCoercion() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "[true]");
-        try {
-            object.getJSONArray("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testObjectCoercion() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "{}");
-        try {
-            object.getJSONObject("foo");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testAccumulateValueChecking() throws JSONException {
-        JSONObject object = new JSONObject();
-        try {
-            object.accumulate("foo", Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        object.accumulate("foo", 1);
-        try {
-            object.accumulate("foo", Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        object.accumulate("foo", 2);
-        try {
-            object.accumulate("foo", Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testToJSONArray() throws JSONException {
-        JSONObject object = new JSONObject();
-        Object value = new Object();
-        object.put("foo", true);
-        object.put("bar", 5.0d);
-        object.put("baz", -0.0d);
-        object.put("quux", value);
-
-        JSONArray names = new JSONArray();
-        names.put("baz");
-        names.put("quux");
-        names.put("foo");
-
-        JSONArray array = object.toJSONArray(names);
-        assertEquals(-0.0d, array.get(0));
-        assertEquals(value, array.get(1));
-        assertEquals(true, array.get(2));
-
-        object.put("foo", false);
-        assertEquals(true, array.get(2));
-    }
-
-    @Test
-    public void testToJSONArrayMissingNames() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", true);
-        object.put("bar", 5.0d);
-        object.put("baz", JSONObject.NULL);
-
-        JSONArray names = new JSONArray();
-        names.put("bar");
-        names.put("foo");
-        names.put("quux");
-        names.put("baz");
-
-        JSONArray array = object.toJSONArray(names);
-        assertEquals(4, array.length());
-
-        assertEquals(5.0d, array.get(0));
-        assertEquals(true, array.get(1));
-        try {
-            array.get(2);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals(JSONObject.NULL, array.get(3));
-    }
-
-    @Test
-    public void testToJSONArrayNull() throws JSONException {
-        JSONObject object = new JSONObject();
-        assertEquals(null, object.toJSONArray(null));
-        object.put("foo", 5);
-        try {
-            object.toJSONArray(null);
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testToJSONArrayEndsUpEmpty() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        JSONArray array = new JSONArray();
-        array.put("bar");
-        assertEquals(1, object.toJSONArray(array).length());
-    }
-
-    @Test
-    public void testToJSONArrayNonString() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        object.put("null", 10);
-        object.put("false", 15);
-
-        JSONArray names = new JSONArray();
-        names.put(JSONObject.NULL);
-        names.put(false);
-        names.put("foo");
-
-        // array elements are converted to strings to do name lookups on the map!
-        JSONArray array = object.toJSONArray(names);
-        assertEquals(3, array.length());
-        assertEquals(10, array.get(0));
-        assertEquals(15, array.get(1));
-        assertEquals(5, array.get(2));
-    }
-
-    @Test
-    public void testPutUnsupportedNumbers() throws JSONException {
-        JSONObject object = new JSONObject();
-        try {
-            object.put("foo", Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testPutUnsupportedNumbersAsObjects() throws JSONException {
-        JSONObject object = new JSONObject();
-        try {
-            object.put("foo", (Double) Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", (Double) Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            object.put("foo", (Double) Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    /**
-     * Although JSONObject is usually defensive about which numbers it accepts,
-     * it doesn't check inputs in its constructor.
-     */
-    @Test
-    public void testCreateWithUnsupportedNumbers() throws JSONException {
-        Map<String, Object> contents = new HashMap<String, Object>();
-        contents.put("foo", Double.NaN);
-        contents.put("bar", Double.NEGATIVE_INFINITY);
-        contents.put("baz", Double.POSITIVE_INFINITY);
-
-        JSONObject object = new JSONObject(contents);
-        assertEquals(Double.NaN, object.get("foo"));
-        assertEquals(Double.NEGATIVE_INFINITY, object.get("bar"));
-        assertEquals(Double.POSITIVE_INFINITY, object.get("baz"));
-    }
-
-    @Test
-    public void testToStringWithUnsupportedNumbers() {
-        // when the object contains an unsupported number, toString returns null!
-        JSONObject object = new JSONObject(Collections.singletonMap("foo", Double.NaN));
-        assertEquals(null, object.toString());
-    }
-
-    @Test
-    public void testMapConstructorCopiesContents() throws JSONException {
-        Map<String, Object> contents = new HashMap<String, Object>();
-        contents.put("foo", 5);
-        JSONObject object = new JSONObject(contents);
-        contents.put("foo", 10);
-        assertEquals(5, object.get("foo"));
-    }
-
-    @Test
-    public void testMapConstructorWithBogusEntries() {
-        Map<Object, Object> contents = new HashMap<Object, Object>();
-        contents.put(5, 5);
-
-        try {
-            new JSONObject(contents);
-            fail("JSONObject constructor doesn't validate its input!");
-        } catch (Exception ignored) {
-        }
-    }
-
-    @Test
-    public void testTokenerConstructor() throws JSONException {
-        JSONObject object = new JSONObject(new JSONTokener("{\"foo\": false}"));
-        assertEquals(1, object.length());
-        assertEquals(false, object.get("foo"));
-    }
-
-    @Test
-    public void testTokenerConstructorWrongType() throws JSONException {
-        try {
-            new JSONObject(new JSONTokener("[\"foo\", false]"));
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testTokenerConstructorNull() throws JSONException {
-        try {
-            new JSONObject((JSONTokener) null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    @Test
-    public void testTokenerConstructorParseFail() {
-        try {
-            new JSONObject(new JSONTokener("{"));
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testStringConstructor() throws JSONException {
-        JSONObject object = new JSONObject("{\"foo\": false}");
-        assertEquals(1, object.length());
-        assertEquals(false, object.get("foo"));
-    }
-
-    @Test
-    public void testStringConstructorWrongType() throws JSONException {
-        try {
-            new JSONObject("[\"foo\", false]");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testStringConstructorNull() throws JSONException {
-        try {
-            new JSONObject((String) null);
-            fail();
-        } catch (NullPointerException ignored) {
-        }
-    }
-
-    @Test
-    public void testStringConstructorParseFail() {
-        try {
-            new JSONObject("{");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testCopyConstructor() throws JSONException {
-        JSONObject source = new JSONObject();
-        source.put("a", JSONObject.NULL);
-        source.put("b", false);
-        source.put("c", 5);
-
-        JSONObject copy = new JSONObject(source, new String[]{"a", "c"});
-        assertEquals(2, copy.length());
-        assertEquals(JSONObject.NULL, copy.get("a"));
-        assertEquals(5, copy.get("c"));
-        assertEquals(null, copy.opt("b"));
-    }
-
-    @Test
-    public void testCopyConstructorMissingName() throws JSONException {
-        JSONObject source = new JSONObject();
-        source.put("a", JSONObject.NULL);
-        source.put("b", false);
-        source.put("c", 5);
-
-        JSONObject copy = new JSONObject(source, new String[]{"a", "c", "d"});
-        assertEquals(2, copy.length());
-        assertEquals(JSONObject.NULL, copy.get("a"));
-        assertEquals(5, copy.get("c"));
-        assertEquals(0, copy.optInt("b"));
-    }
-
-    @Test
-    public void testAccumulateMutatesInPlace() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        object.accumulate("foo", 6);
-        JSONArray array = object.getJSONArray("foo");
-        assertEquals("[5,6]", array.toString());
-        object.accumulate("foo", 7);
-        assertEquals("[5,6,7]", array.toString());
-    }
-
-    @Test
-    public void testAccumulateExistingArray() throws JSONException {
-        JSONArray array = new JSONArray();
-        JSONObject object = new JSONObject();
-        object.put("foo", array);
-        object.accumulate("foo", 5);
-        assertEquals("[5]", array.toString());
-    }
-
-    @Test
-    public void testAccumulatePutArray() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.accumulate("foo", 5);
-        assertEquals("{\"foo\":5}", object.toString());
-        object.accumulate("foo", new JSONArray());
-        assertEquals("{\"foo\":[5,[]]}", object.toString());
-    }
-
-    @Test
-    public void testAccumulateNull() {
-        JSONObject object = new JSONObject();
-        try {
-            object.accumulate(null, 5);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testEmptyStringKey() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("", 5);
-        assertEquals(5, object.get(""));
-        assertEquals("{\"\":5}", object.toString());
-    }
-
-    @Test
-    public void testNullValue() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", JSONObject.NULL);
-        object.put("bar", null);
-
-        // there are two ways to represent null; each behaves differently!
-        assertTrue(object.has("foo"));
-        assertFalse(object.has("bar"));
-        assertTrue(object.isNull("foo"));
-        assertTrue(object.isNull("bar"));
-    }
-
-    @Test
-    public void testNullValue_equalsAndHashCode() {
-        //noinspection ObjectEqualsNull
-        assertTrue(JSONObject.NULL.equals(null)); // guaranteed by javadoc
-        // not guaranteed by javadoc, but seems like a good idea
-        assertEquals(Objects.hashCode(null), JSONObject.NULL.hashCode());
-    }
-
-    @Test
-    public void testHas() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        assertTrue(object.has("foo"));
-        assertFalse(object.has("bar"));
-        assertFalse(object.has(null));
-    }
-
-    @Test
-    public void testOptNull() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", "bar");
-        assertEquals(null, object.opt(null));
-        assertEquals(false, object.optBoolean(null));
-        assertEquals(Double.NaN, object.optDouble(null), 0);
-        assertEquals(0, object.optInt(null));
-        assertEquals(0L, object.optLong(null));
-        assertEquals(null, object.optJSONArray(null));
-        assertEquals(null, object.optJSONObject(null));
-        assertEquals("", object.optString(null));
-        assertEquals(true, object.optBoolean(null, true));
-        assertEquals(0.0d, object.optDouble(null, 0.0d), 0);
-        assertEquals(1, object.optInt(null, 1));
-        assertEquals(1L, object.optLong(null, 1L));
-        assertEquals("baz", object.optString(null, "baz"));
-    }
-
-    @Test
-    public void testToStringWithIndentFactor() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", new JSONArray(Arrays.asList(5, 6)));
-        object.put("bar", new JSONObject());
-        String foobar = "{\n" +
-                "     \"foo\": [\n" +
-                "          5,\n" +
-                "          6\n" +
-                "     ],\n" +
-                "     \"bar\": {}\n" +
-                "}";
-        String barfoo = "{\n" +
-                "     \"bar\": {},\n" +
-                "     \"foo\": [\n" +
-                "          5,\n" +
-                "          6\n" +
-                "     ]\n" +
-                "}";
-        String string = object.toString(5);
-        assertTrue(string, foobar.equals(string) || barfoo.equals(string));
-    }
-
-    @Test
-    public void testNames() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        object.put("bar", 6);
-        object.put("baz", 7);
-        JSONArray array = object.names();
-        assertTrue(array.toString().contains("foo"));
-        assertTrue(array.toString().contains("bar"));
-        assertTrue(array.toString().contains("baz"));
-    }
-
-    @Test
-    public void testKeysEmptyObject() {
-        JSONObject object = new JSONObject();
-        assertFalse(object.keys().hasNext());
-        try {
-            object.keys().next();
-            fail();
-        } catch (NoSuchElementException ignored) {
-        }
-    }
-
-    @Test
-    public void testKeys() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        object.put("bar", 6);
-        object.put("foo", 7);
-
-        @SuppressWarnings("unchecked")
-        Iterator<String> keys = object.keys();
-        Set<String> result = new HashSet<String>();
-        assertTrue(keys.hasNext());
-        result.add(keys.next());
-        assertTrue(keys.hasNext());
-        result.add(keys.next());
-        assertFalse(keys.hasNext());
-        assertEquals(new HashSet<String>(Arrays.asList("foo", "bar")), result);
-
-        try {
-            keys.next();
-            fail();
-        } catch (NoSuchElementException ignored) {
-        }
-    }
-
-    @Test
-    public void testMutatingKeysMutatesObject() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        Iterator keys = object.keys();
-        keys.next();
-        keys.remove();
-        assertEquals(0, object.length());
-    }
-
-    @Test
-    public void testQuote() {
-        // covered by JSONStringerTest.testEscaping
-    }
-
-    @Test
-    public void testQuoteNull() throws JSONException {
-        assertEquals("\"\"", JSONObject.quote(null));
-    }
-
-    @Test
-    public void testNumberToString() throws JSONException {
-        assertEquals("5", JSONObject.numberToString(5));
-        assertEquals("-0", JSONObject.numberToString(-0.0d));
-        assertEquals("9223372036854775806", JSONObject.numberToString(9223372036854775806L));
-        assertEquals("4.9E-324", JSONObject.numberToString(Double.MIN_VALUE));
-        assertEquals("1.7976931348623157E308", JSONObject.numberToString(Double.MAX_VALUE));
-        try {
-            JSONObject.numberToString(Double.NaN);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            JSONObject.numberToString(Double.NEGATIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        try {
-            JSONObject.numberToString(Double.POSITIVE_INFINITY);
-            fail();
-        } catch (JSONException ignored) {
-        }
-        assertEquals("0.001", JSONObject.numberToString(new BigDecimal("0.001")));
-        assertEquals("9223372036854775806",
-                JSONObject.numberToString(new BigInteger("9223372036854775806")));
-        try {
-            JSONObject.numberToString(null);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void test_wrap() throws Exception {
-        assertEquals(JSONObject.NULL, JSONObject.wrap(null));
-
-        JSONArray a = new JSONArray();
-        assertEquals(a, JSONObject.wrap(a));
-
-        JSONObject o = new JSONObject();
-        assertEquals(o, JSONObject.wrap(o));
-
-        assertEquals(JSONObject.NULL, JSONObject.wrap(JSONObject.NULL));
-
-        assertTrue(JSONObject.wrap(new byte[0]) instanceof JSONArray);
-        assertTrue(JSONObject.wrap(new ArrayList<String>()) instanceof JSONArray);
-        assertTrue(JSONObject.wrap(new HashMap<String, String>()) instanceof JSONObject);
-        assertTrue(JSONObject.wrap(0.0) instanceof Double);
-        assertTrue(JSONObject.wrap("hello") instanceof String);
-    }
-
-    // https://code.google.com/p/android/issues/detail?id=55114
-    @Test
-    public void test_toString_listAsMapValue() throws Exception {
-        ArrayList<Object> list = new ArrayList<Object>();
-        list.add("a");
-        list.add(new ArrayList<String>());
-        Map<String, Object> map = new TreeMap<String, Object>();
-        map.put("x", "l");
-        map.put("y", list);
-        assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
-    }
-
-    @Test
-    public void testAppendExistingInvalidKey() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.put("foo", 5);
-        try {
-            object.append("foo", 6);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testAppendExistingArray() throws JSONException {
-        JSONArray array = new JSONArray();
-        JSONObject object = new JSONObject();
-        object.put("foo", array);
-        object.append("foo", 5);
-        assertEquals("[5]", array.toString());
-    }
-
-    @Test
-    public void testAppendPutArray() throws JSONException {
-        JSONObject object = new JSONObject();
-        object.append("foo", 5);
-        assertEquals("{\"foo\":[5]}", object.toString());
-        object.append("foo", new JSONArray());
-        assertEquals("{\"foo\":[5,[]]}", object.toString());
-    }
-
-    @Test
-    public void testAppendNull() {
-        JSONObject object = new JSONObject();
-        try {
-            object.append(null, 5);
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    // https://code.google.com/p/android/issues/detail?id=103641
-    @Test
-    public void testInvalidUnicodeEscape() {
-        try {
-            new JSONObject("{\"q\":\"\\u\", \"r\":[]}");
-            fail();
-        } catch (JSONException ignored) {
-        }
-    }
-
-    @Test
-    public void testBeanThings() throws IllegalAccessException, IntrospectionException, InvocationTargetException {
-        Foo f = new Foo();
-        assertEquals("{\"a\":1,\"b\":1,\"c\":\"c\",\"d\":[{\"e\":\"echo\"}]}", new JSONObject(f).toString());
-    }
-
-    @Test
-    public void testGetNames() throws Exception {
-        assertArrayEquals(new String[]{"a", "b", "c", "d"}, JSONObject.getNames(new JSONObject(new Foo())));
-    }
-
-    private static class Foo {
-        public double getA() {
-            return 1.0;
-        }
-
-        public int getB() {
-            return 1;
-        }
-
-        public String getC() {
-            return "c";
-        }
-
-        public List<Bar> getD() {
-            ArrayList<Bar> r = new ArrayList<Bar>();
-            r.add(new Bar());
-            return r;
-        }
-    }
-
-    private static class Bar {
-        public String getE() {
-            return "echo";
-        }
-    }
-
-    @Test
-    public void testEnumWrapper() throws Exception {
-        Object y = JSONObject.wrap(E.A);
-        assertEquals("A", y);
-        assertTrue(y instanceof String);
-    }
-
-    enum E {
-        A {
-            int key() {
-                return 1;
-            }
-        }, B {
-            int key() {
-                return 2;
-            }
-        };
-        int key() {
-            return -1;
-        }
-    }
+  @Test
+  public void testKeyset() throws Exception {
+    JSONObject x = new JSONObject("{'a':1, 'b':2, 'c':3}");
+    Set<String> k = new TreeSet<String>();
+    for (String kx : Arrays.asList("a", "b", "c")) {
+      k.add(kx);
+    }
+    assertEquals(x.keySet(), k);
+    x = new JSONObject("{}");
+    assertEquals(x.keySet().size(), 0);
+  }
+
+  @Test
+  public void testEmptyObject() throws JSONException {
+    JSONObject object = new JSONObject();
+    assertEquals(0, object.length());
+
+    // bogus (but documented) behaviour: returns null rather than the empty object!
+    assertNull(object.names());
+
+    // returns null rather than an empty array!
+    assertNull(object.toJSONArray(new JSONArray()));
+    assertEquals("{}", object.toString());
+    assertEquals("{}", object.toString(5));
+    try {
+      object.get("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getBoolean("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getDouble("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getInt("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getJSONArray("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getJSONObject("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getLong("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getString("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertFalse(object.has("foo"));
+    assertTrue(object.isNull("foo")); // isNull also means "is not present"
+    assertNull(object.opt("foo"));
+    assertEquals(false, object.optBoolean("foo"));
+    assertEquals(true, object.optBoolean("foo", true));
+    assertEquals(Double.NaN, object.optDouble("foo"), 0);
+    assertEquals(5.0, object.optDouble("foo", 5.0), 0);
+    assertEquals(0, object.optInt("foo"));
+    assertEquals(5, object.optInt("foo", 5));
+    assertEquals(null, object.optJSONArray("foo"));
+    assertEquals(null, object.optJSONObject("foo"));
+    assertEquals(0, object.optLong("foo"));
+    assertEquals(Long.MAX_VALUE - 1, object.optLong("foo", Long.MAX_VALUE - 1));
+    assertEquals("", object.optString("foo")); // empty string is default!
+    assertEquals("bar", object.optString("foo", "bar"));
+    assertNull(object.remove("foo"));
+  }
+
+  @Test
+  public void testEqualsAndHashCode() throws JSONException {
+    JSONObject a = new JSONObject();
+    JSONObject b = new JSONObject();
+
+    // JSON object doesn't override either equals or hashCode (!)
+    assertFalse(a.equals(b));
+    assertEquals(a.hashCode(), System.identityHashCode(a));
+  }
+
+  @Test
+  public void testGet() throws JSONException {
+    JSONObject object = new JSONObject();
+    Object value = new Object();
+    object.put("foo", value);
+    object.put("bar", new Object());
+    object.put("baz", new Object());
+    assertSame(value, object.get("foo"));
+    try {
+      object.get("FOO");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put(null, value);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.get(null);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testPut() throws JSONException {
+    JSONObject object = new JSONObject();
+    assertSame(object, object.put("foo", true));
+    object.put("foo", false);
+    assertEquals(false, object.get("foo"));
+
+    object.put("foo", 5.0d);
+    assertEquals(5.0d, object.get("foo"));
+    object.put("foo", 0);
+    assertEquals(0, object.get("foo"));
+    object.put("bar", Long.MAX_VALUE - 1);
+    assertEquals(Long.MAX_VALUE - 1, object.get("bar"));
+    object.put("baz", "x");
+    assertEquals("x", object.get("baz"));
+    object.put("bar", JSONObject.NULL);
+    assertSame(JSONObject.NULL, object.get("bar"));
+  }
+
+  @Test
+  public void testPutNullRemoves() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "bar");
+    object.put("foo", null);
+    assertEquals(0, object.length());
+    assertFalse(object.has("foo"));
+    try {
+      object.get("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testPutOpt() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "bar");
+    object.putOpt("foo", null);
+    assertEquals("bar", object.get("foo"));
+    object.putOpt(null, null);
+    assertEquals(1, object.length());
+    object.putOpt(null, "bar");
+    assertEquals(1, object.length());
+  }
+
+  @Test
+  public void testPutOptUnsupportedNumbers() throws JSONException {
+    JSONObject object = new JSONObject();
+    try {
+      object.putOpt("foo", Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.putOpt("foo", Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.putOpt("foo", Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testRemove() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "bar");
+    assertEquals(null, object.remove(null));
+    assertEquals(null, object.remove(""));
+    assertEquals(null, object.remove("bar"));
+    assertEquals("bar", object.remove("foo"));
+    assertEquals(null, object.remove("foo"));
+  }
+
+  @Test
+  public void testBooleans() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", true);
+    object.put("bar", false);
+    object.put("baz", "true");
+    object.put("quux", "false");
+    assertEquals(4, object.length());
+    assertEquals(true, object.getBoolean("foo"));
+    assertEquals(false, object.getBoolean("bar"));
+    assertEquals(true, object.getBoolean("baz"));
+    assertEquals(false, object.getBoolean("quux"));
+    assertFalse(object.isNull("foo"));
+    assertFalse(object.isNull("quux"));
+    assertTrue(object.has("foo"));
+    assertTrue(object.has("quux"));
+    assertFalse(object.has("missing"));
+    assertEquals(true, object.optBoolean("foo"));
+    assertEquals(false, object.optBoolean("bar"));
+    assertEquals(true, object.optBoolean("baz"));
+    assertEquals(false, object.optBoolean("quux"));
+    assertEquals(false, object.optBoolean("missing"));
+    assertEquals(true, object.optBoolean("foo", true));
+    assertEquals(false, object.optBoolean("bar", true));
+    assertEquals(true, object.optBoolean("baz", true));
+    assertEquals(false, object.optBoolean("quux", true));
+    assertEquals(true, object.optBoolean("missing", true));
+
+    object.put("foo", "truE");
+    object.put("bar", "FALSE");
+    assertEquals(true, object.getBoolean("foo"));
+    assertEquals(false, object.getBoolean("bar"));
+    assertEquals(true, object.optBoolean("foo"));
+    assertEquals(false, object.optBoolean("bar"));
+    assertEquals(true, object.optBoolean("foo", false));
+    assertEquals(false, object.optBoolean("bar", false));
+  }
+
+  // http://code.google.com/p/android/issues/detail?id=16411
+  @Test
+  public void testCoerceStringToBoolean() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "maybe");
+    try {
+      object.getBoolean("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals(false, object.optBoolean("foo"));
+    assertEquals(true, object.optBoolean("foo", true));
+  }
+
+  @Test
+  public void testNumbers() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", Double.MIN_VALUE);
+    object.put("bar", 9223372036854775806L);
+    object.put("baz", Double.MAX_VALUE);
+    object.put("quux", -0d);
+    assertEquals(4, object.length());
+
+    String toString = object.toString();
+    assertTrue(toString, toString.contains("\"foo\":4.9E-324"));
+    assertTrue(toString, toString.contains("\"bar\":9223372036854775806"));
+    assertTrue(toString, toString.contains("\"baz\":1.7976931348623157E308"));
+
+    // toString() and getString() return different values for -0d!
+    assertTrue(toString, toString.contains("\"quux\":-0}") // no trailing decimal point
+        || toString.contains("\"quux\":-0,"));
+
+    assertEquals(Double.MIN_VALUE, object.get("foo"));
+    assertEquals(9223372036854775806L, object.get("bar"));
+    assertEquals(Double.MAX_VALUE, object.get("baz"));
+    assertEquals(-0d, object.get("quux"));
+    assertEquals(Double.MIN_VALUE, object.getDouble("foo"), 0);
+    assertEquals(9.223372036854776E18, object.getDouble("bar"), 0);
+    assertEquals(Double.MAX_VALUE, object.getDouble("baz"), 0);
+    assertEquals(-0d, object.getDouble("quux"), 0);
+    assertEquals(0, object.getLong("foo"));
+    assertEquals(9223372036854775806L, object.getLong("bar"));
+    assertEquals(Long.MAX_VALUE, object.getLong("baz"));
+    assertEquals(0, object.getLong("quux"));
+    assertEquals(0, object.getInt("foo"));
+    assertEquals(-2, object.getInt("bar"));
+    assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
+    assertEquals(0, object.getInt("quux"));
+    assertEquals(Double.MIN_VALUE, object.opt("foo"));
+    assertEquals(9223372036854775806L, object.optLong("bar"));
+    assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
+    assertEquals(0, object.optInt("quux"));
+    assertEquals(Double.MIN_VALUE, object.opt("foo"));
+    assertEquals(9223372036854775806L, object.optLong("bar"));
+    assertEquals(Double.MAX_VALUE, object.optDouble("baz"), 0);
+    assertEquals(0, object.optInt("quux"));
+    assertEquals(Double.MIN_VALUE, object.optDouble("foo", 5.0d), 0);
+    assertEquals(9223372036854775806L, object.optLong("bar", 1L));
+    assertEquals(Long.MAX_VALUE, object.optLong("baz", 1L));
+    assertEquals(0, object.optInt("quux", -1));
+    assertEquals("4.9E-324", object.getString("foo"));
+    assertEquals("9223372036854775806", object.getString("bar"));
+    assertEquals("1.7976931348623157E308", object.getString("baz"));
+    assertEquals("-0.0", object.getString("quux"));
+  }
+
+  @Test
+  public void testFloats() throws JSONException {
+    JSONObject object = new JSONObject();
+    try {
+      object.put("foo", (Float) Float.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", (Float) Float.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", (Float) Float.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testOtherNumbers() throws JSONException {
+    Number nan = new Number() {
+      public int intValue() {
+        throw new UnsupportedOperationException();
+      }
+
+      public long longValue() {
+        throw new UnsupportedOperationException();
+      }
+
+      public float floatValue() {
+        throw new UnsupportedOperationException();
+      }
+
+      public double doubleValue() {
+        return Double.NaN;
+      }
+
+      @Override
+      public String toString() {
+        return "x";
+      }
+    };
+
+    JSONObject object = new JSONObject();
+    try {
+      object.put("foo", nan);
+      fail("Object.put() accepted a NaN (via a custom Number class)");
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testForeignObjects() throws JSONException {
+    Object foreign = new Object() {
+      @Override
+      public String toString() {
+        return "x";
+      }
+    };
+
+    // foreign object types are accepted and treated as Strings!
+    JSONObject object = new JSONObject();
+    object.put("foo", foreign);
+    assertEquals("{\"foo\":\"x\"}", object.toString());
+  }
+
+  @Test
+  public void testNullKeys() {
+    try {
+      new JSONObject().put(null, false);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONObject().put(null, 0.0d);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONObject().put(null, 5);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONObject().put(null, 5L);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      new JSONObject().put(null, "foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testStrings() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "true");
+    object.put("bar", "5.5");
+    object.put("baz", "9223372036854775806");
+    object.put("quux", "null");
+    object.put("height", "5\"8' tall");
+
+    assertTrue(object.toString().contains("\"foo\":\"true\""));
+    assertTrue(object.toString().contains("\"bar\":\"5.5\""));
+    assertTrue(object.toString().contains("\"baz\":\"9223372036854775806\""));
+    assertTrue(object.toString().contains("\"quux\":\"null\""));
+    assertTrue(object.toString().contains("\"height\":\"5\\\"8' tall\""));
+
+    assertEquals("true", object.get("foo"));
+    assertEquals("null", object.getString("quux"));
+    assertEquals("5\"8' tall", object.getString("height"));
+    assertEquals("true", object.opt("foo"));
+    assertEquals("5.5", object.optString("bar"));
+    assertEquals("true", object.optString("foo", "x"));
+    assertFalse(object.isNull("foo"));
+
+    assertEquals(true, object.getBoolean("foo"));
+    assertEquals(true, object.optBoolean("foo"));
+    assertEquals(true, object.optBoolean("foo", false));
+    assertEquals(0, object.optInt("foo"));
+    assertEquals(-2, object.optInt("foo", -2));
+
+    assertEquals(5.5d, object.getDouble("bar"), 0);
+    assertEquals(5L, object.getLong("bar"));
+    assertEquals(5, object.getInt("bar"));
+    assertEquals(5, object.optInt("bar", 3));
+
+    // The last digit of the string is a 6 but getLong returns a 7. It's probably parsing as a
+    // double and then converting that to a long. This is consistent with JavaScript.
+    assertEquals(9223372036854775807L, object.getLong("baz"));
+    assertEquals(9.223372036854776E18, object.getDouble("baz"), 0);
+    assertEquals(Integer.MAX_VALUE, object.getInt("baz"));
+
+    assertFalse(object.isNull("quux"));
+    try {
+      object.getDouble("quux");
+      fail();
+    } catch (JSONException e) {
+      // expected
+    }
+    assertEquals(Double.NaN, object.optDouble("quux"), 0);
+    assertEquals(-1.0d, object.optDouble("quux", -1.0d), 0);
+
+    object.put("foo", "TRUE");
+    assertEquals(true, object.getBoolean("foo"));
+  }
+
+  @Test
+  public void testJSONObjects() throws JSONException {
+    JSONObject object = new JSONObject();
+
+    JSONArray a = new JSONArray();
+    JSONObject b = new JSONObject();
+    object.put("foo", a);
+    object.put("bar", b);
+
+    assertSame(a, object.getJSONArray("foo"));
+    assertSame(b, object.getJSONObject("bar"));
+    try {
+      object.getJSONObject("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.getJSONArray("bar");
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals(a, object.optJSONArray("foo"));
+    assertEquals(b, object.optJSONObject("bar"));
+    assertEquals(null, object.optJSONArray("bar"));
+    assertEquals(null, object.optJSONObject("foo"));
+  }
+
+  @Test
+  public void testNullCoercionToString() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", JSONObject.NULL);
+    assertEquals("null", object.getString("foo"));
+  }
+
+  @Test
+  public void testArrayCoercion() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "[true]");
+    try {
+      object.getJSONArray("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testObjectCoercion() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "{}");
+    try {
+      object.getJSONObject("foo");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testAccumulateValueChecking() throws JSONException {
+    JSONObject object = new JSONObject();
+    try {
+      object.accumulate("foo", Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    object.accumulate("foo", 1);
+    try {
+      object.accumulate("foo", Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    object.accumulate("foo", 2);
+    try {
+      object.accumulate("foo", Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testToJSONArray() throws JSONException {
+    JSONObject object = new JSONObject();
+    Object value = new Object();
+    object.put("foo", true);
+    object.put("bar", 5.0d);
+    object.put("baz", -0.0d);
+    object.put("quux", value);
+
+    JSONArray names = new JSONArray();
+    names.put("baz");
+    names.put("quux");
+    names.put("foo");
+
+    JSONArray array = object.toJSONArray(names);
+    assertEquals(-0.0d, array.get(0));
+    assertEquals(value, array.get(1));
+    assertEquals(true, array.get(2));
+
+    object.put("foo", false);
+    assertEquals(true, array.get(2));
+  }
+
+  @Test
+  public void testToJSONArrayMissingNames() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", true);
+    object.put("bar", 5.0d);
+    object.put("baz", JSONObject.NULL);
+
+    JSONArray names = new JSONArray();
+    names.put("bar");
+    names.put("foo");
+    names.put("quux");
+    names.put("baz");
+
+    JSONArray array = object.toJSONArray(names);
+    assertEquals(4, array.length());
+
+    assertEquals(5.0d, array.get(0));
+    assertEquals(true, array.get(1));
+    try {
+      array.get(2);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals(JSONObject.NULL, array.get(3));
+  }
+
+  @Test
+  public void testToJSONArrayNull() throws JSONException {
+    JSONObject object = new JSONObject();
+    assertEquals(null, object.toJSONArray(null));
+    object.put("foo", 5);
+    try {
+      object.toJSONArray(null);
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testToJSONArrayEndsUpEmpty() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    JSONArray array = new JSONArray();
+    array.put("bar");
+    assertEquals(1, object.toJSONArray(array).length());
+  }
+
+  @Test
+  public void testToJSONArrayNonString() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    object.put("null", 10);
+    object.put("false", 15);
+
+    JSONArray names = new JSONArray();
+    names.put(JSONObject.NULL);
+    names.put(false);
+    names.put("foo");
+
+    // array elements are converted to strings to do name lookups on the map!
+    JSONArray array = object.toJSONArray(names);
+    assertEquals(3, array.length());
+    assertEquals(10, array.get(0));
+    assertEquals(15, array.get(1));
+    assertEquals(5, array.get(2));
+  }
+
+  @Test
+  public void testPutUnsupportedNumbers() throws JSONException {
+    JSONObject object = new JSONObject();
+    try {
+      object.put("foo", Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testPutUnsupportedNumbersAsObjects() throws JSONException {
+    JSONObject object = new JSONObject();
+    try {
+      object.put("foo", (Double) Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", (Double) Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      object.put("foo", (Double) Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  /**
+   * Although JSONObject is usually defensive about which numbers it accepts, it doesn't check
+   * inputs in its constructor.
+   */
+  @Test
+  public void testCreateWithUnsupportedNumbers() throws JSONException {
+    Map<String, Object> contents = new HashMap<String, Object>();
+    contents.put("foo", Double.NaN);
+    contents.put("bar", Double.NEGATIVE_INFINITY);
+    contents.put("baz", Double.POSITIVE_INFINITY);
+
+    JSONObject object = new JSONObject(contents);
+    assertEquals(Double.NaN, object.get("foo"));
+    assertEquals(Double.NEGATIVE_INFINITY, object.get("bar"));
+    assertEquals(Double.POSITIVE_INFINITY, object.get("baz"));
+  }
+
+  @Test
+  public void testToStringWithUnsupportedNumbers() {
+    // when the object contains an unsupported number, toString returns null!
+    JSONObject object = new JSONObject(Collections.singletonMap("foo", Double.NaN));
+    assertEquals(null, object.toString());
+  }
+
+  @Test
+  public void testMapConstructorCopiesContents() throws JSONException {
+    Map<String, Object> contents = new HashMap<String, Object>();
+    contents.put("foo", 5);
+    JSONObject object = new JSONObject(contents);
+    contents.put("foo", 10);
+    assertEquals(5, object.get("foo"));
+  }
+
+  @Test
+  public void testMapConstructorWithBogusEntries() {
+    Map<Object, Object> contents = new HashMap<Object, Object>();
+    contents.put(5, 5);
+
+    try {
+      new JSONObject(contents);
+      fail("JSONObject constructor doesn't validate its input!");
+    } catch (Exception ignored) {
+    }
+  }
+
+  @Test
+  public void testTokenerConstructor() throws JSONException {
+    JSONObject object = new JSONObject(new JSONTokener("{\"foo\": false}"));
+    assertEquals(1, object.length());
+    assertEquals(false, object.get("foo"));
+  }
+
+  @Test
+  public void testTokenerConstructorWrongType() throws JSONException {
+    try {
+      new JSONObject(new JSONTokener("[\"foo\", false]"));
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testTokenerConstructorNull() throws JSONException {
+    try {
+      new JSONObject((JSONTokener) null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  @Test
+  public void testTokenerConstructorParseFail() {
+    try {
+      new JSONObject(new JSONTokener("{"));
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testStringConstructor() throws JSONException {
+    JSONObject object = new JSONObject("{\"foo\": false}");
+    assertEquals(1, object.length());
+    assertEquals(false, object.get("foo"));
+  }
+
+  @Test
+  public void testStringConstructorWrongType() throws JSONException {
+    try {
+      new JSONObject("[\"foo\", false]");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testStringConstructorNull() throws JSONException {
+    try {
+      new JSONObject((String) null);
+      fail();
+    } catch (NullPointerException ignored) {
+    }
+  }
+
+  @Test
+  public void testStringConstructorParseFail() {
+    try {
+      new JSONObject("{");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testCopyConstructor() throws JSONException {
+    JSONObject source = new JSONObject();
+    source.put("a", JSONObject.NULL);
+    source.put("b", false);
+    source.put("c", 5);
+
+    JSONObject copy = new JSONObject(source, new String[] {"a", "c"});
+    assertEquals(2, copy.length());
+    assertEquals(JSONObject.NULL, copy.get("a"));
+    assertEquals(5, copy.get("c"));
+    assertEquals(null, copy.opt("b"));
+  }
+
+  @Test
+  public void testCopyConstructorMissingName() throws JSONException {
+    JSONObject source = new JSONObject();
+    source.put("a", JSONObject.NULL);
+    source.put("b", false);
+    source.put("c", 5);
+
+    JSONObject copy = new JSONObject(source, new String[] {"a", "c", "d"});
+    assertEquals(2, copy.length());
+    assertEquals(JSONObject.NULL, copy.get("a"));
+    assertEquals(5, copy.get("c"));
+    assertEquals(0, copy.optInt("b"));
+  }
+
+  @Test
+  public void testAccumulateMutatesInPlace() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    object.accumulate("foo", 6);
+    JSONArray array = object.getJSONArray("foo");
+    assertEquals("[5,6]", array.toString());
+    object.accumulate("foo", 7);
+    assertEquals("[5,6,7]", array.toString());
+  }
+
+  @Test
+  public void testAccumulateExistingArray() throws JSONException {
+    JSONArray array = new JSONArray();
+    JSONObject object = new JSONObject();
+    object.put("foo", array);
+    object.accumulate("foo", 5);
+    assertEquals("[5]", array.toString());
+  }
+
+  @Test
+  public void testAccumulatePutArray() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.accumulate("foo", 5);
+    assertEquals("{\"foo\":5}", object.toString());
+    object.accumulate("foo", new JSONArray());
+    assertEquals("{\"foo\":[5,[]]}", object.toString());
+  }
+
+  @Test
+  public void testAccumulateNull() {
+    JSONObject object = new JSONObject();
+    try {
+      object.accumulate(null, 5);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testEmptyStringKey() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("", 5);
+    assertEquals(5, object.get(""));
+    assertEquals("{\"\":5}", object.toString());
+  }
+
+  @Test
+  public void testNullValue() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", JSONObject.NULL);
+    object.put("bar", null);
+
+    // there are two ways to represent null; each behaves differently!
+    assertTrue(object.has("foo"));
+    assertFalse(object.has("bar"));
+    assertTrue(object.isNull("foo"));
+    assertTrue(object.isNull("bar"));
+  }
+
+  @Test
+  public void testNullValue_equalsAndHashCode() {
+    // noinspection ObjectEqualsNull
+    assertTrue(JSONObject.NULL.equals(null)); // guaranteed by javadoc
+    // not guaranteed by javadoc, but seems like a good idea
+    assertEquals(Objects.hashCode(null), JSONObject.NULL.hashCode());
+  }
+
+  @Test
+  public void testHas() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    assertTrue(object.has("foo"));
+    assertFalse(object.has("bar"));
+    assertFalse(object.has(null));
+  }
+
+  @Test
+  public void testOptNull() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", "bar");
+    assertEquals(null, object.opt(null));
+    assertEquals(false, object.optBoolean(null));
+    assertEquals(Double.NaN, object.optDouble(null), 0);
+    assertEquals(0, object.optInt(null));
+    assertEquals(0L, object.optLong(null));
+    assertEquals(null, object.optJSONArray(null));
+    assertEquals(null, object.optJSONObject(null));
+    assertEquals("", object.optString(null));
+    assertEquals(true, object.optBoolean(null, true));
+    assertEquals(0.0d, object.optDouble(null, 0.0d), 0);
+    assertEquals(1, object.optInt(null, 1));
+    assertEquals(1L, object.optLong(null, 1L));
+    assertEquals("baz", object.optString(null, "baz"));
+  }
+
+  @Test
+  public void testToStringWithIndentFactor() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", new JSONArray(Arrays.asList(5, 6)));
+    object.put("bar", new JSONObject());
+    String foobar = "{\n" + "     \"foo\": [\n" + "          5,\n" + "          6\n" + "     ],\n"
+        + "     \"bar\": {}\n" + "}";
+    String barfoo = "{\n" + "     \"bar\": {},\n" + "     \"foo\": [\n" + "          5,\n"
+        + "          6\n" + "     ]\n" + "}";
+    String string = object.toString(5);
+    assertTrue(string, foobar.equals(string) || barfoo.equals(string));
+  }
+
+  @Test
+  public void testNames() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    object.put("bar", 6);
+    object.put("baz", 7);
+    JSONArray array = object.names();
+    assertTrue(array.toString().contains("foo"));
+    assertTrue(array.toString().contains("bar"));
+    assertTrue(array.toString().contains("baz"));
+  }
+
+  @Test
+  public void testKeysEmptyObject() {
+    JSONObject object = new JSONObject();
+    assertFalse(object.keys().hasNext());
+    try {
+      object.keys().next();
+      fail();
+    } catch (NoSuchElementException ignored) {
+    }
+  }
+
+  @Test
+  public void testKeys() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    object.put("bar", 6);
+    object.put("foo", 7);
+
+    @SuppressWarnings("unchecked")
+    Iterator<String> keys = object.keys();
+    Set<String> result = new HashSet<String>();
+    assertTrue(keys.hasNext());
+    result.add(keys.next());
+    assertTrue(keys.hasNext());
+    result.add(keys.next());
+    assertFalse(keys.hasNext());
+    assertEquals(new HashSet<String>(Arrays.asList("foo", "bar")), result);
+
+    try {
+      keys.next();
+      fail();
+    } catch (NoSuchElementException ignored) {
+    }
+  }
+
+  @Test
+  public void testMutatingKeysMutatesObject() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    Iterator keys = object.keys();
+    keys.next();
+    keys.remove();
+    assertEquals(0, object.length());
+  }
+
+  @Test
+  public void testQuote() {
+    // covered by JSONStringerTest.testEscaping
+  }
+
+  @Test
+  public void testQuoteNull() throws JSONException {
+    assertEquals("\"\"", JSONObject.quote(null));
+  }
+
+  @Test
+  public void testNumberToString() throws JSONException {
+    assertEquals("5", JSONObject.numberToString(5));
+    assertEquals("-0", JSONObject.numberToString(-0.0d));
+    assertEquals("9223372036854775806", JSONObject.numberToString(9223372036854775806L));
+    assertEquals("4.9E-324", JSONObject.numberToString(Double.MIN_VALUE));
+    assertEquals("1.7976931348623157E308", JSONObject.numberToString(Double.MAX_VALUE));
+    try {
+      JSONObject.numberToString(Double.NaN);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      JSONObject.numberToString(Double.NEGATIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    try {
+      JSONObject.numberToString(Double.POSITIVE_INFINITY);
+      fail();
+    } catch (JSONException ignored) {
+    }
+    assertEquals("0.001", JSONObject.numberToString(new BigDecimal("0.001")));
+    assertEquals("9223372036854775806",
+        JSONObject.numberToString(new BigInteger("9223372036854775806")));
+    try {
+      JSONObject.numberToString(null);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void test_wrap() throws Exception {
+    assertEquals(JSONObject.NULL, JSONObject.wrap(null));
+
+    JSONArray a = new JSONArray();
+    assertEquals(a, JSONObject.wrap(a));
+
+    JSONObject o = new JSONObject();
+    assertEquals(o, JSONObject.wrap(o));
+
+    assertEquals(JSONObject.NULL, JSONObject.wrap(JSONObject.NULL));
+
+    assertTrue(JSONObject.wrap(new byte[0]) instanceof JSONArray);
+    assertTrue(JSONObject.wrap(new ArrayList<String>()) instanceof JSONArray);
+    assertTrue(JSONObject.wrap(new HashMap<String, String>()) instanceof JSONObject);
+    assertTrue(JSONObject.wrap(0.0) instanceof Double);
+    assertTrue(JSONObject.wrap("hello") instanceof String);
+  }
+
+  // https://code.google.com/p/android/issues/detail?id=55114
+  @Test
+  public void test_toString_listAsMapValue() throws Exception {
+    ArrayList<Object> list = new ArrayList<Object>();
+    list.add("a");
+    list.add(new ArrayList<String>());
+    Map<String, Object> map = new TreeMap<String, Object>();
+    map.put("x", "l");
+    map.put("y", list);
+    assertEquals("{\"x\":\"l\",\"y\":[\"a\",[]]}", new JSONObject(map).toString());
+  }
+
+  @Test
+  public void testAppendExistingInvalidKey() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.put("foo", 5);
+    try {
+      object.append("foo", 6);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testAppendExistingArray() throws JSONException {
+    JSONArray array = new JSONArray();
+    JSONObject object = new JSONObject();
+    object.put("foo", array);
+    object.append("foo", 5);
+    assertEquals("[5]", array.toString());
+  }
+
+  @Test
+  public void testAppendPutArray() throws JSONException {
+    JSONObject object = new JSONObject();
+    object.append("foo", 5);
+    assertEquals("{\"foo\":[5]}", object.toString());
+    object.append("foo", new JSONArray());
+    assertEquals("{\"foo\":[5,[]]}", object.toString());
+  }
+
+  @Test
+  public void testAppendNull() {
+    JSONObject object = new JSONObject();
+    try {
+      object.append(null, 5);
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  // https://code.google.com/p/android/issues/detail?id=103641
+  @Test
+  public void testInvalidUnicodeEscape() {
+    try {
+      new JSONObject("{\"q\":\"\\u\", \"r\":[]}");
+      fail();
+    } catch (JSONException ignored) {
+    }
+  }
+
+  @Test
+  public void testBeanThings()
+      throws IllegalAccessException, IntrospectionException, InvocationTargetException {
+    Foo f = new Foo();
+    assertEquals("{\"a\":1,\"b\":1,\"c\":\"c\",\"d\":[{\"e\":\"echo\"}]}",
+        new JSONObject(f).toString());
+  }
+
+  @Test
+  public void testGetNames() throws Exception {
+    assertArrayEquals(new String[] {"a", "b", "c", "d"},
+        JSONObject.getNames(new JSONObject(new Foo())));
+  }
+
+  private static class Foo {
+    public double getA() {
+      return 1.0;
+    }
+
+    public int getB() {
+      return 1;
+    }
+
+    public String getC() {
+      return "c";
+    }
+
+    public List<Bar> getD() {
+      ArrayList<Bar> r = new ArrayList<Bar>();
+      r.add(new Bar());
+      return r;
+    }
+  }
+
+  private static class Bar {
+    public String getE() {
+      return "echo";
+    }
+  }
+
+  @Test
+  public void testEnumWrapper() throws Exception {
+    Object y = JSONObject.wrap(E.A);
+    assertEquals("A", y);
+    assertTrue(y instanceof String);
+  }
+
+  enum E {
+    A {
+      int key() {
+        return 1;
+      }
+    },
+    B {
+      int key() {
+        return 2;
+      }
+    };
+    int key() {
+      return -1;
+    }
+  }
 }