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.JSONArray;
  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 {
   protected InternalResponse resp = null;
   private List<Map<StringObject>> data = Lists.newArrayList();


  
Constructor, parses from a JSON response String.
 
   public ReadResponse(InternalResponse resp) {
     this. = resp;
     try{
       JSONObject rootJsonObj = new JSONObject(resp.getContent());
       Response.withMeta(thisrootJsonObj);
       JSONObject respJson = rootJsonObj.getJSONObject(.);
       Object dataObj = respJson.get(.);
       if (dataObj instanceof JSONArray) {
          = JsonUtil.data(respJson.getJSONArray(.));
       } else if (dataObj instanceof JSONObject) {
         .add(JsonUtil.toMap((JSONObject) dataObj));
       }
     } catch (JSONException e) {
       throw new RuntimeException(e);
     }
   }

  

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

  

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.
 
   @Override
   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