APIClient: Add the getMapInetAddressFloatValue implementation

This adds the implementation to the stubed getMapInetAddressFloatValue,
it gets an array of 'key', 'value' and translate it into a map of key to
float.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
Amnon Heiman 2015-08-24 10:32:16 +03:00
parent 35e5b22746
commit 7e7e0ca367

View File

@ -37,6 +37,8 @@ import javax.ws.rs.core.MediaType;
public class APIClient {
JsonReaderFactory factory = Json.createReaderFactory(null);
private static final java.util.logging.Logger logger = java.util.logging.Logger
.getLogger(APIClient.class.getName());
public static String getBaseUrl() {
return "http://" + System.getProperty("apiaddress", "localhost") + ":"
@ -372,11 +374,29 @@ public class APIClient {
return Long.parseLong(getStringValue(string));
}
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string) {
// TODO Auto-generated method stub
return null;
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string,
MultivaluedMap<String, String> queryParams) {
Map<InetAddress, Float> res = new HashMap<InetAddress, Float>();
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
JsonObject obj = null;
for (int i = 0; i < arr.size(); i++) {
try {
obj = arr.getJsonObject(i);
res.put(InetAddress.getByName(obj.getString("key")),
Float.parseFloat(obj.getString("value")));
} catch (UnknownHostException e) {
logger.warning("Bad formatted address " + obj.getString("key"));
}
}
return res;
}
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string) {
return getMapInetAddressFloatValue(string, null);
}
public Map<String, Long> getMapStringLongValue(String string) {
// TODO Auto-generated method stub
return null;