[java][okhttp-gson] minor improvements (#13792)

* use replace instead of replaceAll

* avoid using instance to accessd static methods

* use entrySet instead of keySet

* use statis class instead of instance for static method

* update samples
This commit is contained in:
William Cheng
2022-10-22 13:31:59 +08:00
committed by GitHub
parent 2e4a02532e
commit ca56242e4f
19 changed files with 103 additions and 103 deletions

View File

@@ -354,7 +354,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setDateFormat(DateFormat dateFormat) {
this.json.setDateFormat(dateFormat);
JSON.setDateFormat(dateFormat);
return this;
}
@@ -365,7 +365,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setSqlDateFormat(DateFormat dateFormat) {
this.json.setSqlDateFormat(dateFormat);
JSON.setSqlDateFormat(dateFormat);
return this;
}
@@ -376,7 +376,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
this.json.setOffsetDateTimeFormat(dateFormat);
JSON.setOffsetDateTimeFormat(dateFormat);
return this;
}
@@ -387,7 +387,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setLocalDateFormat(DateTimeFormatter dateFormat) {
this.json.setLocalDateFormat(dateFormat);
JSON.setLocalDateFormat(dateFormat);
return this;
}
@@ -398,7 +398,7 @@ public class ApiClient {
* @return a {@link org.openapitools.client.ApiClient} object
*/
public ApiClient setLenientOnJson(boolean lenientOnJson) {
this.json.setLenientOnJson(lenientOnJson);
JSON.setLenientOnJson(lenientOnJson);
return this;
}
@@ -679,7 +679,7 @@ public class ApiClient {
return "";
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
String jsonStr = json.serialize(param);
String jsonStr = JSON.serialize(param);
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
@@ -938,7 +938,7 @@ public class ApiClient {
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return json.deserialize(respBody, returnType);
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
@@ -972,7 +972,7 @@ public class ApiClient {
} else if (isJsonMime(contentType)) {
String content;
if (obj != null) {
content = json.serialize(obj);
content = JSON.serialize(obj);
} else {
content = null;
}
@@ -1451,7 +1451,7 @@ public class ApiClient {
} else {
String content;
if (obj != null) {
content = json.serialize(obj);
content = JSON.serialize(obj);
} else {
content = null;
}

View File

@@ -253,7 +253,7 @@ public class PetApi {
// create path and map variables
String localVarPath = "/pet/{petId}"
.replaceAll("\\{" + "petId" + "\\}", localVarApiClient.escapeString(petId.toString()));
.replace("{" + "petId" + "}", localVarApiClient.escapeString(petId.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
@@ -759,7 +759,7 @@ public class PetApi {
// create path and map variables
String localVarPath = "/pet/{petId}"
.replaceAll("\\{" + "petId" + "\\}", localVarApiClient.escapeString(petId.toString()));
.replace("{" + "petId" + "}", localVarApiClient.escapeString(petId.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
@@ -1109,7 +1109,7 @@ public class PetApi {
// create path and map variables
String localVarPath = "/pet/{petId}"
.replaceAll("\\{" + "petId" + "\\}", localVarApiClient.escapeString(petId.toString()));
.replace("{" + "petId" + "}", localVarApiClient.escapeString(petId.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
@@ -1234,7 +1234,7 @@ public class PetApi {
// create path and map variables
String localVarPath = "/pet/{petId}/uploadImage"
.replaceAll("\\{" + "petId" + "\\}", localVarApiClient.escapeString(petId.toString()));
.replace("{" + "petId" + "}", localVarApiClient.escapeString(petId.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();

View File

@@ -65,8 +65,8 @@ public class RetryingOAuth extends OAuth implements Interceptor {
.setClientSecret(clientSecret));
setFlow(flow);
if (parameters != null) {
for (String paramName : parameters.keySet()) {
tokenRequestBuilder.setParameter(paramName, parameters.get(paramName));
for (Map.Entry<String, String> entry : parameters.entrySet()) {
tokenRequestBuilder.setParameter(entry.getKey(), entry.getValue());
}
}
}
@@ -129,8 +129,8 @@ public class RetryingOAuth extends OAuth implements Interceptor {
}
Map<String, String> headers = oAuthRequest.getHeaders();
for (String headerName : headers.keySet()) {
requestBuilder.addHeader(headerName, headers.get(headerName));
for (Map.Entry<String, String> entry : headers.entrySet()) {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
requestBuilder.url(oAuthRequest.getLocationUri());