/** * Get the optional object value associated with an index. * @param index The index must be between 0 and length() - 1. * @return An object value, or null if there is no * object at that index. */ public Object opt(final int index) { return index < 0 || index >= length() ? null : myArrayList.get(index); }
/** * Get the optional object value associated with an index. * @param index The index must be between 0 and length() - 1. * @return An object value, or null if there is no * object at that index. */ public Object opt(final int index) { return index < 0 || index >= length() ? null : myArrayList.get(index); }
/** * Make a string from the contents of this JSONArray. The * <code>separator</code> string is inserted between each element. * Warning: This method assumes that the data structure is acyclical. * @param separator A string that will be inserted between the elements. * @return a string. * @throws JSONException If the array contains an invalid number. */ public String join(final String separator) throws JSONException { int len = length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator); } sb.append(JSONObject.valueToString(myArrayList.get(i))); } return sb.toString(); }
/** * Make a string from the contents of this JSONArray. The * <code>separator</code> string is inserted between each element. * Warning: This method assumes that the data structure is acyclical. * @param separator A string that will be inserted between the elements. * @return a string. * @throws JSONException If the array contains an invalid number. */ public String join(final String separator) throws JSONException { int len = length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator); } sb.append(JSONObject.valueToString(myArrayList.get(i))); } return sb.toString(); }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(final JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), opt(i)); } return jo; }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(final JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), opt(i)); } return jo; }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
public static JMSSessionInfo[] from(final String jsonString) throws JSONException { JSONArray array = new JSONArray(jsonString); JMSSessionInfo[] infos = new JMSSessionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"), obj.getLong("creationTime")); infos[i] = info; } return infos; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(final JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(opt(names.getString(i))); } return ja; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(final JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(opt(names.getString(i))); } return ja; }
/** * 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; }
/** * 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 JMSConnectionInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); JMSConnectionInfo[] infos = new JMSConnectionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String cid = obj.isNull("clientID") ? null : obj.getString("clientID"); String uname = obj.isNull("principal") ? null : obj.getString("principal"); JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"), obj.getString("clientAddress"), obj.getLong("creationTime"), cid, uname); infos[i] = info; } return infos; }
/** * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. */ public static SubscriptionInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); SubscriptionInfo[] infos = new SubscriptionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject sub = array.getJSONObject(i); SubscriptionInfo info = new SubscriptionInfo(sub.getString("queueName"), sub.optString("clientID", null), sub.optString("name", null), sub.getBoolean("durable"), sub.optString("selector", null), sub.getInt("messageCount"), sub.getInt("deliveringCount")); infos[i] = info; } return infos; }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link AddressControl#getRolesAsJSON()}. */ public static final RoleInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); RoleInfo[] roles = new RoleInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject r = array.getJSONObject(i); RoleInfo role = new RoleInfo(r.getString("name"), r.getBoolean("send"), r.getBoolean("consume"), r.getBoolean("createDurableQueue"), r.getBoolean("deleteDurableQueue"), r.getBoolean("createNonDurableQueue"), r.getBoolean("deleteNonDurableQueue"), r.getBoolean("manage")); roles[i] = role; } return roles; }
/** * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. */ public static JMSConsumerInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); JMSConsumerInfo[] infos = new JMSConsumerInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject sub = array.getJSONObject(i); JMSConsumerInfo info = new JMSConsumerInfo(sub.getString("consumerID"), sub.getString("connectionID"), sub.getString("destinationName"), sub.getString("destinationType"), sub.getBoolean("browseOnly"), sub.getLong("creationTime"), sub.getBoolean("durable"), sub.optString("filter", null)); infos[i] = info; } return infos; }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link AddressControl#getRolesAsJSON()}. */ public static RoleInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); RoleInfo[] roles = new RoleInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject r = array.getJSONObject(i); RoleInfo role = new RoleInfo(r.getString("name"), r.getBoolean("send"), r.getBoolean("consume"), r.getBoolean("createDurableQueue"), r.getBoolean("deleteDurableQueue"), r.getBoolean("createNonDurableQueue"), r.getBoolean("deleteNonDurableQueue"), r.getBoolean("manage")); roles[i] = role; } return roles; }