public static String listMessageCounterHistory(final MessageCounter counter) throws Exception { List<DayCounter> history = counter.getHistory(); DayCounterInfo[] infos = new DayCounterInfo[history.size()]; for (int i = 0; i < infos.length; i++) { DayCounter dayCounter = history.get(i); int[] counters = dayCounter.getCounters(); GregorianCalendar date = dayCounter.getDate(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT); String strData = dateFormat.format(date.getTime()); infos[i] = new DayCounterInfo(strData, counters); } return DayCounterInfo.toJSON(infos); }
public static String toJSON(final DayCounterInfo[] infos) throws JSONException { JSONObject json = new JSONObject(); JSONArray counters = new JSONArray(); for (DayCounterInfo info : infos) { JSONObject counter = new JSONObject(); counter.put("date", info.getDate()); counter.put("counters", Arrays.asList(info.getCounters())); counters.put(counter); } json.put("dayCounters", counters); return json.toString(); }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounterHistory()}. */ public static DayCounterInfo[] fromJSON(final String jsonString) throws JSONException { JSONObject json = new JSONObject(jsonString); JSONArray dayCounters = json.getJSONArray("dayCounters"); DayCounterInfo[] infos = new DayCounterInfo[dayCounters.length()]; for (int i = 0; i < dayCounters.length(); i++) { JSONObject counter = (JSONObject)dayCounters.get(i); JSONArray hour = (JSONArray)counter.getJSONArray("counters").get(0); int[] hourCounters = new int[24]; for (int j = 0; j < 24; j++) { hourCounters[j] = hour.getInt(j); } DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters); infos[i] = info; } return infos; }
public static String toJSON(final DayCounterInfo[] infos) throws JSONException { JSONObject json = new JSONObject(); JSONArray counters = new JSONArray(); for (DayCounterInfo info : infos) { JSONObject counter = new JSONObject(); counter.put("date", info.getDate()); counter.put("counters", Arrays.asList(info.getCounters())); counters.put(counter); } json.put("dayCounters", counters); return json.toString(); }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounterHistory()}. */ public static DayCounterInfo[] fromJSON(final String jsonString) throws JSONException { JSONObject json = new JSONObject(jsonString); JSONArray dayCounters = json.getJSONArray("dayCounters"); DayCounterInfo[] infos = new DayCounterInfo[dayCounters.length()]; for (int i = 0; i < dayCounters.length(); i++) { JSONObject counter = (JSONObject)dayCounters.get(i); JSONArray hour = (JSONArray)counter.getJSONArray("counters").get(0); int[] hourCounters = new int[24]; for (int j = 0; j < 24; j++) { hourCounters[j] = hour.getInt(j); } DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters); infos[i] = info; } return infos; }
public static String listMessageCounterHistory(final MessageCounter counter) throws Exception { List<DayCounter> history = counter.getHistory(); DayCounterInfo[] infos = new DayCounterInfo[history.size()]; for (int i = 0; i < infos.length; i++) { DayCounter dayCounter = history.get(i); int[] counters = dayCounter.getCounters(); GregorianCalendar date = dayCounter.getDate(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT); String strData = dateFormat.format(date.getTime()); infos[i] = new DayCounterInfo(strData, counters); } return DayCounterInfo.toJSON(infos); }