Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.factual.driver;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.json.JSONException;
 import  org.json.JSONObject;
 
Represents the response from running a fetch request against Factual, such as a geolocation based query for specific places entities.

Author(s):
aaron
public class ReadResponse extends Response implements Tabular {
  private final String json;
  private List<Map<StringObject>> data = Lists.newArrayList();


  
Constructor, parses from a JSON response String.

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

  

Returns:
The full JSON response from Factual
  public String getJson() {
    return ;
  }

  

Returns:
the first data record or null if no data was returned.
  public Map<StringObjectfirst() {
    if(.isEmpty()) {
      return null;
    } else {
      return .get(0);
    }
  }

  
An ordered collection of the main data returned by Factual. Represented as Maps, where each Map is a record in the results.

Returns:
the main data returned by Factual.
  public List<Map<StringObject>> getData() {
    return ;
  }

  

Returns:
the size of the result set
  public int size() {
    return .size();
  }

  

Returns:
a Collection of all String values found in this Response's data rows as the field attribute.
  public Collection<StringmapStrings(final String field) {
    return Collections2.transform(new Function<Map<StringObject>, String>() {
      @Override
      public String apply(Map<StringObjectrow) {
        Object val = row.get(field);
        return val != null ? val.toString() : null;
      }});
  }
  //TODO: Bradley: "mapToStrings, mapToDoubles, etc."
New to GrepCode? Check out our FAQ X