From c3e9bd6ef7c5e3f9238fe7be92c4808fde24b178 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Sun, 21 Jun 2015 09:41:43 +0300 Subject: [PATCH] APIClinet: Add mapToString helper function and intArr impl This adds a helper function to make a string out of a map, by default, key/names are joing by '=' and entries are joined by ',' but it can be modified. It also adds the implementation for getIntArr, which return an array of ints. Signed-off-by: Amnon Heiman --- .../com/cloudius/urchin/api/APIClient.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudius/urchin/api/APIClient.java b/src/main/java/com/cloudius/urchin/api/APIClient.java index f7f1c7e..f937697 100644 --- a/src/main/java/com/cloudius/urchin/api/APIClient.java +++ b/src/main/java/com/cloudius/urchin/api/APIClient.java @@ -175,6 +175,24 @@ public class APIClient { return join(arr, ","); } + public static String mapToString(Map mp, String pairJoin, + String joiner) { + String res = ""; + if (mp != null) { + for (String name : mp.keySet()) { + if (!res.equals("")) { + res = res + joiner; + } + res = res + name + pairJoin + mp.get(name); + } + } + return res; + } + + public static String mapToString(Map mp) { + return mapToString(mp, "=", ","); + } + public static boolean set_query_param( MultivaluedMap queryParams, String key, String value) { if (queryParams != null && key != null && value != null @@ -373,9 +391,20 @@ public class APIClient { return null; } + public int[] getIntArrValue(String string, + MultivaluedMap queryParams) { + JsonReader reader = getReader(string, queryParams); + JsonArray arr = reader.readArray(); + int[] res = new int[arr.size()]; + for (int i = 0; i < arr.size(); i++) { + res[i] = arr.getInt(i); + } + reader.close(); + return res; + } + public int[] getIntArrValue(String string) { - // TODO Auto-generated method stub - return null; + return getIntArrValue(string, null); } public Map getListMapStringLongValue(String string,