Skip to content

Commit

Permalink
Address checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Apr 27, 2016
1 parent 9a27d68 commit 8009399
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,54 @@
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Version;
import retrofit2.BaseUrl;

/**
* User agent interceptor for putting a 'User-Agent' header in the request.
* An instance of class handles dynamic base URLs in the HTTP pipeline.
*/
public class BaseUrlHandler implements Interceptor {
/** The URL template for the dynamic URL. */
private final String rawUrl;
/** The base URL after applying the variable replacements. */
private String baseUrl;

/**
* Creates an instance of this class with a URL template.
*
* @param rawUrl the URL template with variables wrapped in "{" and "}".
*/
public BaseUrlHandler(String rawUrl) {
this.rawUrl = rawUrl;
this.baseUrl = null;
}

/**
* Gets the base URL.
*
* @return the URL template if it's not a dynamic URL or variables in a
* dynamic URL haven't been set. The compiled URL otherwise.
*/
public String baseUrl() {
if (this.baseUrl == null) {
return rawUrl;
}
return this.baseUrl;
}

/**
* Handles dynamic replacements on base URL. The arguments must be in pairs
* with the string in raw URL to replace as replacements[i] and the dynamic
* part as replacements[i+1]. E.g. {subdomain}.microsoft.com can be set
* dynamically by calling setBaseUrl("{subdomain}", "azure").
*
* @param replacements the string replacements in pairs.
*/
public void setBaseUrl(String... replacements) {
if (replacements.length % 2 != 0) {
throw new IllegalArgumentException("Must provide a replacement value for each pattern");
}
baseUrl = rawUrl;
for (int i = 0; i < replacements.length; i += 2) {
baseUrl = baseUrl.replace(replacements[i], replacements[i+1]);
baseUrl = baseUrl.replace(replacements[i], replacements[i + 1]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* An instance of this class stores the client information for making REST calls.
*/
public class RestClient {
public final class RestClient {
/** The {@link okhttp3.OkHttpClient} object. */
private OkHttpClient httpClient;
/** The {@link retrofit2.Retrofit} object. */
Expand Down

0 comments on commit 8009399

Please sign in to comment.