Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Update libraries, Added test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJeongHwan committed Sep 23, 2019
1 parent a588382 commit 403d5e0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry combineaccessrules="false" kind="src" path="/reflection"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/main/
/test/
/default/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
compile 'com.github.realtimetech-solution:reflection:0.1.1'
compile 'com.github.realtimetech-solution:reflection:0.1.2'
}

jar {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/realtimetech/kson/KsonContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private enum ValueMode {
// for object
private FastStack<Object> objectStack;
private FastStack<KsonValue> ksonStack;
private boolean working;

private HashMap<Class<?>, Transformer<?>> registeredTransformers;

Expand All @@ -54,6 +55,7 @@ public KsonContext() {
}

public KsonContext(int stackSize, int stringBufferSize) {
this.working = false;
this.valueStack = new FastStack<Object>(stackSize);
this.modeStack = new FastStack<ValueMode>(stackSize);
this.stringMaker = new StringMaker(stringBufferSize);
Expand Down Expand Up @@ -279,11 +281,10 @@ public Object addToObjectStack(Object object) throws DeserializeException {
}

public Object addToObjectStack(Class<?> clazz, Object object) throws DeserializeException {
boolean needLoop = this.objectStack.isEmpty();

Object result = this.createAtToObject(true, clazz, object);

if (needLoop) {
if (!this.working) {
this.working = true;
while (!this.objectStack.isEmpty()) {
Object targetObject = this.objectStack.pop();
KsonValue targetKson = this.ksonStack.pop();
Expand Down Expand Up @@ -316,7 +317,7 @@ public Object addToObjectStack(Class<?> clazz, Object object) throws Deserialize
}
}
}

this.working = false;
this.objectStack.reset();
this.ksonStack.reset();
}
Expand Down Expand Up @@ -405,7 +406,7 @@ private Object createAtToObject(boolean first, Class<?> type, Object originalVal
}
}

if (useStack) {
if (useStack && convertedValue != null) {
this.ksonStack.push((KsonValue) originalValue);
this.objectStack.push(convertedValue);
}
Expand All @@ -415,19 +416,18 @@ private Object createAtToObject(boolean first, Class<?> type, Object originalVal
}

public KsonValue fromObject(Object object) throws SerializeException {
if (this.objectStack.isEmpty()) {
if (!this.working) {
return (KsonValue) addFromObjectStack(object);
} else {
throw new SerializeException("This context already running serialize!");
}
}

public Object addFromObjectStack(Object object) throws SerializeException {
boolean needLoop = this.objectStack.isEmpty();

Object result = null;

if (needLoop) {
if (!this.working) {
this.working = true;
result = this.createAtFromObject(true, object.getClass(), object);

while (!this.objectStack.isEmpty()) {
Expand Down Expand Up @@ -461,6 +461,7 @@ public Object addFromObjectStack(Object object) throws SerializeException {

this.objectStack.reset();
this.ksonStack.reset();
this.working = false;
} else {
result = this.createAtFromObject(false, Object.class, object);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/realtimetech/kson/test/TestObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class TestObject {
private LinkedList<Double> doubleLinkedList;
private List<Double> doubleList;

private LinkedList<TestSingle> testSingleList;

private HashMap<String, String> stringMap;
private HashMap<String, Date> dateMap;
private HashMap<HashMap<String, String>, HashMap<String, String>> mapMap;
Expand Down Expand Up @@ -257,6 +259,13 @@ public TestObject(Test test) {
this.doubleList.add(2d);
}

this.testSingleList = new LinkedList<TestSingle>();
{
this.testSingleList.add(new TestSingle());
this.testSingleList.add(new TestSingle());
this.testSingleList.add(new TestSingle());
}

this.mapMap = new HashMap<HashMap<String, String>, HashMap<String, String>>();
{
{
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/realtimetech/kson/test/TestSingle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.realtimetech.kson.test;

import java.util.LinkedList;

public class TestSingle {
private LinkedList<TestSmall> testSmallList;

public TestSingle() {
this.testSmallList = new LinkedList<TestSmall>();
{
this.testSmallList.add(new TestSmall());
this.testSmallList.add(new TestSmall());
this.testSmallList.add(new TestSmall());
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/realtimetech/kson/test/TestSmall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.realtimetech.kson.test;

public class TestSmall {
private String string = "ABC";

public String getString() {
return string;
}
}

0 comments on commit 403d5e0

Please sign in to comment.