Skip to content

Commit

Permalink
Add getKeyValuePair API on ObjectElement (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code authored Nov 27, 2024
1 parent 9f1e9b6 commit 129b2bb
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,22 @@ public String toString() {
w.flush();
return w.toString();
}


/**
* Gets an Optional KeyValuePairElement matching the provided key.
* If no such element exist an empty Optional is returned.
* @param key the key whose corresponding entry should be returned
* @return Optional with the entry if it is present.
*/
public Optional<KeyValuePairElement> getKeyValuePair(String key) {
for (KeyValuePairElement element : entries) {
if (Objects.equals(element.key, key)) {
return Optional.of(element);
}
}
return Optional.empty();
}

/**
* Gets a primtive element if it exists in this object. This method cannot return null values, only
* PrimitiveElements representing the null value. If no element exists with the specified key, or the element
Expand Down

0 comments on commit 129b2bb

Please sign in to comment.