Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.factual.driver;
 
 import java.util.List;
 
 import  org.json.JSONArray;
 import  org.json.JSONException;
 import  org.json.JSONObject;
 
Represents the response from running a Crosswalk lookup against Factual.

Author(s):
aaron
public class CrosswalkResponse extends Response {
  private final List<Crosswalkcrosswalks = Lists.newArrayList();
  private final String json;


  
Constructor, parses from a JSON response String.

Parameters:
json the JSON response String returned by Factual.
  public CrosswalkResponse(String json) {
    this. = json;
    try {
      JSONObject rootJsonObj = new JSONObject(json);
      Response.withMeta(thisrootJsonObj);
      parseCrosswalks(rootJsonObj.getJSONObject("response").getJSONArray("data"));
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
  }
  public String getJson() {
    return ;
  }

  
Returns the ordered collection of Crosswalks represented by this response.

Returns:
the ordered collection of Crosswalks represented by this response.
  public List<CrosswalkgetCrosswalks() {
    return ;
  }

  

Returns:
the first Crosswalk hit or null if no data was returned.
  public Crosswalk first() {
    if(.isEmpty()) {
      return null;
    } else {
      return .get(0);
    }
  }

  

Returns:
the size of the result set
  public int size() {
    return .size();
  }
  private void parseCrosswalks(JSONArray arrthrows JSONException {
    for(int i=0; i<arr.length(); i++) {
      .add(crosswalkFrom(arr.getJSONObject(i)));
    }
  }
  private static Crosswalk crosswalkFrom(JSONObject jothrows JSONException {
    Crosswalk cw = new Crosswalk();
    cw.setFactualId(jo.getString("factual_id"));
    cw.setNamespace(jo.getString("namespace"));
    cw.setNamespaceId(jo.getString("namespace_id"));
    if(jo.has("url")) {
      cw.setUrl(jo.getString("url"));
    }
    return cw;
  }
New to GrepCode? Check out our FAQ X