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 2016/05/20 17:11:04 UTC
[39/50] [abbrv] incubator-geode git commit: GEODE-1391 JsonFormatter
javadocs need to be cleaned up
GEODE-1391 JsonFormatter javadocs need to be cleaned up
I've made another pass at JSONFormatter javadocs, putting the JSON <-> Java
types in a table and correcting a few grammatical errors. I also found that
the class was being referred to as PdxFormatter in a lot of places and that
its test was also using this name instead of JSONFormatter.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/9d23a695
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9d23a695
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9d23a695
Branch: refs/heads/feature/GEODE-835
Commit: 9d23a69506a0ff531831147c4c704a3553aa6d9f
Parents: 14a548f
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Thu May 19 14:11:50 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Thu May 19 14:20:14 2016 -0700
----------------------------------------------------------------------
.../com/gemstone/gemfire/pdx/JSONFormatter.java | 69 +-
.../gemfire/pdx/JSONFormatterJUnitTest.java | 208 ++++
.../pdx/JSONPdxClientServerDUnitTest.java | 10 +-
.../pdx/PdxFormatterPutGetJUnitTest.java | 208 ----
.../gemfire/pdx/TestObjectForJSONFormatter.java | 1000 +++++++++++++++++
.../gemfire/pdx/TestObjectForPdxFormatter.java | 1003 ------------------
6 files changed, 1251 insertions(+), 1247 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/main/java/com/gemstone/gemfire/pdx/JSONFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/pdx/JSONFormatter.java b/geode-core/src/main/java/com/gemstone/gemfire/pdx/JSONFormatter.java
index b9b6329..61f5643 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/pdx/JSONFormatter.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/pdx/JSONFormatter.java
@@ -32,27 +32,34 @@ import com.gemstone.gemfire.pdx.internal.json.PdxToJSON;
/**
- * PdxFormatter class has static method {@link JSONFormatter#fromJSON(String)} to convert JSON
- * document into a {@link PdxInstance} and static method {@link JSONFormatter#toJSON(PdxInstance)}
- * to convert back {@link PdxInstance} into a JSON Document.
- *
- * Using this, application can put PdxInstance(a converted JSON document) in a geode cache.
- * Application can define indexes on PdxInstance and then query those using OQL. Query will
- * return the PdxInstances as a result, that needs to convert back into JSON document.
- *
- * This uses Jackson parser to parse the json document. Parser treats values in json document as
- * number(byte, short, int, long..), string, array, object, 'true', 'false' or 'null'. Which
- * further treated as following java types in PdxInstance
- *
- * JSON object is converted into {@link PdxInstance}
- * JSON arrays is converted into {@link java.util.LinkedList}
- * JSON BigDecimal is converted into {@link BigDecimal}
- * JSON BigInterger is converted into {@link BigInteger}
- * JSON Double is converted into java primitive double
- * JSON float is converted into java primitive float
- * JSON boolean is converted into java primitive boolean
- * JSON Integer is converted based on its range to java byte, short or int.
- * JSON null is converted java null object.
+ * <p>
+ * JSONFormatter has a static method {@link JSONFormatter#fromJSON(String)} to convert a JSON
+ * document into a {@link PdxInstance} and a static method {@link JSONFormatter#toJSON(PdxInstance)}
+ * to convert a {@link PdxInstance} into a JSON Document.
+ * </p>
+ * <p>
+ * Using these methods an applications may convert a JSON document into a PdxInstance for storing in the cache.
+ * Indexes can then be defined on the PdxInstances so that queries can be performed using OQL. Queries will
+ * return PdxInstances and these can be turned back back into JSON documents using JSONFormatter.
+ * </p>
+ * <p>
+ * JSONFormatter treats values in a json document as
+ * number(byte, short, int, long..), string, array, object, 'true', 'false' or 'null'. These correspond
+ * to the following java types:
+ * </p>
+ *
+ * <table>
+ * <th>JSON</th><th>Java</th>
+ * <tr> <td>object</td> <td>{@link PdxInstance}</td> </tr>
+ * <tr> <td>arrays</td> <td>{@link java.util.LinkedList}</td> </tr>
+ * <tr> <td>BigDecimal</td> <td>{@link BigDecimal}</td> </tr>
+ * <tr> <td>BigInterger</td> <td>{@link BigInteger}</td> </tr>
+ * <tr> <td>Double</td> <td>double</td> </tr>
+ * <tr> <td>float</td> <td>float</td> </tr>
+ * <tr> <td>boolean</td> <td>boolean</td> </tr>
+ * <tr> <td>Integer</td> <td>byte, short or int</td> </tr>
+ * <tr> <td>null</td> <td>null</td> </tr>
+ * </table>
*/
public class JSONFormatter {
@@ -65,10 +72,10 @@ public class JSONFormatter {
}
/**
- * To create PdxInstance from JSON string
+ * Converts a JSON document into a PdxInstance
*
* @return the PdxInstance.
- * @throws JSONFormatterException if unable to parse JSON doucment
+ * @throws JSONFormatterException if unable to parse the JSON document
*/
public static PdxInstance fromJSON(String jsonString) {
JsonParser jp = null;
@@ -86,10 +93,10 @@ public class JSONFormatter {
}
/**
- * To create PdxInstance from JSON string
+ * Converts a JSON document into a PdxInstance
*
* @return the PdxInstance.
- * @throws JSONFormatterException if unable to parse JSON doucment
+ * @throws JSONFormatterException if unable to parse the JSON document
*/
public static PdxInstance fromJSON(byte[] jsonByteArray) {
JsonParser jp = null;
@@ -112,32 +119,32 @@ public class JSONFormatter {
}
/**
- *To create JSON string from PdxInstance
+ * Converts a PdxInstance into a JSON document
*
* @return the JSON string.
- * @throws JSONFormatterException if unable to create JSON doucment from PdxInstance
+ * @throws JSONFormatterException if unable to create the JSON document
*/
public static String toJSON(PdxInstance pdxInstance) {
try {
PdxToJSON pj = new PdxToJSON(pdxInstance);
return pj.getJSON();
} catch (Exception e) {
- throw new JSONFormatterException("Could not create JSON document from PdxInstance ", e);
+ throw new JSONFormatterException("Could not create JSON document from PdxInstance", e);
}
}
/**
- *To create JSON byte array from PdxInstance
+ * Converts a PdxInstance into a JSON document in byte-array form
*
* @return the JSON byte array.
- * @throws JSONFormatterException if unable to create JSON doucment from PdxInstance
+ * @throws JSONFormatterException if unable to create the JSON document
*/
public static byte[] toJSONByteArray(PdxInstance pdxInstance) {
try {
PdxToJSON pj = new PdxToJSON(pdxInstance);
return pj.getJSONByteArray();
} catch (Exception e) {
- throw new JSONFormatterException("Could not create JSON document from PdxInstance ", e);
+ throw new JSONFormatterException("Could not create JSON document from PdxInstance", e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONFormatterJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONFormatterJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONFormatterJUnitTest.java
new file mode 100755
index 0000000..458c020
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONFormatterJUnitTest.java
@@ -0,0 +1,208 @@
+/*
+ * 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 com.gemstone.gemfire.pdx;
+
+import static org.junit.Assert.fail;
+
+import java.text.SimpleDateFormat;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.gemstone.gemfire.cache.AttributesFactory;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.internal.Assert;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+@Category(IntegrationTest.class)
+public class JSONFormatterJUnitTest {
+
+ private GemFireCacheImpl c;
+ private final String PRIMITIVE_KV_STORE_REGION = "primitiveKVStore";
+
+ public JSONFormatterJUnitTest() {
+ super();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ this.c = (GemFireCacheImpl) new CacheFactory().set("mcast-port", "0").setPdxReadSerialized(true).create();
+
+ //start cache-server
+ CacheServer server = c.addCacheServer();
+ final int serverPort = 40405;
+ server.setPort(serverPort);
+ server.start();
+
+ // Create region, primitiveKVStore
+ final AttributesFactory<Object, Object> af1 = new AttributesFactory<Object, Object>();
+ af1.setDataPolicy(DataPolicy.PARTITION);
+ final RegionAttributes<Object, Object> rAttributes = af1.create();
+ c.createRegion(PRIMITIVE_KV_STORE_REGION, rAttributes);
+ }
+
+ @After
+ public void tearDown() {
+ //shutdown and clean up the manager node.
+ this.c.close();
+ }
+
+ private void ValidatePdxInstanceToJsonConversion(){
+
+ Cache c = CacheFactory.getAnyInstance();
+ Region region = c.getRegion("primitiveKVStore");
+
+ TestObjectForJSONFormatter actualTestObject = new TestObjectForJSONFormatter();
+ actualTestObject.defaultInitialization();
+
+ //Testcase-1: PdxInstance to Json conversion
+ //put Object and getvalue as Pdxinstance
+ region.put("201", actualTestObject);
+ Object receivedObject = region.get("201");
+
+ //PdxInstance->Json conversion
+ if(receivedObject instanceof PdxInstance){
+ PdxInstance pi = (PdxInstance)receivedObject;
+ String json = JSONFormatter.toJSON(pi);
+
+ verifyJsonWithJavaObject(json, actualTestObject);
+ }else {
+ fail("receivedObject is expected to be of type PdxInstance");
+ }
+
+ }
+
+ //Testcase-2: validate Json->PdxInstance-->Java conversion
+ private void verifyJsonToPdxInstanceConversion(){
+ TestObjectForJSONFormatter expectedTestObject = new TestObjectForJSONFormatter();
+ expectedTestObject.defaultInitialization();
+ Cache c = CacheFactory.getAnyInstance();
+ Region region = c.getRegion("primitiveKVStore");
+
+ //1.gets pdxInstance using R.put() and R.get()
+ region.put("501", expectedTestObject);
+ Object receivedObject = region.get("501");
+ if(receivedObject instanceof PdxInstance){
+ PdxInstance expectedPI = (PdxInstance)receivedObject;
+
+ //2. Get the JSON string from actualTestObject using jackson ObjectMapper.
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ String json;
+ try {
+ json = objectMapper.writeValueAsString(expectedTestObject);
+ String jsonWithClassType = expectedTestObject.addClassTypeToJson(json);
+
+ //3. Get PdxInstance from the Json String and Validate pi.getObject() API.
+ PdxInstance actualPI = JSONFormatter.fromJSON(jsonWithClassType);
+ //Note: expectedPI will contains those fields that are part of toData()
+ // expectedPI.className = "com.gemstone.gemfire.pdx.TestObjectForJSONFormatter"
+ // actualPI will contains all the fields that are member of the class.
+ // actualPI..className = __GEMFIRE_JSON
+ // and hence actualPI.equals(expectedPI) will returns false.
+
+ Object actualTestObject = actualPI.getObject();
+ if(actualTestObject instanceof TestObjectForJSONFormatter){
+ boolean isObjectEqual = actualTestObject.equals(expectedTestObject);
+ Assert.assertTrue(isObjectEqual, "actualTestObject and expectedTestObject should be equal");
+ }else {
+ fail("actualTestObject is expected to be of type PdxInstance");
+ }
+ } catch (JsonProcessingException e1) {
+ fail("JsonProcessingException occurred:" + e1.getMessage());
+ } catch (JSONException e) {
+ fail("JSONException occurred:" + e.getMessage());
+ }
+ }else {
+ fail("receivedObject is expected to be of type PdxInstance");
+ }
+ }
+
+ private void verifyJsonWithJavaObject (String json, TestObjectForJSONFormatter testObject) {
+ try {
+ JSONObject jsonObject = new JSONObject(json);
+
+ //Testcase-1: Validate json string against the pdxInstance.
+ //validation for primitive types
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Int type values are not matched",
+ testObject.getP_int(), jsonObject.getInt(testObject.getP_intFN()));
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: long type values are not matched",
+ testObject.getP_long(), jsonObject.getLong(testObject.getP_longFN()));
+
+ //validation for wrapper types
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Boolean type values are not matched",
+ testObject.getW_bool().booleanValue(), jsonObject.getBoolean(testObject.getW_boolFN()));
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Float type values are not matched",
+ testObject.getW_double().doubleValue(), jsonObject.getDouble(testObject.getW_doubleFN()));
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: bigDec type values are not matched",
+ testObject.getW_bigDec().longValue(), jsonObject.getLong(testObject.getW_bigDecFN()));
+
+ //vlidation for array types
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Byte[] type values are not matched",
+ (int)testObject.getW_byteArray()[1], jsonObject.getJSONArray(testObject.getW_byteArrayFN()).getInt(1));
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Double[] type values are not matched",
+ testObject.getW_doubleArray()[0], jsonObject.getJSONArray(testObject.getW_doubleArrayFN()).getDouble(0));
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: String[] type values are not matched",
+ testObject.getW_strArray()[2], jsonObject.getJSONArray(testObject.getW_strArrayFN()).getString(2));
+
+ //validation for collection types
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: list type values are not matched",
+ testObject.getC_list().get(0),
+ jsonObject.getJSONArray(testObject.getC_listFN()).getString(0));
+
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: stack type values are not matched",
+ testObject.getC_stack().get(2),
+ jsonObject.getJSONArray(testObject.getC_stackFN()).getString(2));
+
+ //validation for Map
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Map type values are not matched",
+ testObject.getM_empByCity().get("Ahmedabad").get(0).getFname(),
+ jsonObject.getJSONObject(testObject.getM_empByCityFN()).getJSONArray("Ahmedabad").getJSONObject(0).getString("fname"));
+
+ //validation Enum
+ junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Enum type values are not matched",
+ testObject.getDay().toString(),
+ jsonObject.getString(testObject.getDayFN()));
+
+ } catch (JSONException e) {
+ fail("Error in VerifyPdxInstanceToJson, Malformed json, can not create JSONArray from it");
+ }
+ }
+
+ @Test
+ public void testJSONFormatterAPIs() {
+ ValidatePdxInstanceToJsonConversion();
+ verifyJsonToPdxInstanceConversion();
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java
index 55aa5aa..d76b5bd 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java
@@ -141,7 +141,7 @@ public class JSONPdxClientServerDUnitTest extends CacheTestCase {
Region region = getRootRegion("testSimplePdx");
//Create Object and initialize its members.
- TestObjectForPdxFormatter testObject = new TestObjectForPdxFormatter();
+ TestObjectForJSONFormatter testObject = new TestObjectForJSONFormatter();
testObject.defaultInitialization();
// put the object into cache.
@@ -205,7 +205,7 @@ public class JSONPdxClientServerDUnitTest extends CacheTestCase {
}
//TestCase-2 : Validate Java-->JSON-->PdxInstance --> Java Mapping
- TestObjectForPdxFormatter actualTestObject = new TestObjectForPdxFormatter();
+ TestObjectForJSONFormatter actualTestObject = new TestObjectForJSONFormatter();
actualTestObject.defaultInitialization();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
@@ -227,13 +227,13 @@ public class JSONPdxClientServerDUnitTest extends CacheTestCase {
//4. get the actualType testObject from the pdxInstance and compare it with actualTestObject
Object getObj = receivedPdxInstance.getObject();
- if(getObj instanceof TestObjectForPdxFormatter){
- TestObjectForPdxFormatter receivedTestObject = (TestObjectForPdxFormatter)getObj;
+ if(getObj instanceof TestObjectForJSONFormatter){
+ TestObjectForJSONFormatter receivedTestObject = (TestObjectForJSONFormatter)getObj;
boolean isEqual = actualTestObject.equals(receivedTestObject);
Assert.assertTrue(isEqual, "actualTestObject and receivedTestObject should be equal");
}else {
- fail("getObj is expected to be an instance of TestObjectForPdxFormatter");
+ fail("getObj is expected to be an instance of TestObjectForJSONFormatter");
}
}else {
fail("receivedObject is expected to be of type PdxInstance");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxFormatterPutGetJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxFormatterPutGetJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxFormatterPutGetJUnitTest.java
deleted file mode 100644
index b1a81b5..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxFormatterPutGetJUnitTest.java
+++ /dev/null
@@ -1,208 +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 com.gemstone.gemfire.pdx;
-
-import static org.junit.Assert.fail;
-
-import java.text.SimpleDateFormat;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.gemstone.gemfire.cache.AttributesFactory;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.DataPolicy;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.server.CacheServer;
-import com.gemstone.gemfire.internal.Assert;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-@Category(IntegrationTest.class)
-public class PdxFormatterPutGetJUnitTest {
-
- private GemFireCacheImpl c;
- private final String PRIMITIVE_KV_STORE_REGION = "primitiveKVStore";
-
- public PdxFormatterPutGetJUnitTest() {
- super();
- }
-
- @Before
- public void setUp() throws Exception {
- this.c = (GemFireCacheImpl) new CacheFactory().set("mcast-port", "0").setPdxReadSerialized(true).create();
-
- //start cache-server
- CacheServer server = c.addCacheServer();
- final int serverPort = 40405;
- server.setPort(serverPort);
- server.start();
-
- // Create region, primitiveKVStore
- final AttributesFactory<Object, Object> af1 = new AttributesFactory<Object, Object>();
- af1.setDataPolicy(DataPolicy.PARTITION);
- final RegionAttributes<Object, Object> rAttributes = af1.create();
- c.createRegion(PRIMITIVE_KV_STORE_REGION, rAttributes);
- }
-
- @After
- public void tearDown() {
- //shutdown and clean up the manager node.
- this.c.close();
- }
-
- private void ValidatePdxInstanceToJsonConversion(){
-
- Cache c = CacheFactory.getAnyInstance();
- Region region = c.getRegion("primitiveKVStore");
-
- TestObjectForPdxFormatter actualTestObject = new TestObjectForPdxFormatter();
- actualTestObject.defaultInitialization();
-
- //Testcase-1: PdxInstance to Json conversion
- //put Object and getvalue as Pdxinstance
- region.put("201", actualTestObject);
- Object receivedObject = region.get("201");
-
- //PdxInstance->Json conversion
- if(receivedObject instanceof PdxInstance){
- PdxInstance pi = (PdxInstance)receivedObject;
- String json = JSONFormatter.toJSON(pi);
-
- verifyJsonWithJavaObject(json, actualTestObject);
- }else {
- fail("receivedObject is expected to be of type PdxInstance");
- }
-
- }
-
- //Testcase-2: validate Json->PdxInstance-->Java conversion
- private void VarifyJsonToPdxInstanceConversion(){
- TestObjectForPdxFormatter expectedTestObject = new TestObjectForPdxFormatter();
- expectedTestObject.defaultInitialization();
- Cache c = CacheFactory.getAnyInstance();
- Region region = c.getRegion("primitiveKVStore");
-
- //1.gets pdxInstance using R.put() and R.get()
- region.put("501", expectedTestObject);
- Object receivedObject = region.get("501");
- if(receivedObject instanceof PdxInstance){
- PdxInstance expectedPI = (PdxInstance)receivedObject;
-
- //2. Get the JSON string from actualTestObject using jackson ObjectMapper.
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-
- String json;
- try {
- json = objectMapper.writeValueAsString(expectedTestObject);
- String jsonWithClassType = expectedTestObject.addClassTypeToJson(json);
-
- //3. Get PdxInstance from the Json String and Validate pi.getObject() API.
- PdxInstance actualPI = JSONFormatter.fromJSON(jsonWithClassType);
- //Note: expectedPI will contains those fields that are part of toData()
- // expectedPI.className = "com.gemstone.gemfire.pdx.TestObjectForPdxFormatter"
- // actualPI will contains all the fields that are member of the class.
- // actualPI..className = __GEMFIRE_JSON
- // and hence actualPI.equals(expectedPI) will returns false.
-
- Object actualTestObject = actualPI.getObject();
- if(actualTestObject instanceof TestObjectForPdxFormatter){
- boolean isObjectEqual = actualTestObject.equals(expectedTestObject);
- Assert.assertTrue(isObjectEqual, "actualTestObject and expectedTestObject should be equal");
- }else {
- fail("actualTestObject is expected to be of type PdxInstance");
- }
- } catch (JsonProcessingException e1) {
- fail("JsonProcessingException occurred:" + e1.getMessage());
- } catch (JSONException e) {
- fail("JSONException occurred:" + e.getMessage());
- }
- }else {
- fail("receivedObject is expected to be of type PdxInstance");
- }
- }
-
- private void verifyJsonWithJavaObject (String json, TestObjectForPdxFormatter testObject) {
- try {
- JSONObject jsonObject = new JSONObject(json);
-
- //Testcase-1: Validate json string against the pdxInstance.
- //validation for primitive types
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Int type values are not matched",
- testObject.getP_int(), jsonObject.getInt(testObject.getP_intFN()));
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: long type values are not matched",
- testObject.getP_long(), jsonObject.getLong(testObject.getP_longFN()));
-
- //validation for wrapper types
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Boolean type values are not matched",
- testObject.getW_bool().booleanValue(), jsonObject.getBoolean(testObject.getW_boolFN()));
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Float type values are not matched",
- testObject.getW_double().doubleValue(), jsonObject.getDouble(testObject.getW_doubleFN()));
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: bigDec type values are not matched",
- testObject.getW_bigDec().longValue(), jsonObject.getLong(testObject.getW_bigDecFN()));
-
- //vlidation for array types
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Byte[] type values are not matched",
- (int)testObject.getW_byteArray()[1], jsonObject.getJSONArray(testObject.getW_byteArrayFN()).getInt(1));
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Double[] type values are not matched",
- testObject.getW_doubleArray()[0], jsonObject.getJSONArray(testObject.getW_doubleArrayFN()).getDouble(0));
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: String[] type values are not matched",
- testObject.getW_strArray()[2], jsonObject.getJSONArray(testObject.getW_strArrayFN()).getString(2));
-
- //validation for collection types
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: list type values are not matched",
- testObject.getC_list().get(0),
- jsonObject.getJSONArray(testObject.getC_listFN()).getString(0));
-
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: stack type values are not matched",
- testObject.getC_stack().get(2),
- jsonObject.getJSONArray(testObject.getC_stackFN()).getString(2));
-
- //validation for Map
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Map type values are not matched",
- testObject.getM_empByCity().get("Ahmedabad").get(0).getFname(),
- jsonObject.getJSONObject(testObject.getM_empByCityFN()).getJSONArray("Ahmedabad").getJSONObject(0).getString("fname"));
-
- //validation Enum
- junit.framework.Assert.assertEquals("VerifyPdxInstanceToJson: Enum type values are not matched",
- testObject.getDay().toString(),
- jsonObject.getString(testObject.getDayFN()));
-
- } catch (JSONException e) {
- fail("Error in VerifyPdxInstanceToJson, Malformed json, can not create JSONArray from it");
- }
- }
-
- @Test
- public void testPdxFormatterAPIs() {
- ValidatePdxInstanceToJsonConversion();
- VarifyJsonToPdxInstanceConversion();
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForJSONFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForJSONFormatter.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForJSONFormatter.java
new file mode 100755
index 0000000..2347af8
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForJSONFormatter.java
@@ -0,0 +1,1000 @@
+/*
+ * 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 com.gemstone.gemfire.pdx;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.Set;
+import java.util.Stack;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+enum Day {
+ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
+}
+
+public class TestObjectForJSONFormatter implements PdxSerializable {
+
+ private boolean p_bool;
+ private byte p_byte;
+ private short p_short;
+ private int p_int;
+ private long p_long;
+ private float p_float;
+ private double p_double;
+
+ //wrapper
+ private Boolean w_bool;
+ private Byte w_byte;
+ private Short w_short;
+ private Integer w_int;
+ private Long w_long;
+ private BigInteger w_bigInt;
+ private Float w_float;
+ private BigDecimal w_bigDec;
+ private Double w_double;
+ private String w_string;
+
+ //Primitive_Arrays
+ private boolean[] p_boolArray;
+ private byte[] p_byteArray;
+ private short[] p_shortArray;
+ private int[] p_intArray;
+ private long[] p_longArray;
+ private float[] p_floatArray;
+ private double[] p_doubleArray;
+
+ //Wrapper_Arrays
+ private Boolean[] w_boolArray;
+ private Byte[] w_byteArray;
+ private Short[] w_shortArray;
+ private Integer[] w_intArray;
+ private Long[] w_longArray;
+ private BigInteger[] w_bigIntArray;
+ private Float[] w_floatArray;
+ private BigDecimal[] w_bigDecArray;
+ private Double[] w_doubleArray;
+ private String [] w_strArray;
+
+ //Collection Type: List, Set, Queue, Deque
+ private List<String> c_list;
+ private Set<Object> c_set;
+ private Queue<String> c_queue;
+ private Deque<Integer> c_deque;
+ private Stack<String> c_stack;
+
+ //Map - Classify Person objects by city
+ Map<String, List<Employee>> m_empByCity;
+
+ //Enum
+ private Day day;
+
+ private Employee employee;
+
+ public TestObjectForJSONFormatter(){
+ }
+
+ public String addClassTypeToJson(String json) throws JSONException {
+ JSONObject jsonObj = new JSONObject(json);
+ jsonObj.put("@type", "com.gemstone.gemfire.pdx.TestObjectForJSONFormatter");
+ return jsonObj.toString();
+ }
+
+ public void defaultInitialization(){
+
+ employee = new Employee(1010L, "NilkanthKumar", "Patel");
+
+ //Initialize Map type member
+ Employee e1 = new Employee(1L, "Nilkanth", "Patel");
+ Employee e2 = new Employee(2L, "Amey", "Barve");
+ Employee e3 = new Employee(3L, "Shankar", "Hundekar");
+ Employee e4 = new Employee(4L, "Avinash", "Dongre");
+ Employee e5 = new Employee(5L, "supriya", "Patil");
+ Employee e6 = new Employee(6L, "Rajesh", "Kumar");
+ Employee e7 = new Employee(7L, "Vishal", "Rao");
+ Employee e8 = new Employee(8L, "Hitesh", "Khamesara");
+ Employee e9 = new Employee(9L, "Sudhir", "Menon");
+
+ m_empByCity = new HashMap<String, List<Employee>>();
+ List<Employee> list1 = new ArrayList<Employee>();
+ List<Employee> list2 = new ArrayList<Employee>();
+ List<Employee> list3 = new ArrayList<Employee>();
+
+ list1.add(e1);
+ list1.add(e2);
+ list1.add(e3);
+
+ list2.add(e4);
+ list2.add(e5);
+ list2.add(e6);
+
+ list3.add(e7);
+ list3.add(e8);
+ list3.add(e9);
+
+ m_empByCity.put("Ahmedabad", list1);
+ m_empByCity.put("mumbai", list2);
+ m_empByCity.put("Pune", list3);
+
+
+ //Initialize Collection types members
+ c_list = new ArrayList<String>();
+ c_list.add("Java");
+ c_list.add("scala");
+ c_list.add("closure");
+
+ c_set = new HashSet<Object>();
+ c_set.add("element 0");
+ c_set.add("element 1");
+ c_set.add("element 2");
+
+ c_queue = new PriorityQueue<String>(3);
+ c_queue.add("short");
+ c_queue.add("very long indeed");
+ c_queue.add("medium");
+
+ c_deque = new ArrayDeque<Integer>(4);
+ c_deque.add(15);
+ c_deque.add(30);
+ c_deque.add(20);
+ c_deque.add(18);
+
+ c_stack = new Stack();
+ c_stack.push( "bat" );
+ c_stack.push( "cat" );
+ c_stack.push( "dog" );
+
+ //Initialize primitive types members
+ p_bool = true;
+ p_byte = 101;
+ p_short = 32001;
+ p_int = 100001;
+ p_long = 1234567898765432L;
+ p_float = 123.456f;
+ p_double = 98765.12345d;
+
+ //Wrapper type member initialization
+ w_bool = new Boolean(false);
+ w_byte = new Byte((byte)11);
+ w_short = new Short((short)101);
+ w_int = new Integer(1001);
+ w_long = new Long(987654321234567L);
+ w_bigInt = new BigInteger("12345678910");
+ w_float = new Float(789.456f);
+ w_bigDec = new BigDecimal(8866333);
+ w_double = new Double(123456.9876d);
+ w_string = new String("Nilkanth Patel");
+
+ //Initialization for members of type primitive arrays
+ p_boolArray = new boolean[]{ true, false, false};
+ p_byteArray = new byte[]{10, 11, 12};
+ p_shortArray = new short[]{101, 102, 103};
+ p_intArray = new int[]{1001,1002, 1003, 1004, 1005, 1006};
+ p_longArray = new long[]{ 12345678910L, 12345678911L, 12345678912L };
+ p_floatArray = new float[]{ 123.45f, 456.78f, -91011.123f};
+ p_doubleArray = new double[]{1234.5678d, -91011.1213d, 1415.1617d };
+
+ //Initialization for members of type wrapper arrays
+ w_boolArray = new Boolean[3];
+ w_byteArray = new Byte[3];
+ w_shortArray = new Short[3];
+ w_intArray = new Integer[3];
+ w_longArray = new Long[3];
+ w_floatArray = new Float[3];
+ w_doubleArray = new Double[3];
+ w_strArray = new String[3];
+
+ for (int i=0; i< 3; i++){
+ w_boolArray[i] = p_boolArray[i];
+ w_byteArray[i] = p_byteArray[i];
+ w_shortArray[i] = p_shortArray[i];
+ w_intArray[i] = p_intArray[i];
+ w_longArray[i] = p_longArray[i];
+ w_floatArray[i] = p_floatArray[i];
+ w_doubleArray[i] = p_doubleArray[i];
+ }
+
+ w_bigIntArray = new BigInteger[] {BigInteger.ZERO, BigInteger.ONE, new BigInteger("12345678910")};
+ w_bigDecArray = new BigDecimal[] {BigDecimal.TEN, new BigDecimal("143.145"), new BigDecimal("10.01")};
+ w_strArray = new String[]{"Nilkanth", "Vishal", "Hitesh"};
+
+ //Enum type initialization
+ day = Day.Thursday;
+ }
+
+ public TestObjectForJSONFormatter(boolean p_bool, byte p_byte, short p_short,
+ int p_int, long p_long, float p_float, double p_double, Boolean w_bool,
+ Byte w_byte, Short w_short, Integer w_int, Long w_long,
+ BigInteger w_bigInt, Float w_float, BigDecimal w_bigDec,
+ Double w_double, String w_string) {
+ super();
+ this.p_bool = p_bool;
+ this.p_byte = p_byte;
+ this.p_short = p_short;
+ this.p_int = p_int;
+ this.p_long = p_long;
+ this.p_float = p_float;
+ this.p_double = p_double;
+ this.w_bool = w_bool;
+ this.w_byte = w_byte;
+ this.w_short = w_short;
+ this.w_int = w_int;
+ this.w_long = w_long;
+ this.w_bigInt = w_bigInt;
+ this.w_float = w_float;
+ this.w_bigDec = w_bigDec;
+ this.w_double = w_double;
+ this.w_string = w_string;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+
+ public List<String> getC_list() {
+ return c_list;
+ }
+
+ public void setC_list(List<String> c_list) {
+ this.c_list = c_list;
+ }
+
+ public Set<Object> getC_set() {
+ return c_set;
+ }
+
+ public void setC_set(Set<Object> c_set) {
+ this.c_set = c_set;
+ }
+
+ public Queue<String> getC_queue() {
+ return c_queue;
+ }
+
+ public void setC_queue(Queue<String> c_queue) {
+ this.c_queue = c_queue;
+ }
+
+ public Deque<Integer> getC_deque() {
+ return c_deque;
+ }
+
+ public void setC_deque(Deque<Integer> c_deque) {
+ this.c_deque = c_deque;
+ }
+
+ public Map<String, List<Employee>> getM_empByCity() {
+ return m_empByCity;
+ }
+
+ public void setM_empByCity(Map<String, List<Employee>> m_empByCity) {
+ this.m_empByCity = m_empByCity;
+ }
+
+ public Day getDay() {
+ return day;
+ }
+
+ public void setDay(Day day) {
+ this.day = day;
+ }
+
+ public boolean isP_bool() {
+ return p_bool;
+ }
+
+ public void setP_bool(boolean p_bool) {
+ this.p_bool = p_bool;
+ }
+
+ public byte getP_byte() {
+ return p_byte;
+ }
+
+ public void setP_byte(byte p_byte) {
+ this.p_byte = p_byte;
+ }
+
+ public short getP_short() {
+ return p_short;
+ }
+
+ public void setP_short(short p_short) {
+ this.p_short = p_short;
+ }
+
+ public int getP_int() {
+ return p_int;
+ }
+
+ public void setP_int(int p_int) {
+ this.p_int = p_int;
+ }
+
+ public long getP_long() {
+ return p_long;
+ }
+
+ public void setP_long(long p_long) {
+ this.p_long = p_long;
+ }
+
+ public float getP_float() {
+ return p_float;
+ }
+
+ public void setP_float(float p_float) {
+ this.p_float = p_float;
+ }
+
+ public double getP_double() {
+ return p_double;
+ }
+
+ public void setP_double(double p_double) {
+ this.p_double = p_double;
+ }
+
+ public Boolean getW_bool() {
+ return w_bool;
+ }
+
+ public void setW_bool(Boolean w_bool) {
+ this.w_bool = w_bool;
+ }
+
+ public Byte getW_byte() {
+ return w_byte;
+ }
+
+ public void setW_byte(Byte w_byte) {
+ this.w_byte = w_byte;
+ }
+
+ public Short getW_short() {
+ return w_short;
+ }
+
+ public void setW_short(Short w_short) {
+ this.w_short = w_short;
+ }
+
+ public Integer getW_int() {
+ return w_int;
+ }
+
+ public void setW_int(Integer w_int) {
+ this.w_int = w_int;
+ }
+
+ public Long getW_long() {
+ return w_long;
+ }
+
+ public void setW_long(Long w_long) {
+ this.w_long = w_long;
+ }
+
+ public BigInteger getW_bigInt() {
+ return w_bigInt;
+ }
+
+ public void setW_bigInt(BigInteger w_bigInt) {
+ this.w_bigInt = w_bigInt;
+ }
+
+ public Float getW_float() {
+ return w_float;
+ }
+
+ public void setW_float(Float w_float) {
+ this.w_float = w_float;
+ }
+
+ public BigDecimal getW_bigDec() {
+ return w_bigDec;
+ }
+
+ public void setW_bigDec(BigDecimal w_bigDec) {
+ this.w_bigDec = w_bigDec;
+ }
+
+ public Double getW_double() {
+ return w_double;
+ }
+
+ public void setW_double(Double w_double) {
+ this.w_double = w_double;
+ }
+
+ public String getW_string() {
+ return w_string;
+ }
+
+ public void setW_string(String w_string) {
+ this.w_string = w_string;
+ }
+
+ public boolean[] getP_boolArray() {
+ return p_boolArray;
+ }
+
+ public void setP_boolArray(boolean[] p_boolArray) {
+ this.p_boolArray = p_boolArray;
+ }
+
+ public byte[] getP_byteArray() {
+ return p_byteArray;
+ }
+
+ public void setP_byteArray(byte[] p_byteArray) {
+ this.p_byteArray = p_byteArray;
+ }
+
+ public short[] getP_shortArray() {
+ return p_shortArray;
+ }
+
+ public void setP_shortArray(short[] p_shortArray) {
+ this.p_shortArray = p_shortArray;
+ }
+
+ public int[] getP_intArray() {
+ return p_intArray;
+ }
+
+ public void setP_intArray(int[] p_intArray) {
+ this.p_intArray = p_intArray;
+ }
+
+ public long[] getP_longArray() {
+ return p_longArray;
+ }
+
+ public void setP_longArray(long[] p_longArray) {
+ this.p_longArray = p_longArray;
+ }
+
+ public float[] getP_floatArray() {
+ return p_floatArray;
+ }
+
+ public void setP_floatArray(float[] p_floatArray) {
+ this.p_floatArray = p_floatArray;
+ }
+
+ public double[] getP_doubleArray() {
+ return p_doubleArray;
+ }
+
+ public void setP_doubleArray(double[] p_doubleArray) {
+ this.p_doubleArray = p_doubleArray;
+ }
+
+ public Boolean[] getW_boolArray() {
+ return w_boolArray;
+ }
+
+ public void setW_boolArray(Boolean[] w_boolArray) {
+ this.w_boolArray = w_boolArray;
+ }
+
+ public Byte[] getW_byteArray() {
+ return w_byteArray;
+ }
+
+ public void setW_byteArray(Byte[] w_byteArray) {
+ this.w_byteArray = w_byteArray;
+ }
+
+ public Short[] getW_shortArray() {
+ return w_shortArray;
+ }
+
+ public void setW_shortArray(Short[] w_shortArray) {
+ this.w_shortArray = w_shortArray;
+ }
+
+ public Integer[] getW_intArray() {
+ return w_intArray;
+ }
+
+ public void setW_intArray(Integer[] w_intArray) {
+ this.w_intArray = w_intArray;
+ }
+
+ public Long[] getW_longArray() {
+ return w_longArray;
+ }
+
+ public void setW_longArray(Long[] w_longArray) {
+ this.w_longArray = w_longArray;
+ }
+
+ public BigInteger[] getW_bigIntArray() {
+ return w_bigIntArray;
+ }
+
+ public void setW_bigIntArray(BigInteger[] w_bigIntArray) {
+ this.w_bigIntArray = w_bigIntArray;
+ }
+
+ public Float[] getW_floatArray() {
+ return w_floatArray;
+ }
+
+ public void setW_floatArray(Float[] w_floatArray) {
+ this.w_floatArray = w_floatArray;
+ }
+
+ public BigDecimal[] getW_bigDecArray() {
+ return w_bigDecArray;
+ }
+
+ public void setW_bigDecArray(BigDecimal[] w_bigDecArray) {
+ this.w_bigDecArray = w_bigDecArray;
+ }
+
+ public Double[] getW_doubleArray() {
+ return w_doubleArray;
+ }
+
+ public void setW_doubleArray(Double[] w_doubleArray) {
+ this.w_doubleArray = w_doubleArray;
+ }
+
+ public String[] getW_strArray() {
+ return w_strArray;
+ }
+
+ public void setW_strArray(String[] w_strArray) {
+ this.w_strArray = w_strArray;
+ }
+
+ public Stack<String> getC_stack() {
+ return c_stack;
+ }
+
+ public void setC_stack(Stack<String> c_stack) {
+ this.c_stack = c_stack;
+ }
+
+ // Getters for returning field names
+ public String getP_boolFN() {
+ return "p_bool";
+ }
+
+ public String getP_byteFN() {
+ return "p_byte";
+ }
+
+ public String getP_shortFN() {
+ return "p_short";
+ }
+
+ public String getP_intFN() {
+ return "p_int";
+ }
+
+ public String getP_longFN() {
+ return "p_long";
+ }
+
+ public String getP_floatFn() {
+ return "p_float";
+ }
+
+ public String getP_doubleFN() {
+ return "p_double";
+ }
+
+ public String getW_boolFN() {
+ return "w_bool";
+ }
+
+ public String getW_byteFN() {
+ return "w_byte";
+ }
+
+ public String getW_shortFN() {
+ return "w_short";
+ }
+
+ public String getW_intFN() {
+ return "w_int";
+ }
+
+ public String getW_longFN() {
+ return "w_long";
+ }
+
+ public String getW_bigIntFN() {
+ return "w_bigInt";
+ }
+
+ public String getW_floatFN() {
+ return "w_float";
+ }
+
+ public String getW_bigDecFN() {
+ return "w_bigDec";
+ }
+
+ public String getW_doubleFN() {
+ return "w_double";
+ }
+
+ public String getW_stringFN() {
+ return "w_string";
+ }
+
+ public String getP_boolArrayFN() {
+ return "p_boolArray";
+ }
+
+ public String getP_byteArrayFN() {
+ return "p_byteArray";
+ }
+
+ public String getP_shortArrayFN() {
+ return "p_shortArray";
+ }
+
+ public String getP_intArrayFN() {
+ return "p_intArray";
+ }
+
+ public String getP_longArrayFN() {
+ return "p_longArray";
+ }
+
+ public String getP_floatArrayFN() {
+ return "p_floatArray";
+ }
+
+ public String getP_doubleArrayFN() {
+ return "p_doubleArray";
+ }
+
+ public String getW_boolArrayFN() {
+ return "w_boolArray";
+ }
+
+ public String getW_byteArrayFN() {
+ return "w_byteArray";
+ }
+
+ public String getW_shortArrayFN() {
+ return "w_shortArray";
+ }
+
+ public String getW_intArrayFN() {
+ return "w_intArray";
+ }
+
+ public String getW_longArrayFN() {
+ return "w_longArray";
+ }
+
+ public String getW_bigIntArrayFN() {
+ return "w_bigIntArray";
+ }
+
+ public String getW_floatArrayFN() {
+ return "w_floatArray";
+ }
+
+ public String getW_bigDecArrayFN() {
+ return "w_bigDecArray";
+ }
+
+ public String getW_doubleArrayFN() {
+ return "w_doubleArray";
+ }
+
+ public String getW_strArrayFN() {
+ return "w_strArray";
+ }
+
+ public String getC_listFN() {
+ return "c_list";
+ }
+
+ public String getC_setFN() {
+ return "c_set";
+ }
+
+ public String getC_queueFN() {
+ return "c_queue";
+ }
+
+ public String getC_dequeFN() {
+ return "c_deque";
+ }
+
+ public String getC_stackFN() {
+ return "c_stack";
+ }
+
+ public String getM_empByCityFN() {
+ return "m_empByCity";
+ }
+
+ public String getDayFN() {
+ return "day";
+ }
+
+ @Override
+ public void fromData(PdxReader in) {
+ this.p_bool = in.readBoolean("p_bool");
+ this.p_byte = in.readByte("p_byte");
+ this.p_short = in.readShort("p_short");
+ this.p_int = in.readInt("p_int");
+ this.p_long = in.readLong("p_long");
+ this.p_float = in.readFloat("p_float");
+ this.p_double = in.readDouble("p_double");
+ this.w_bool = in.readBoolean("w_bool");
+ this.w_byte = in.readByte("w_byte");
+ this.w_short = in.readShort("w_short");
+ this.w_int = in.readInt("w_int");
+ this.w_long = in.readLong("w_long");
+ this.w_float = in.readFloat("w_float");
+ this.w_double = in.readDouble("w_double");
+ this.w_string = in.readString("w_string");
+ this.w_bigInt = (BigInteger) in.readObject("w_bigInt");
+ this.w_bigDec = (BigDecimal) in.readObject("w_bigDec");
+
+ // P_Arrays
+ this.p_boolArray = in.readBooleanArray("p_boolArray");
+ this.p_byteArray = in.readByteArray("p_byteArray");
+ this.p_shortArray = in.readShortArray("p_shortArray");
+ this.p_intArray = in.readIntArray("p_intArray");
+ this.p_longArray = in.readLongArray("p_longArray");
+ this.p_floatArray = in.readFloatArray("p_floatArray");
+ this.p_doubleArray = in.readDoubleArray("p_doubleArray");
+
+ // W_Arrays
+ this.w_boolArray = (Boolean[]) in.readObjectArray("w_boolArray");
+ this.w_byteArray = (Byte[]) in.readObjectArray("w_byteArray");
+ this.w_shortArray = (Short[]) in.readObjectArray("w_shortArray");
+ this.w_intArray = (Integer[]) in.readObjectArray("w_intArray");
+ this.w_longArray = (Long[]) in.readObjectArray("w_longArray");
+ this.w_floatArray = (Float[]) in.readObjectArray("w_floatArray");
+ this.w_doubleArray = (Double[]) in.readObjectArray("w_doubleArray");
+ this.w_strArray = in.readStringArray("w_strArray");
+ this.w_bigIntArray = (BigInteger[]) in.readObjectArray("w_bigIntArray");
+ this.w_bigDecArray = (BigDecimal[]) in.readObjectArray("w_bigDecArray");
+
+ // Collections
+ this.c_list = (List<String>) in.readObject("c_list");
+ this.c_set = (Set<Object>) in.readObject("c_set");
+ this.c_queue = (Queue<String>) in.readObject("c_queue");
+ this.c_deque = (Deque<Integer>) in.readObject("c_deque");
+ this.c_stack = (Stack<String>) in.readObject("c_stack");
+
+ // Map
+ this.m_empByCity = (Map<String, List<Employee>>) in.readObject("m_empByCity");
+
+ // Enum
+ this.day = (Day) (in.readObject("day"));
+
+ //User Object
+ this.employee = (Employee) in.readObject("employee");
+ //String type= in.readString("@type");
+ }
+
+ @Override
+ public void toData(PdxWriter out) {
+ //if(m_unreadFields != null){ out.writeUnreadFields(m_unreadFields); }
+ out.writeBoolean("p_bool", this.p_bool);
+ out.writeByte("p_byte", this.p_byte);
+ out.writeShort("p_short", p_short);
+ out.writeInt("p_int", p_int);
+ out.writeLong("p_long", p_long);
+ out.writeFloat("p_float", p_float);
+ out.writeDouble("p_double", p_double);
+ out.writeBoolean("w_bool", w_bool);
+ out.writeByte("w_byte", w_byte);
+ out.writeShort("w_short", w_short);
+ out.writeInt("w_int", w_int);
+ out.writeLong("w_long", w_long);
+ out.writeFloat("w_float", w_float);
+ out.writeDouble("w_double", w_double);
+ out.writeString("w_string", w_string);
+ out.writeObject("w_bigInt", w_bigInt);
+ out.writeObject("w_bigDec", w_bigDec);
+
+ // P_Arrays
+ out.writeBooleanArray("p_boolArray", p_boolArray);
+ out.writeByteArray("p_byteArray", p_byteArray);
+ out.writeShortArray("p_shortArray", p_shortArray);
+ out.writeIntArray("p_intArray", p_intArray);
+ out.writeLongArray("p_longArray", p_longArray);
+ out.writeFloatArray("p_floatArray", p_floatArray);
+ out.writeDoubleArray("p_doubleArray", p_doubleArray);
+
+ // W_Arrays
+ out.writeObjectArray("w_boolArray", w_boolArray);
+ out.writeObjectArray("w_byteArray", w_byteArray);
+ out.writeObjectArray("w_shortArray", w_shortArray);
+ out.writeObjectArray("w_intArray", w_intArray);
+ out.writeObjectArray("w_longArray", w_longArray);
+ out.writeObjectArray("w_floatArray", w_floatArray);
+ out.writeObjectArray("w_doubleArray", w_doubleArray);
+ out.writeStringArray("w_strArray", w_strArray);
+ out.writeObjectArray("w_bigIntArray", w_bigIntArray);
+ out.writeObjectArray("w_bigDecArray", w_bigDecArray);
+
+ // Collections
+ out.writeObject("c_list", c_list);
+ out.writeObject("c_set", c_set);
+ out.writeObject("c_queue", c_queue);
+ out.writeObject("c_deque", c_deque);
+ out.writeObject("c_stack", c_stack);
+
+ // Map
+ out.writeObject("m_empByCity", m_empByCity);
+
+ // Enum
+ out.writeObject("day", day);
+
+ out.writeObject("employee", this.employee);
+ //out.writeString("@type", "com.gemstone.gemfire.pdx.TestObjectForJSONFormatter");
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ TestObjectForJSONFormatter other = (TestObjectForJSONFormatter) obj;
+
+ // primitive type
+ if (p_bool != other.p_bool)
+ return false;
+ if (p_byte != other.p_byte)
+ return false;
+ if (p_short != other.p_short)
+ return false;
+ if (p_int != other.p_int)
+ return false;
+ if (p_long != other.p_long)
+ return false;
+ if (p_float != other.p_float)
+ return false;
+ if (p_double != other.p_double)
+ return false;
+
+ // wrapper type
+ if (w_bool.booleanValue() != other.w_bool.booleanValue())
+ return false;
+ if (w_byte.byteValue() != other.w_byte.byteValue())
+ return false;
+ if (w_short.shortValue() != other.w_short.shortValue())
+ return false;
+ if (w_int.intValue() != other.w_int.intValue())
+ return false;
+ if (w_long.longValue() != other.w_long.longValue())
+ return false;
+ if (w_float.floatValue() != other.w_float.floatValue())
+ return false;
+ if (w_double.doubleValue() != other.w_double.doubleValue())
+ return false;
+ if (!w_string.equals(other.w_string))
+ return false;
+ if (w_bigInt.longValue() != other.w_bigInt.longValue())
+ return false;
+ if (w_bigDec.longValue() != other.w_bigDec.longValue())
+ return false;
+
+ // Primitive arrays
+ if (!Arrays.equals(p_boolArray, other.p_boolArray))
+ return false;
+ if (!Arrays.equals(p_byteArray, other.p_byteArray))
+ return false;
+ if (!Arrays.equals(p_shortArray, other.p_shortArray))
+ return false;
+ if (!Arrays.equals(p_intArray, other.p_intArray))
+ return false;
+ if (!Arrays.equals(p_longArray, other.p_longArray))
+ return false;
+ if (!Arrays.equals(p_floatArray, other.p_floatArray))
+ return false;
+ if (!Arrays.equals(p_doubleArray, other.p_doubleArray))
+ return false;
+
+ // wrapper Arrays
+ if (!Arrays.equals(w_boolArray, other.w_boolArray))
+ return false;
+ if (!Arrays.equals(w_byteArray, other.w_byteArray))
+ return false;
+ if (!Arrays.equals(w_shortArray, other.w_shortArray))
+ return false;
+ if (!Arrays.equals(w_intArray, other.w_intArray))
+ return false;
+ if (!Arrays.equals(w_longArray, other.w_longArray))
+ return false;
+ if (!Arrays.equals(w_floatArray, other.w_floatArray))
+ return false;
+ if (!Arrays.equals(w_doubleArray, other.w_doubleArray))
+ return false;
+ if (!Arrays.equals(w_strArray, other.w_strArray))
+ return false;
+ if (!Arrays.equals(w_bigIntArray, other.w_bigIntArray))
+ return false;
+ if (!Arrays.equals(w_bigDecArray, other.w_bigDecArray))
+ return false;
+
+ // comparing Collections based on content, order not considered
+ if (!(c_list.size() == other.c_list.size()
+ && c_list.containsAll(other.c_list)
+ && other.c_list.containsAll(c_list)))
+ return false;
+ if (!(c_set.size() == other.c_set.size()
+ && c_set.containsAll(other.c_set)
+ && other.c_set.containsAll(c_set)))
+ return false;
+ if (!(c_queue.size() == other.c_queue.size()
+ && c_queue.containsAll(other.c_queue)
+ && other.c_queue.containsAll(c_queue)))
+ return false;
+ if (!(c_deque.size() == other.c_deque.size()
+ && c_deque.containsAll(other.c_deque)
+ && other.c_deque.containsAll(c_deque)))
+ return false;
+
+ // map comparision.
+ if (!(compareMaps(m_empByCity, other.m_empByCity)))
+ return false;
+
+ // Enum validation
+ if (!(day.equals(other.day)))
+ return false;
+
+ return true;
+ }
+
+ boolean compareMaps(Map m1, Map m2) {
+ if (m1.size() != m2.size())
+ return false;
+ for (Object key : m1.keySet())
+ if (!m1.get(key).equals(m2.get(key)))
+ return false;
+ return true;
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d23a695/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForPdxFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForPdxFormatter.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForPdxFormatter.java
deleted file mode 100644
index 462a572..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/TestObjectForPdxFormatter.java
+++ /dev/null
@@ -1,1003 +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 com.gemstone.gemfire.pdx;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.PriorityQueue;
-import java.util.Queue;
-import java.util.Set;
-import java.util.Stack;
-
-import com.gemstone.gemfire.pdx.PdxReader;
-import com.gemstone.gemfire.pdx.PdxSerializable;
-import com.gemstone.gemfire.pdx.PdxWriter;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-enum Day {
- Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
-}
-
-public class TestObjectForPdxFormatter implements PdxSerializable {
-
- private boolean p_bool;
- private byte p_byte;
- private short p_short;
- private int p_int;
- private long p_long;
- private float p_float;
- private double p_double;
-
- //wrapper
- private Boolean w_bool;
- private Byte w_byte;
- private Short w_short;
- private Integer w_int;
- private Long w_long;
- private BigInteger w_bigInt;
- private Float w_float;
- private BigDecimal w_bigDec;
- private Double w_double;
- private String w_string;
-
- //Primitive_Arrays
- private boolean[] p_boolArray;
- private byte[] p_byteArray;
- private short[] p_shortArray;
- private int[] p_intArray;
- private long[] p_longArray;
- private float[] p_floatArray;
- private double[] p_doubleArray;
-
- //Wrapper_Arrays
- private Boolean[] w_boolArray;
- private Byte[] w_byteArray;
- private Short[] w_shortArray;
- private Integer[] w_intArray;
- private Long[] w_longArray;
- private BigInteger[] w_bigIntArray;
- private Float[] w_floatArray;
- private BigDecimal[] w_bigDecArray;
- private Double[] w_doubleArray;
- private String [] w_strArray;
-
- //Collection Type: List, Set, Queue, Deque
- private List<String> c_list;
- private Set<Object> c_set;
- private Queue<String> c_queue;
- private Deque<Integer> c_deque;
- private Stack<String> c_stack;
-
- //Map - Classify Person objects by city
- Map<String, List<Employee>> m_empByCity;
-
- //Enum
- private Day day;
-
- private Employee employee;
-
- public TestObjectForPdxFormatter(){
- }
-
- public String addClassTypeToJson(String json) throws JSONException {
- JSONObject jsonObj = new JSONObject(json);
- jsonObj.put("@type", "com.gemstone.gemfire.pdx.TestObjectForPdxFormatter");
- return jsonObj.toString();
- }
-
- public void defaultInitialization(){
-
- employee = new Employee(1010L, "NilkanthKumar", "Patel");
-
- //Initialize Map type member
- Employee e1 = new Employee(1L, "Nilkanth", "Patel");
- Employee e2 = new Employee(2L, "Amey", "Barve");
- Employee e3 = new Employee(3L, "Shankar", "Hundekar");
- Employee e4 = new Employee(4L, "Avinash", "Dongre");
- Employee e5 = new Employee(5L, "supriya", "Patil");
- Employee e6 = new Employee(6L, "Rajesh", "Kumar");
- Employee e7 = new Employee(7L, "Vishal", "Rao");
- Employee e8 = new Employee(8L, "Hitesh", "Khamesara");
- Employee e9 = new Employee(9L, "Sudhir", "Menon");
-
- m_empByCity = new HashMap<String, List<Employee>>();
- List<Employee> list1 = new ArrayList<Employee>();
- List<Employee> list2 = new ArrayList<Employee>();
- List<Employee> list3 = new ArrayList<Employee>();
-
- list1.add(e1);
- list1.add(e2);
- list1.add(e3);
-
- list2.add(e4);
- list2.add(e5);
- list2.add(e6);
-
- list3.add(e7);
- list3.add(e8);
- list3.add(e9);
-
- m_empByCity.put("Ahmedabad", list1);
- m_empByCity.put("mumbai", list2);
- m_empByCity.put("Pune", list3);
-
-
- //Initialize Collection types members
- c_list = new ArrayList<String>();
- c_list.add("Java");
- c_list.add("scala");
- c_list.add("closure");
-
- c_set = new HashSet<Object>();
- c_set.add("element 0");
- c_set.add("element 1");
- c_set.add("element 2");
-
- c_queue = new PriorityQueue<String>(3);
- c_queue.add("short");
- c_queue.add("very long indeed");
- c_queue.add("medium");
-
- c_deque = new ArrayDeque<Integer>(4);
- c_deque.add(15);
- c_deque.add(30);
- c_deque.add(20);
- c_deque.add(18);
-
- c_stack = new Stack();
- c_stack.push( "bat" );
- c_stack.push( "cat" );
- c_stack.push( "dog" );
-
- //Initialize primitive types members
- p_bool = true;
- p_byte = 101;
- p_short = 32001;
- p_int = 100001;
- p_long = 1234567898765432L;
- p_float = 123.456f;
- p_double = 98765.12345d;
-
- //Wrapper type member initialization
- w_bool = new Boolean(false);
- w_byte = new Byte((byte)11);
- w_short = new Short((short)101);
- w_int = new Integer(1001);
- w_long = new Long(987654321234567L);
- w_bigInt = new BigInteger("12345678910");
- w_float = new Float(789.456f);
- w_bigDec = new BigDecimal(8866333);
- w_double = new Double(123456.9876d);
- w_string = new String("Nilkanth Patel");
-
- //Initialization for members of type primitive arrays
- p_boolArray = new boolean[]{ true, false, false};
- p_byteArray = new byte[]{10, 11, 12};
- p_shortArray = new short[]{101, 102, 103};
- p_intArray = new int[]{1001,1002, 1003, 1004, 1005, 1006};
- p_longArray = new long[]{ 12345678910L, 12345678911L, 12345678912L };
- p_floatArray = new float[]{ 123.45f, 456.78f, -91011.123f};
- p_doubleArray = new double[]{1234.5678d, -91011.1213d, 1415.1617d };
-
- //Initialization for members of type wrapper arrays
- w_boolArray = new Boolean[3];
- w_byteArray = new Byte[3];
- w_shortArray = new Short[3];
- w_intArray = new Integer[3];
- w_longArray = new Long[3];
- w_floatArray = new Float[3];
- w_doubleArray = new Double[3];
- w_strArray = new String[3];
-
- for (int i=0; i< 3; i++){
- w_boolArray[i] = p_boolArray[i];
- w_byteArray[i] = p_byteArray[i];
- w_shortArray[i] = p_shortArray[i];
- w_intArray[i] = p_intArray[i];
- w_longArray[i] = p_longArray[i];
- w_floatArray[i] = p_floatArray[i];
- w_doubleArray[i] = p_doubleArray[i];
- }
-
- w_bigIntArray = new BigInteger[] {BigInteger.ZERO, BigInteger.ONE, new BigInteger("12345678910")};
- w_bigDecArray = new BigDecimal[] {BigDecimal.TEN, new BigDecimal("143.145"), new BigDecimal("10.01")};
- w_strArray = new String[]{"Nilkanth", "Vishal", "Hitesh"};
-
- //Enum type initialization
- day = Day.Thursday;
- }
-
- public TestObjectForPdxFormatter(boolean p_bool, byte p_byte, short p_short,
- int p_int, long p_long, float p_float, double p_double, Boolean w_bool,
- Byte w_byte, Short w_short, Integer w_int, Long w_long,
- BigInteger w_bigInt, Float w_float, BigDecimal w_bigDec,
- Double w_double, String w_string) {
- super();
- this.p_bool = p_bool;
- this.p_byte = p_byte;
- this.p_short = p_short;
- this.p_int = p_int;
- this.p_long = p_long;
- this.p_float = p_float;
- this.p_double = p_double;
- this.w_bool = w_bool;
- this.w_byte = w_byte;
- this.w_short = w_short;
- this.w_int = w_int;
- this.w_long = w_long;
- this.w_bigInt = w_bigInt;
- this.w_float = w_float;
- this.w_bigDec = w_bigDec;
- this.w_double = w_double;
- this.w_string = w_string;
- }
-
- public Employee getEmployee() {
- return employee;
- }
-
- public void setEmployee(Employee employee) {
- this.employee = employee;
- }
-
- public List<String> getC_list() {
- return c_list;
- }
-
- public void setC_list(List<String> c_list) {
- this.c_list = c_list;
- }
-
- public Set<Object> getC_set() {
- return c_set;
- }
-
- public void setC_set(Set<Object> c_set) {
- this.c_set = c_set;
- }
-
- public Queue<String> getC_queue() {
- return c_queue;
- }
-
- public void setC_queue(Queue<String> c_queue) {
- this.c_queue = c_queue;
- }
-
- public Deque<Integer> getC_deque() {
- return c_deque;
- }
-
- public void setC_deque(Deque<Integer> c_deque) {
- this.c_deque = c_deque;
- }
-
- public Map<String, List<Employee>> getM_empByCity() {
- return m_empByCity;
- }
-
- public void setM_empByCity(Map<String, List<Employee>> m_empByCity) {
- this.m_empByCity = m_empByCity;
- }
-
- public Day getDay() {
- return day;
- }
-
- public void setDay(Day day) {
- this.day = day;
- }
-
- public boolean isP_bool() {
- return p_bool;
- }
-
- public void setP_bool(boolean p_bool) {
- this.p_bool = p_bool;
- }
-
- public byte getP_byte() {
- return p_byte;
- }
-
- public void setP_byte(byte p_byte) {
- this.p_byte = p_byte;
- }
-
- public short getP_short() {
- return p_short;
- }
-
- public void setP_short(short p_short) {
- this.p_short = p_short;
- }
-
- public int getP_int() {
- return p_int;
- }
-
- public void setP_int(int p_int) {
- this.p_int = p_int;
- }
-
- public long getP_long() {
- return p_long;
- }
-
- public void setP_long(long p_long) {
- this.p_long = p_long;
- }
-
- public float getP_float() {
- return p_float;
- }
-
- public void setP_float(float p_float) {
- this.p_float = p_float;
- }
-
- public double getP_double() {
- return p_double;
- }
-
- public void setP_double(double p_double) {
- this.p_double = p_double;
- }
-
- public Boolean getW_bool() {
- return w_bool;
- }
-
- public void setW_bool(Boolean w_bool) {
- this.w_bool = w_bool;
- }
-
- public Byte getW_byte() {
- return w_byte;
- }
-
- public void setW_byte(Byte w_byte) {
- this.w_byte = w_byte;
- }
-
- public Short getW_short() {
- return w_short;
- }
-
- public void setW_short(Short w_short) {
- this.w_short = w_short;
- }
-
- public Integer getW_int() {
- return w_int;
- }
-
- public void setW_int(Integer w_int) {
- this.w_int = w_int;
- }
-
- public Long getW_long() {
- return w_long;
- }
-
- public void setW_long(Long w_long) {
- this.w_long = w_long;
- }
-
- public BigInteger getW_bigInt() {
- return w_bigInt;
- }
-
- public void setW_bigInt(BigInteger w_bigInt) {
- this.w_bigInt = w_bigInt;
- }
-
- public Float getW_float() {
- return w_float;
- }
-
- public void setW_float(Float w_float) {
- this.w_float = w_float;
- }
-
- public BigDecimal getW_bigDec() {
- return w_bigDec;
- }
-
- public void setW_bigDec(BigDecimal w_bigDec) {
- this.w_bigDec = w_bigDec;
- }
-
- public Double getW_double() {
- return w_double;
- }
-
- public void setW_double(Double w_double) {
- this.w_double = w_double;
- }
-
- public String getW_string() {
- return w_string;
- }
-
- public void setW_string(String w_string) {
- this.w_string = w_string;
- }
-
- public boolean[] getP_boolArray() {
- return p_boolArray;
- }
-
- public void setP_boolArray(boolean[] p_boolArray) {
- this.p_boolArray = p_boolArray;
- }
-
- public byte[] getP_byteArray() {
- return p_byteArray;
- }
-
- public void setP_byteArray(byte[] p_byteArray) {
- this.p_byteArray = p_byteArray;
- }
-
- public short[] getP_shortArray() {
- return p_shortArray;
- }
-
- public void setP_shortArray(short[] p_shortArray) {
- this.p_shortArray = p_shortArray;
- }
-
- public int[] getP_intArray() {
- return p_intArray;
- }
-
- public void setP_intArray(int[] p_intArray) {
- this.p_intArray = p_intArray;
- }
-
- public long[] getP_longArray() {
- return p_longArray;
- }
-
- public void setP_longArray(long[] p_longArray) {
- this.p_longArray = p_longArray;
- }
-
- public float[] getP_floatArray() {
- return p_floatArray;
- }
-
- public void setP_floatArray(float[] p_floatArray) {
- this.p_floatArray = p_floatArray;
- }
-
- public double[] getP_doubleArray() {
- return p_doubleArray;
- }
-
- public void setP_doubleArray(double[] p_doubleArray) {
- this.p_doubleArray = p_doubleArray;
- }
-
- public Boolean[] getW_boolArray() {
- return w_boolArray;
- }
-
- public void setW_boolArray(Boolean[] w_boolArray) {
- this.w_boolArray = w_boolArray;
- }
-
- public Byte[] getW_byteArray() {
- return w_byteArray;
- }
-
- public void setW_byteArray(Byte[] w_byteArray) {
- this.w_byteArray = w_byteArray;
- }
-
- public Short[] getW_shortArray() {
- return w_shortArray;
- }
-
- public void setW_shortArray(Short[] w_shortArray) {
- this.w_shortArray = w_shortArray;
- }
-
- public Integer[] getW_intArray() {
- return w_intArray;
- }
-
- public void setW_intArray(Integer[] w_intArray) {
- this.w_intArray = w_intArray;
- }
-
- public Long[] getW_longArray() {
- return w_longArray;
- }
-
- public void setW_longArray(Long[] w_longArray) {
- this.w_longArray = w_longArray;
- }
-
- public BigInteger[] getW_bigIntArray() {
- return w_bigIntArray;
- }
-
- public void setW_bigIntArray(BigInteger[] w_bigIntArray) {
- this.w_bigIntArray = w_bigIntArray;
- }
-
- public Float[] getW_floatArray() {
- return w_floatArray;
- }
-
- public void setW_floatArray(Float[] w_floatArray) {
- this.w_floatArray = w_floatArray;
- }
-
- public BigDecimal[] getW_bigDecArray() {
- return w_bigDecArray;
- }
-
- public void setW_bigDecArray(BigDecimal[] w_bigDecArray) {
- this.w_bigDecArray = w_bigDecArray;
- }
-
- public Double[] getW_doubleArray() {
- return w_doubleArray;
- }
-
- public void setW_doubleArray(Double[] w_doubleArray) {
- this.w_doubleArray = w_doubleArray;
- }
-
- public String[] getW_strArray() {
- return w_strArray;
- }
-
- public void setW_strArray(String[] w_strArray) {
- this.w_strArray = w_strArray;
- }
-
- public Stack<String> getC_stack() {
- return c_stack;
- }
-
- public void setC_stack(Stack<String> c_stack) {
- this.c_stack = c_stack;
- }
-
- // Getters for returning field names
- public String getP_boolFN() {
- return "p_bool";
- }
-
- public String getP_byteFN() {
- return "p_byte";
- }
-
- public String getP_shortFN() {
- return "p_short";
- }
-
- public String getP_intFN() {
- return "p_int";
- }
-
- public String getP_longFN() {
- return "p_long";
- }
-
- public String getP_floatFn() {
- return "p_float";
- }
-
- public String getP_doubleFN() {
- return "p_double";
- }
-
- public String getW_boolFN() {
- return "w_bool";
- }
-
- public String getW_byteFN() {
- return "w_byte";
- }
-
- public String getW_shortFN() {
- return "w_short";
- }
-
- public String getW_intFN() {
- return "w_int";
- }
-
- public String getW_longFN() {
- return "w_long";
- }
-
- public String getW_bigIntFN() {
- return "w_bigInt";
- }
-
- public String getW_floatFN() {
- return "w_float";
- }
-
- public String getW_bigDecFN() {
- return "w_bigDec";
- }
-
- public String getW_doubleFN() {
- return "w_double";
- }
-
- public String getW_stringFN() {
- return "w_string";
- }
-
- public String getP_boolArrayFN() {
- return "p_boolArray";
- }
-
- public String getP_byteArrayFN() {
- return "p_byteArray";
- }
-
- public String getP_shortArrayFN() {
- return "p_shortArray";
- }
-
- public String getP_intArrayFN() {
- return "p_intArray";
- }
-
- public String getP_longArrayFN() {
- return "p_longArray";
- }
-
- public String getP_floatArrayFN() {
- return "p_floatArray";
- }
-
- public String getP_doubleArrayFN() {
- return "p_doubleArray";
- }
-
- public String getW_boolArrayFN() {
- return "w_boolArray";
- }
-
- public String getW_byteArrayFN() {
- return "w_byteArray";
- }
-
- public String getW_shortArrayFN() {
- return "w_shortArray";
- }
-
- public String getW_intArrayFN() {
- return "w_intArray";
- }
-
- public String getW_longArrayFN() {
- return "w_longArray";
- }
-
- public String getW_bigIntArrayFN() {
- return "w_bigIntArray";
- }
-
- public String getW_floatArrayFN() {
- return "w_floatArray";
- }
-
- public String getW_bigDecArrayFN() {
- return "w_bigDecArray";
- }
-
- public String getW_doubleArrayFN() {
- return "w_doubleArray";
- }
-
- public String getW_strArrayFN() {
- return "w_strArray";
- }
-
- public String getC_listFN() {
- return "c_list";
- }
-
- public String getC_setFN() {
- return "c_set";
- }
-
- public String getC_queueFN() {
- return "c_queue";
- }
-
- public String getC_dequeFN() {
- return "c_deque";
- }
-
- public String getC_stackFN() {
- return "c_stack";
- }
-
- public String getM_empByCityFN() {
- return "m_empByCity";
- }
-
- public String getDayFN() {
- return "day";
- }
-
- @Override
- public void fromData(PdxReader in) {
- this.p_bool = in.readBoolean("p_bool");
- this.p_byte = in.readByte("p_byte");
- this.p_short = in.readShort("p_short");
- this.p_int = in.readInt("p_int");
- this.p_long = in.readLong("p_long");
- this.p_float = in.readFloat("p_float");
- this.p_double = in.readDouble("p_double");
- this.w_bool = in.readBoolean("w_bool");
- this.w_byte = in.readByte("w_byte");
- this.w_short = in.readShort("w_short");
- this.w_int = in.readInt("w_int");
- this.w_long = in.readLong("w_long");
- this.w_float = in.readFloat("w_float");
- this.w_double = in.readDouble("w_double");
- this.w_string = in.readString("w_string");
- this.w_bigInt = (BigInteger) in.readObject("w_bigInt");
- this.w_bigDec = (BigDecimal) in.readObject("w_bigDec");
-
- // P_Arrays
- this.p_boolArray = in.readBooleanArray("p_boolArray");
- this.p_byteArray = in.readByteArray("p_byteArray");
- this.p_shortArray = in.readShortArray("p_shortArray");
- this.p_intArray = in.readIntArray("p_intArray");
- this.p_longArray = in.readLongArray("p_longArray");
- this.p_floatArray = in.readFloatArray("p_floatArray");
- this.p_doubleArray = in.readDoubleArray("p_doubleArray");
-
- // W_Arrays
- this.w_boolArray = (Boolean[]) in.readObjectArray("w_boolArray");
- this.w_byteArray = (Byte[]) in.readObjectArray("w_byteArray");
- this.w_shortArray = (Short[]) in.readObjectArray("w_shortArray");
- this.w_intArray = (Integer[]) in.readObjectArray("w_intArray");
- this.w_longArray = (Long[]) in.readObjectArray("w_longArray");
- this.w_floatArray = (Float[]) in.readObjectArray("w_floatArray");
- this.w_doubleArray = (Double[]) in.readObjectArray("w_doubleArray");
- this.w_strArray = in.readStringArray("w_strArray");
- this.w_bigIntArray = (BigInteger[]) in.readObjectArray("w_bigIntArray");
- this.w_bigDecArray = (BigDecimal[]) in.readObjectArray("w_bigDecArray");
-
- // Collections
- this.c_list = (List<String>) in.readObject("c_list");
- this.c_set = (Set<Object>) in.readObject("c_set");
- this.c_queue = (Queue<String>) in.readObject("c_queue");
- this.c_deque = (Deque<Integer>) in.readObject("c_deque");
- this.c_stack = (Stack<String>) in.readObject("c_stack");
-
- // Map
- this.m_empByCity = (Map<String, List<Employee>>) in.readObject("m_empByCity");
-
- // Enum
- this.day = (Day) (in.readObject("day"));
-
- //User Object
- this.employee = (Employee) in.readObject("employee");
- //String type= in.readString("@type");
- }
-
- @Override
- public void toData(PdxWriter out) {
- //if(m_unreadFields != null){ out.writeUnreadFields(m_unreadFields); }
- out.writeBoolean("p_bool", this.p_bool);
- out.writeByte("p_byte", this.p_byte);
- out.writeShort("p_short", p_short);
- out.writeInt("p_int", p_int);
- out.writeLong("p_long", p_long);
- out.writeFloat("p_float", p_float);
- out.writeDouble("p_double", p_double);
- out.writeBoolean("w_bool", w_bool);
- out.writeByte("w_byte", w_byte);
- out.writeShort("w_short", w_short);
- out.writeInt("w_int", w_int);
- out.writeLong("w_long", w_long);
- out.writeFloat("w_float", w_float);
- out.writeDouble("w_double", w_double);
- out.writeString("w_string", w_string);
- out.writeObject("w_bigInt", w_bigInt);
- out.writeObject("w_bigDec", w_bigDec);
-
- // P_Arrays
- out.writeBooleanArray("p_boolArray", p_boolArray);
- out.writeByteArray("p_byteArray", p_byteArray);
- out.writeShortArray("p_shortArray", p_shortArray);
- out.writeIntArray("p_intArray", p_intArray);
- out.writeLongArray("p_longArray", p_longArray);
- out.writeFloatArray("p_floatArray", p_floatArray);
- out.writeDoubleArray("p_doubleArray", p_doubleArray);
-
- // W_Arrays
- out.writeObjectArray("w_boolArray", w_boolArray);
- out.writeObjectArray("w_byteArray", w_byteArray);
- out.writeObjectArray("w_shortArray", w_shortArray);
- out.writeObjectArray("w_intArray", w_intArray);
- out.writeObjectArray("w_longArray", w_longArray);
- out.writeObjectArray("w_floatArray", w_floatArray);
- out.writeObjectArray("w_doubleArray", w_doubleArray);
- out.writeStringArray("w_strArray", w_strArray);
- out.writeObjectArray("w_bigIntArray", w_bigIntArray);
- out.writeObjectArray("w_bigDecArray", w_bigDecArray);
-
- // Collections
- out.writeObject("c_list", c_list);
- out.writeObject("c_set", c_set);
- out.writeObject("c_queue", c_queue);
- out.writeObject("c_deque", c_deque);
- out.writeObject("c_stack", c_stack);
-
- // Map
- out.writeObject("m_empByCity", m_empByCity);
-
- // Enum
- out.writeObject("day", day);
-
- out.writeObject("employee", this.employee);
- //out.writeString("@type", "com.gemstone.gemfire.pdx.TestObjectForPdxFormatter");
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
-
- TestObjectForPdxFormatter other = (TestObjectForPdxFormatter) obj;
-
- // primitive type
- if (p_bool != other.p_bool)
- return false;
- if (p_byte != other.p_byte)
- return false;
- if (p_short != other.p_short)
- return false;
- if (p_int != other.p_int)
- return false;
- if (p_long != other.p_long)
- return false;
- if (p_float != other.p_float)
- return false;
- if (p_double != other.p_double)
- return false;
-
- // wrapper type
- if (w_bool.booleanValue() != other.w_bool.booleanValue())
- return false;
- if (w_byte.byteValue() != other.w_byte.byteValue())
- return false;
- if (w_short.shortValue() != other.w_short.shortValue())
- return false;
- if (w_int.intValue() != other.w_int.intValue())
- return false;
- if (w_long.longValue() != other.w_long.longValue())
- return false;
- if (w_float.floatValue() != other.w_float.floatValue())
- return false;
- if (w_double.doubleValue() != other.w_double.doubleValue())
- return false;
- if (!w_string.equals(other.w_string))
- return false;
- if (w_bigInt.longValue() != other.w_bigInt.longValue())
- return false;
- if (w_bigDec.longValue() != other.w_bigDec.longValue())
- return false;
-
- // Primitive arrays
- if (!Arrays.equals(p_boolArray, other.p_boolArray))
- return false;
- if (!Arrays.equals(p_byteArray, other.p_byteArray))
- return false;
- if (!Arrays.equals(p_shortArray, other.p_shortArray))
- return false;
- if (!Arrays.equals(p_intArray, other.p_intArray))
- return false;
- if (!Arrays.equals(p_longArray, other.p_longArray))
- return false;
- if (!Arrays.equals(p_floatArray, other.p_floatArray))
- return false;
- if (!Arrays.equals(p_doubleArray, other.p_doubleArray))
- return false;
-
- // wrapper Arrays
- if (!Arrays.equals(w_boolArray, other.w_boolArray))
- return false;
- if (!Arrays.equals(w_byteArray, other.w_byteArray))
- return false;
- if (!Arrays.equals(w_shortArray, other.w_shortArray))
- return false;
- if (!Arrays.equals(w_intArray, other.w_intArray))
- return false;
- if (!Arrays.equals(w_longArray, other.w_longArray))
- return false;
- if (!Arrays.equals(w_floatArray, other.w_floatArray))
- return false;
- if (!Arrays.equals(w_doubleArray, other.w_doubleArray))
- return false;
- if (!Arrays.equals(w_strArray, other.w_strArray))
- return false;
- if (!Arrays.equals(w_bigIntArray, other.w_bigIntArray))
- return false;
- if (!Arrays.equals(w_bigDecArray, other.w_bigDecArray))
- return false;
-
- // comparing Collections based on content, order not considered
- if (!(c_list.size() == other.c_list.size()
- && c_list.containsAll(other.c_list)
- && other.c_list.containsAll(c_list)))
- return false;
- if (!(c_set.size() == other.c_set.size()
- && c_set.containsAll(other.c_set)
- && other.c_set.containsAll(c_set)))
- return false;
- if (!(c_queue.size() == other.c_queue.size()
- && c_queue.containsAll(other.c_queue)
- && other.c_queue.containsAll(c_queue)))
- return false;
- if (!(c_deque.size() == other.c_deque.size()
- && c_deque.containsAll(other.c_deque)
- && other.c_deque.containsAll(c_deque)))
- return false;
-
- // map comparision.
- if (!(compareMaps(m_empByCity, other.m_empByCity)))
- return false;
-
- // Enum validation
- if (!(day.equals(other.day)))
- return false;
-
- return true;
- }
-
- boolean compareMaps(Map m1, Map m2) {
- if (m1.size() != m2.size())
- return false;
- for (Object key : m1.keySet())
- if (!m1.get(key).equals(m2.get(key)))
- return false;
- return true;
- }
-}
-
-