|
|
|
@ -7,7 +7,6 @@ import com.jayway.jsonpath.json.JsonArray;
|
|
|
|
|
import com.jayway.jsonpath.json.JsonElement; |
|
|
|
|
import com.jayway.jsonpath.json.JsonException; |
|
|
|
|
import com.jayway.jsonpath.json.JsonFactory; |
|
|
|
|
import com.jayway.jsonpath.json.JsonPathResultList; |
|
|
|
|
|
|
|
|
|
import static java.lang.String.format; |
|
|
|
|
|
|
|
|
@ -16,40 +15,52 @@ import static java.lang.String.format;
|
|
|
|
|
* Date: 2/9/11 |
|
|
|
|
* Time: 12:28 PM |
|
|
|
|
*/ |
|
|
|
|
public class FilterOutput extends ArrayList<JsonElement> { |
|
|
|
|
public class FilterOutput { |
|
|
|
|
|
|
|
|
|
private final List<JsonElement> result; |
|
|
|
|
|
|
|
|
|
public FilterOutput(JsonElement root) { |
|
|
|
|
super(); |
|
|
|
|
this.add(root); |
|
|
|
|
} |
|
|
|
|
public FilterOutput(){ |
|
|
|
|
super(); |
|
|
|
|
this.result = new ArrayList<JsonElement>(); |
|
|
|
|
result.add(root); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JsonArray getResultAsJsonArray() throws JsonException { |
|
|
|
|
return this.get(0).toJsonArray(); |
|
|
|
|
public FilterOutput(List<JsonElement> result) { |
|
|
|
|
this.result = result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JsonElement getResultAsJson() throws JsonException { |
|
|
|
|
if(this.size()>1){ |
|
|
|
|
JsonArray ja = JsonFactory.getInstance().createJsonArray(); |
|
|
|
|
for(JsonElement je:this){ |
|
|
|
|
ja.add(je); |
|
|
|
|
|
|
|
|
|
public FilterOutput() { |
|
|
|
|
this.result = new ArrayList<JsonElement>(); |
|
|
|
|
} |
|
|
|
|
return ja; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JsonElement getResult() throws JsonException { |
|
|
|
|
if(result.size()==0){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
else if(this.size()==1){ |
|
|
|
|
return this.get(0); |
|
|
|
|
else if(result.size()==1){ |
|
|
|
|
return result.get(0); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
return JsonFactory.getInstance().createJsonNull(null, null); |
|
|
|
|
JsonFactory fact = JsonFactory.getInstance(); |
|
|
|
|
JsonArray ja = fact.createJsonArray(); |
|
|
|
|
for(JsonElement ele:result) |
|
|
|
|
ja.add(ele); |
|
|
|
|
return ja; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JsonArray getResultAsList() throws JsonException { |
|
|
|
|
return getResult().toJsonArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<JsonElement> getList() throws JsonException { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|