Skip to content

Commit

Permalink
Add getKeyValuePair API on ObjectElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Nov 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 43bd3e4 commit d39e38c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/blue/endless/jankson/api/document/ObjectElement.java
Original file line number Diff line number Diff line change
@@ -167,6 +167,21 @@ public String toString() {
w.flush();
return w.toString();
}

/**
* Gets the KeyValuePairElement entry if it exists in this object.
* If no element exists with the specified key then null will be returned.
* @param key the key whose corresponding entry should be returned
* @return The entry if it is present, otherwise null.
*/
public KeyValuePairElement getKeyValuePair(String key) {
for (KeyValuePairElement element : entries) {
if (Objects.equals(element.key, key)) {
return element;
}
}
return null;
}

/**
* Gets a primtive element if it exists in this object. This method cannot return null values, only

0 comments on commit d39e38c

Please sign in to comment.