Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.factual.driver;
  
  import java.util.Set;
  
Represents a Factual Crosswalk query.

Author(s):
aaron
 
 public class CrosswalkQuery {
   private String factualId;
   private int limit;
   private String namespace;
   private String namespaceId;
   private final Set<Stringonly = Sets.newHashSet();


  
Adds the specified Factual ID to this Query. Returned Crosswalk data will be for only the entity associated with the Factual ID.

Parameters:
factualId a unique Factual ID.
Returns:
this CrosswalkQuery
 
   public CrosswalkQuery factualId(String factualId) {
     this. = factualId;
     return this;
   }

  
Adds the specified limit to this Query. The amount of returned Crosswalk records will not exceed this limit.

Parameters:
factualId a unique Factual ID.
Returns:
this CrosswalkQuery
 
   public CrosswalkQuery limit(int limit) {
     this. = limit;
     return this;
   }

  
The namespace to search for a third party ID within.

Parameters:
namespace The namespace to search for a third party ID within.
Returns:
this CrosswalkQuery
 
   public CrosswalkQuery namespace(String namespace) {
     this. = namespace;
     return this;
   }

  
The id used by a third party to identify a place.

You must also supply namespace via namespace(java.lang.String).

Parameters:
namespaceId The id used by a third party to identify a place.
Returns:
this CrosswalkQuery
 
   public CrosswalkQuery namespaceId(String namespaceId) {
     this. = namespaceId;
     return this;
   }

  
Restricts the results to only return ids for the specified namespace(s).

Returns:
this CrosswalkQuery
 
   public CrosswalkQuery only(String... namespaces) {
     for(String ns : namespaces) {
       .add(ns);
     }
     return this;
   }
 
   protected String toUrlQuery() {
     return Joiner.on("&").skipNulls().join(
         urlPair("factual_id"),
         ( > 0 ? urlPair("limit") : null),
         urlPair("namespace"),
         urlPair("namespace_id"),
         urlPair("only"onlysOrNull()));
   }
 
   private String onlysOrNull() {
     if(!.isEmpty()) {
       return Joiner.on(",").skipNulls().join();
     } else {
      return null;
    }
  }
  private String urlPair(String nameObject val) {
    if(val != null) {
      try {
        return name + "=" + (val instanceof String ? URLEncoder.encode(val.toString(), "UTF-8") : val);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
    } else {
      return null;
    }
  }
New to GrepCode? Check out our FAQ X