APIClient adding getSetStringValue getMapStringListStrValue
This adds the getSetStringValue getMapStringListStrValue, the first return a set of string and the second a map from a string to a list of string. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
1cf0279644
commit
331c6c13b3
@ -8,9 +8,11 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
@ -193,6 +195,29 @@ public class APIClient {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getMapStringListStrValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
if (string.equals("")) {
|
||||
return null;
|
||||
}
|
||||
JsonReader reader = getReader(string, queryParams);
|
||||
JsonArray arr = reader.readArray();
|
||||
Map<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
JsonObject obj = arr.getJsonObject(i);
|
||||
if (obj.containsKey("key") && obj.containsKey("value")) {
|
||||
map.put(obj.getString("key"),
|
||||
listStrFromJArr(obj.getJsonArray("value")));
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getMapStringListStrValue(String string) {
|
||||
return getMapStringListStrValue(string, null);
|
||||
}
|
||||
|
||||
public Map<List<String>, List<String>> getMapListStrValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
if (string.equals("")) {
|
||||
@ -216,6 +241,22 @@ public class APIClient {
|
||||
return getMapListStrValue(string, null);
|
||||
}
|
||||
|
||||
public Set<String> getSetStringValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
JsonReader reader = getReader(string, queryParams);
|
||||
JsonArray arr = reader.readArray();
|
||||
Set<String> res = new HashSet<String>();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
res.add(arr.getString(i));
|
||||
}
|
||||
reader.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
public Set<String> getSetStringValue(String string) {
|
||||
return getSetStringValue(string, null);
|
||||
}
|
||||
|
||||
public Map<String, String> getMapStrValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
if (string.equals("")) {
|
||||
|
Loading…
Reference in New Issue
Block a user