/** * Put a key/boolean pair in the JSONObject. * * @param key A key string. * @param value A boolean which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final boolean value) throws JSONException { put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Put a key/boolean pair in the JSONObject. * * @param key A key string. * @param value A boolean which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final boolean value) throws JSONException { put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Put a key/value pair in the JSONObject, but only if the * key and the value are both non-null. * @param key A key string. * @param value An object which is the value. It should be of one of these * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, * or the JSONObject.NULL object. * @return this. * @throws JSONException If the value is a non-finite number. */ public JSONObject putOpt(final String key, final Object value) throws JSONException { if (key != null && value != null) { put(key, value); } return this; }
/** * Put a key/double pair in the JSONObject. * * @param key A key string. * @param value A double which is the value. * @return this. * @throws JSONException If the key is null or if the number is invalid. */ public JSONObject put(final String key, final double value) throws JSONException { put(key, new Double(value)); return this; }
/** * Put a key/int pair in the JSONObject. * * @param key A key string. * @param value An int which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final int value) throws JSONException { put(key, Integer.valueOf(value)); return this; }
/** * Put a key/double pair in the JSONObject. * * @param key A key string. * @param value A double which is the value. * @return this. * @throws JSONException If the key is null or if the number is invalid. */ public JSONObject put(final String key, final double value) throws JSONException { put(key, new Double(value)); return this; }
/** * Put a key/int pair in the JSONObject. * * @param key A key string. * @param value An int which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final int value) throws JSONException { put(key, new Integer(value)); return this; }
/** * Put a key/long pair in the JSONObject. * * @param key A key string. * @param value A long which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final long value) throws JSONException { put(key, new Long(value)); return this; }
/** * Put a key/long pair in the JSONObject. * * @param key A key string. * @param value A long which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final long value) throws JSONException { put(key, Long.valueOf(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * @param key A key string. * @param value A Map value. * @return this. * @throws JSONException */ public JSONObject put(final String key, final Map value) throws JSONException { put(key, new JSONObject(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. * @param key A key string. * @param value A Collection value. * @return this. * @throws JSONException */ public JSONObject put(final String key, final Collection value) throws JSONException { put(key, new JSONArray(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. * @param key A key string. * @param value A Collection value. * @return this. * @throws JSONException */ public JSONObject put(final String key, final Collection value) throws JSONException { put(key, new JSONArray(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * @param key A key string. * @param value A Map value. * @return this. * @throws JSONException */ public JSONObject put(final String key, final Map value) throws JSONException { put(key, new JSONObject(value)); return this; }
public static String toJSon(final MessageCounter counter) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); JSONObject json = new JSONObject(counter); String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime())); json.put("lastAddTimestamp", lastAddTimestamp); String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate())); json.put("updateTimestamp", updateTimestamp); return json.toString(); }
@Override public void describeProducersInfo(JSONArray array) throws Exception { Map<SimpleString, Pair<UUID, AtomicLong>> targetCopy = cloneTargetAddresses(); for (Map.Entry<SimpleString, Pair<UUID, AtomicLong>> entry : targetCopy.entrySet()) { JSONObject producerInfo = new JSONObject(); producerInfo.put("connectionID", this.getConnectionID().toString()); producerInfo.put("sessionID", this.getName()); producerInfo.put("destination", entry.getKey().toString()); producerInfo.put("lastUUIDSent", entry.getValue().getA()); producerInfo.put("msgSent", entry.getValue().getB().longValue()); array.put(producerInfo); } }
public void describeProducersInfo(JSONArray array) throws Exception { Map<SimpleString, Pair<UUID, AtomicLong>> targetCopy = cloneTargetAddresses(); for (Map.Entry<SimpleString, Pair<UUID, AtomicLong>> entry : targetCopy.entrySet()) { JSONObject producerInfo = new JSONObject(); producerInfo.put("connectionID", this.getConnectionID().toString()); producerInfo.put("sessionID", this.getName()); producerInfo.put("destination", entry.getKey().toString()); producerInfo.put("lastUUIDSent", entry.getValue().getA()); producerInfo.put("msgSent", entry.getValue().getB().longValue()); array.put(producerInfo); } }
/** * Returns a JSON String serialization of a {@link MessageCounter} object. * @param counter * @return * @throws Exception */ public static String toJSon(final MessageCounter counter) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); JSONObject json = new JSONObject(counter); String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime())); json.put("lastAddTimestamp", lastAddTimestamp); String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate())); json.put("updateTimestamp", updateTimestamp); return json.toString(); }
/** * Put a key/value pair in the JSONObject, but only if the key and the * value are both non-null, and only if there is not already a member * with that name. * @param key * @param value * @return his. * @throws JSONException if the key is a duplicate */ public JSONObject putOnce(final String key, final Object value) throws JSONException { if (key != null && value != null) { if (opt(key) != null) { throw new JSONException("Duplicate key \"" + key + "\""); } put(key, value); } return this; }
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(); }
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(); }