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:
parent
35e5b22746
commit
7e7e0ca367
@ -37,6 +37,8 @@ import javax.ws.rs.core.MediaType;
|
|||||||
|
|
||||||
public class APIClient {
|
public class APIClient {
|
||||||
JsonReaderFactory factory = Json.createReaderFactory(null);
|
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() {
|
public static String getBaseUrl() {
|
||||||
return "http://" + System.getProperty("apiaddress", "localhost") + ":"
|
return "http://" + System.getProperty("apiaddress", "localhost") + ":"
|
||||||
@ -372,11 +374,29 @@ public class APIClient {
|
|||||||
return Long.parseLong(getStringValue(string));
|
return Long.parseLong(getStringValue(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string) {
|
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string,
|
||||||
// TODO Auto-generated method stub
|
MultivaluedMap<String, String> queryParams) {
|
||||||
return null;
|
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) {
|
public Map<String, Long> getMapStringLongValue(String string) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user