/** * Convenience method to get the specified member as a JsonPrimitive element. * * @param memberName name of the member being requested. * @return the JsonPrimitive corresponding to the specified member. */ public JsonPrimitive getAsJsonPrimitive(String memberName) { return (JsonPrimitive) members.get(memberName); }
@Override public T construct() { return (T) new LinkedTreeMap<String, Object>(); } };
/** * Adds a member, which is a name-value pair, to self. The name must be a String, but the value * can be an arbitrary JsonElement, thereby allowing you to build a full tree of JsonElements * rooted at this node. * * @param property name of the member. * @param value the member object. */ public void add(String property, JsonElement value) { if (value == null) { value = JsonNull.INSTANCE; } members.put(property, value); }
Node<K, V> removeInternalByKey(Object key) { Node<K, V> node = findByObject(key); if (node != null) { removeInternal(node, true); } return node; }
/** * Returns this map's entry that has the same key and value as {@code * entry}, or null if this map has no such entry. * * <p>This method uses the comparator for key equality rather than {@code * equals}. If this map's comparator isn't consistent with equals (such as * {@code String.CASE_INSENSITIVE_ORDER}), then {@code remove()} and {@code * contains()} will violate the collections API. */ Node<K, V> findByEntry(Entry<?, ?> entry) { Node<K, V> mine = findByObject(entry.getKey()); boolean valuesEqual = mine != null && equal(mine.value, entry.getValue()); return valuesEqual ? mine : null; }
final String key = "Hello"; final String randomValue = TestUtilities.randomString(); final LinkedTreeMap settings = new LinkedTreeMap(); settings.put(key, randomValue); final HookSettings updateHook = HookSettings.of(settings); final HookSettings hookSettings = api().update(projectKey, settings.put(key, randomValueAgain); final HookSettings hookSettingsAgain = HookSettings.of(settings); final HookSettings hookSettingsUpdated = api().update(projectKey,
if (o1.containsKey(JsonKeyValue)) { System.out.println("NEucaCometInterface::read: value=" + o1.get(JsonKeyValue)); JSONObject o2 = (JSONObject) JSONValue.parse(o1.get(JsonKeyValue).toString()); if (o2 != null) { if (o2.containsKey(JsonKeyVal)) {
@SuppressWarnings("unchecked") Node<K, V> findByObject(Object key) { try { return key != null ? find((K) key, false) : null; } catch (ClassCastException e) { return null; } }
/** * Returns a set of members of this object. The set is ordered, and the order is in which the * elements were added. * * @return a set of members of this object. */ public Set<Map.Entry<String, JsonElement>> entrySet() { return members.entrySet(); }
/** * Convenience method to check if a member with the specified name is present in this object. * * @param memberName name of the member that is being checked for presence. * @return true if there is a member with the specified name, false otherwise. */ public boolean has(String memberName) { return members.containsKey(memberName); }
@Override public V get(Object key) { Node<K, V> node = findByObject(key); return node != null ? node.value : null; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof JsonObject && ((JsonObject) o).members.equals(members)); }
public void testUpdateHookSettings() throws Exception { final MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/hook-settings.json")).setResponseCode(200)); final BitbucketApi baseApi = api(server.getUrl("/")); final HookApi api = baseApi.hookApi(); try { final LinkedTreeMap settings = new LinkedTreeMap(); settings.put(testKey, testValue); final HookSettings updateHook = HookSettings.of(settings); final String hookKey = qwertyKeyword; final HookSettings hookSettings = api.update(projectKey, repoKey, hookKey, updateHook); assertThat(hookSettings).isNotNull(); assertThat(hookSettings.settings().getAsJsonObject().entrySet()).isNotEmpty(); assertThat(hookSettings.errors()).isEmpty(); final String possibleValue = hookSettings .settings() .getAsJsonObject() .get(testKey) .getAsString(); assertThat(possibleValue).isEqualTo(testValue); assertSent(server, putMethod, restApiPath + BitbucketApiMetadata.API_VERSION + projectsPath + projectKey + reposPath + repoKey + hooksPath + "/" + hookKey + settingsEndpoint); } finally { baseApi.close(); server.shutdown(); } }
Node<K, V> removeInternalByKey(Object key) { Node<K, V> node = findByObject(key); if (node != null) { removeInternal(node, true); } return node; }
/** * Returns this map's entry that has the same key and value as {@code * entry}, or null if this map has no such entry. * * <p>This method uses the comparator for key equality rather than {@code * equals}. If this map's comparator isn't consistent with equals (such as * {@code String.CASE_INSENSITIVE_ORDER}), then {@code remove()} and {@code * contains()} will violate the collections API. */ Node<K, V> findByEntry(Entry<?, ?> entry) { Node<K, V> mine = findByObject(entry.getKey()); boolean valuesEqual = mine != null && equal(mine.value, entry.getValue()); return valuesEqual ? mine : null; }
@Override public V put(K key, V value) { if (key == null) { throw new NullPointerException("key == null"); } Node<K, V> created = find(key, true); V result = created.value; created.value = value; return result; }
/** * Creates a deep copy of this element and all its children * @since 2.8.2 */ @Override public JsonObject deepCopy() { JsonObject result = new JsonObject(); for (Map.Entry<String, JsonElement> entry : members.entrySet()) { result.add(entry.getKey(), entry.getValue().deepCopy()); } return result; }
/** * Convenience method to check if a member with the specified name is present in this object. * * @param memberName name of the member that is being checked for presence. * @return true if there is a member with the specified name, false otherwise. */ public boolean has(String memberName) { return members.containsKey(memberName); }
@Override public boolean containsKey(Object key) { return findByObject(key) != null; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof JsonObject && ((JsonObject) o).members.equals(members)); }