Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Document#getAsInt bound to NSFItemGetLong #402

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions domino-jnx-api/src/main/java/com/hcl/domino/data/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,17 @@ boolean convertRichTextItem(String itemName, Document targetNote, String targetI
* @return the timestamp of when the document was added to the file
*/
DominoDateTime getAddedToFile();

/**
* Retrieves the item value as an integer ({@code LONG} in the API).
*
* @param itemName the name of the item to retrieve
* @param defaultValue the value to return when the item is not
* present
* @return the item value as an {@code int}
* @since 1.31.0
*/
int getAsInt(String itemName, int defaultValue);

/**
* Retrieves the item value as text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4537,6 +4537,16 @@ public Document compileLotusScript() {
return this;
}

@Override
public int getAsInt(String itemName, int defaultValue) {
checkDisposed();

return LockUtil.lockHandle(getAllocations().getNoteHandle(), (hNoteByVal) -> {
Memory itemNameLmbcs = NotesStringUtils.toLMBCS(itemName, true);
return NotesCAPI.get().NSFItemGetLong(hNoteByVal, itemNameLmbcs, defaultValue);
});
}

@Override
public String getAsText(String itemName, char separator) {
checkDisposed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,15 @@ short NSFItemGetText(
Memory item_text,
short text_len);

/**
* @since 1.31.0
*/
int NSFItemGetLong(
DHANDLE.ByValue note_handle,
Memory item_name,
int number_item_default
);

short NSFDbGetNamesList(HANDLE.ByValue hDB, int Flags, DHANDLE.ByReference rethNamesList);

@UndocumentedAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,18 @@ public void testItemGetAsTextNumberMultiItem() throws Exception {
});
});
}

@Test
public void testItemGetAsInt() throws Exception {
withTempDb(database -> {
Document doc = database.createDocument();
doc.replaceItemValue("Foo", "dsf");
assertEquals(21, doc.getAsInt("Foo", 21));
doc.replaceItemValue("Bar", 43);
assertEquals(43, doc.getAsInt("Bar", 0));
doc.replaceItemValue("Baz", 82.1);
assertEquals(82, doc.getAsInt("Baz", 1));
assertEquals(-2, doc.getAsInt("Fake", -2));
});
}
}
Loading