package foundation.clean;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
|
import foundation.data.entity.Entity;
|
import foundation.json.IJSONProvider;
|
import foundation.json.IJSONWriter;
|
import foundation.json.JObjectReader;
|
import foundation.json.JType;
|
|
public class CleanResult implements IJSONProvider{
|
private JSONArray orginalListAfterClean;
|
private JSONArray standardListAfterClean;
|
private JType type;
|
|
public CleanResult() {
|
orginalListAfterClean = new JSONArray();
|
standardListAfterClean = new JSONArray();
|
}
|
|
public void addOneOrginal(Object value) {
|
orginalListAfterClean.add(value);
|
}
|
|
public void addOneStandard(Object value) {
|
standardListAfterClean.add(value);
|
}
|
|
public void removeLastOrgional() {
|
orginalListAfterClean.remove(orginalListAfterClean.size()-1);
|
}
|
|
public void setType(JType type) {
|
this.type = type;
|
}
|
|
@Override
|
public void writeJSON(IJSONWriter writer) {
|
if(JType.Object.equals(type)) {
|
writerJSONReader(writer);
|
}
|
else if(JType.String.equals(type)) {
|
writerJSONFormal(writer);
|
}
|
else {
|
writerJSONEntity(writer);
|
}
|
}
|
|
private void writerJSONReader(IJSONWriter writer) {
|
JObjectReader jsonReader;
|
writer.beginArray("orginalListAfterClean");
|
for(Object json: orginalListAfterClean) {
|
jsonReader = (JObjectReader) json;
|
jsonReader.writeJSON(writer);
|
}
|
writer.endArray();
|
|
writer.beginArray("standardListAfterClean");
|
for(Object json: standardListAfterClean) {
|
jsonReader = (JObjectReader) json;
|
jsonReader.writeJSON(writer);
|
}
|
writer.endArray();
|
|
}
|
|
private void writerJSONFormal(IJSONWriter writer) {
|
writer.beginArray("orginalListAfterClean");
|
for(Object json: orginalListAfterClean) {
|
writer.writeJSON(JSON.toJSONString(json));
|
}
|
writer.endArray();
|
|
writer.beginArray("standardListAfterClean");
|
for(Object json: standardListAfterClean) {
|
writer.writeJSON(JSON.toJSONString(json));
|
}
|
writer.endArray();
|
|
}
|
|
private void writerJSONEntity(IJSONWriter writer) {
|
writer.beginArray("orginalListAfterClean");
|
for(Object json: orginalListAfterClean) {
|
Entity entity = (Entity)json;
|
entity.writeJSON(writer);
|
}
|
writer.endArray();
|
|
writer.beginArray("standardListAfterClean");
|
for(Object json: standardListAfterClean) {
|
Entity entity = (Entity)json;
|
entity.writeJSON(writer);
|
}
|
writer.endArray();
|
|
}
|
}
|