HUGE refactoring - rewriting rest client

DO NOT TRY TO BUILD THIS VERSION
[ci skip]
This commit is contained in:
Mariotaku Lee 2015-05-06 20:40:23 +08:00
parent 5b6aecf852
commit 3328cd7a14
2 changed files with 18 additions and 18 deletions

View File

@ -4,7 +4,6 @@ import android.support.annotation.NonNull;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.mariotaku.simplerestapi.http.KeyValuePair;
import org.mariotaku.simplerestapi.http.ValueMap;
import org.mariotaku.simplerestapi.http.mime.BaseTypedData;
import org.mariotaku.simplerestapi.http.mime.FormTypedBody;
@ -43,7 +42,7 @@ public final class RestMethodInfo {
private final HashMap<Extra, Object> extras;
private final FileValue file;
private ArrayList<KeyValuePair> queriesCache, formsCache, headersCache;
private ArrayList<Pair<String, String>> queriesCache, formsCache, headersCache;
private ArrayList<Pair<String, TypedData>> partsCache;
private Map<String, Object> extrasCache;
private TypedData bodyCache;
@ -105,9 +104,9 @@ public final class RestMethodInfo {
return extrasCache = map;
}
public List<KeyValuePair> getForms() {
public List<Pair<String, String>> getForms() {
if (formsCache != null) return formsCache;
final ArrayList<KeyValuePair> list = new ArrayList<>();
final ArrayList<Pair<String, String>> list = new ArrayList<>();
for (Map.Entry<Form, Object> entry : forms.entrySet()) {
final Form form = entry.getKey();
final Object value = entry.getValue();
@ -115,12 +114,12 @@ public final class RestMethodInfo {
final ValueMap valueMap = (ValueMap) value;
for (String key : form.value()) {
if (valueMap.has(key)) {
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
}
}
} else if (value != null) {
for (String key : form.value()) {
list.add(new KeyValuePair(key, String.valueOf(value)));
list.add(new ImmutablePair<>(key, String.valueOf(value)));
}
}
}
@ -144,9 +143,9 @@ public final class RestMethodInfo {
}
@NonNull
public List<KeyValuePair> getHeaders() {
public List<Pair<String, String>> getHeaders() {
if (headersCache != null) return headersCache;
final ArrayList<KeyValuePair> list = new ArrayList<>();
final ArrayList<Pair<String, String>> list = new ArrayList<>();
for (Map.Entry<Header, Object> entry : headers.entrySet()) {
final Header form = entry.getKey();
final Object value = entry.getValue();
@ -154,12 +153,12 @@ public final class RestMethodInfo {
final ValueMap valueMap = (ValueMap) value;
for (String key : form.value()) {
if (valueMap.has(key)) {
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
}
}
} else if (value != null) {
for (String key : form.value()) {
list.add(new KeyValuePair(key, String.valueOf(value)));
list.add(new ImmutablePair<>(key, String.valueOf(value)));
}
}
}
@ -186,9 +185,9 @@ public final class RestMethodInfo {
return sb.toString();
}
public List<KeyValuePair> getQueries() {
public List<Pair<String, String>> getQueries() {
if (queriesCache != null) return queriesCache;
final ArrayList<KeyValuePair> list = new ArrayList<>();
final ArrayList<Pair<String, String>> list = new ArrayList<>();
for (Map.Entry<Query, Object> entry : queries.entrySet()) {
final Query form = entry.getKey();
final Object value = entry.getValue();
@ -196,12 +195,12 @@ public final class RestMethodInfo {
final ValueMap valueMap = (ValueMap) value;
for (String key : form.value()) {
if (valueMap.has(key)) {
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
}
}
} else if (value != null) {
for (String key : form.value()) {
list.add(new KeyValuePair(key, String.valueOf(value)));
list.add(new ImmutablePair<>(key, String.valueOf(value)));
}
}
}

View File

@ -1,5 +1,6 @@
package org.mariotaku.simplerestapi.http;
import org.apache.commons.lang3.tuple.Pair;
import org.mariotaku.simplerestapi.RestMethodInfo;
import org.mariotaku.simplerestapi.Utils;
@ -25,15 +26,15 @@ public class Endpoint {
return constructUrl(endpoint, requestInfo.getPath(), requestInfo.getQueries());
}
public String construct(String path, List<KeyValuePair> queries) {
public String construct(String path, List<Pair<String, String>> queries) {
return constructUrl(url, path, queries);
}
public String construct(String path, KeyValuePair... queries) {
public String construct(String path, Pair<String, String>... queries) {
return constructUrl(url, path, Arrays.asList(queries));
}
public static String constructUrl(String endpoint, String path, List<KeyValuePair> queries) {
public static String constructUrl(String endpoint, String path, List<Pair<String, String>> queries) {
final StringBuilder urlBuilder = new StringBuilder();
if (endpoint.charAt(endpoint.length() - 1) == '/') {
urlBuilder.append(endpoint.substring(0, endpoint.length() - 1));
@ -49,7 +50,7 @@ public class Endpoint {
return constructUrl(urlBuilder.toString(), queries);
}
public static String constructUrl(String url, List<KeyValuePair> queries) {
public static String constructUrl(String url, List<Pair<String, String>> queries) {
if (queries == null || queries.isEmpty()) return url;
final StringBuilder urlBuilder = new StringBuilder(url);
for (int i = 0, j = queries.size(); i < j; i++) {