ApiClient: Add getReverseMapStrValue method
Sometimes it is usefull to get a reverse of the map return by the API. For example instread of ip address to hostid to get the hostid to ip address. Though it is possible to reverse a map, there is no need, it's easier to generate the reverse mapping. Signed-off-by: Amnon Heiman <amnon@scylladb.com> Message-Id: <1458405434-8491-2-git-send-email-amnon@scylladb.com>
This commit is contained in:
parent
8f90d413a1
commit
a60c3156c6
@ -406,6 +406,28 @@ public class APIClient {
|
||||
return getMapStrValue(string, null);
|
||||
}
|
||||
|
||||
public Map<String, String> getReverseMapStrValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
if (string.equals("")) {
|
||||
return null;
|
||||
}
|
||||
JsonReader reader = getReader(string, queryParams);
|
||||
JsonArray arr = reader.readArray();
|
||||
Map<String, String> map = new HashMap<String, 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("value"), obj.getString("key"));
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map<String, String> getReverseMapStrValue(String string) {
|
||||
return getReverseMapStrValue(string, null);
|
||||
}
|
||||
|
||||
public List<InetAddress> getListInetAddressValue(String string,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
List<String> vals = getListStrValue(string, queryParams);
|
||||
|
Loading…
Reference in New Issue
Block a user